Commit 40a16a77 authored by Julian Zobel's avatar Julian Zobel
Browse files

Update of GraphHopper Routing API to allow the blockager of paths and areas.

parent 48af126d
......@@ -103,10 +103,22 @@
</repository>
<!-- uk maven central, since the local central server is slow as hell -->
<!--
<repository>
<id>uk.maven.org</id>
<url>http://uk.maven.org/maven2</url>
</repository>
-->
<repository>
<id>Google Maven Central</id>
<url>https://maven-central.storage.googleapis.com/repos/central/data/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
</snapshots>
<releases>
<updatePolicy>always</updatePolicy>
</releases>
</repository>
......@@ -349,10 +361,11 @@
<artifactId>jung-samples</artifactId> <version>2.0.1</version> </dependency> -->
<!-- OSM-Data for movement models -->
<!--
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
......@@ -360,7 +373,19 @@
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-core</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>com.graphhopper</groupId>
<artifactId>graphhopper-reader-osm</artifactId>
<version>0.13.0</version>
</dependency>
<!-- Json (used for OSM-Movement-Model) -->
<dependency>
<groupId>org.json</groupId>
......
......@@ -32,15 +32,18 @@ import com.graphhopper.GHRequest;
import com.graphhopper.GHResponse;
import com.graphhopper.GraphHopper;
import com.graphhopper.PathWrapper;
import com.graphhopper.reader.osm.GraphHopperOSM;
import com.graphhopper.routing.util.EdgeFilter;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.routing.weighting.BlockAreaWeighting;
import com.graphhopper.storage.index.LocationIndex;
import com.graphhopper.storage.index.QueryResult;
import com.graphhopper.util.DistanceCalc2D;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.Instruction;
import com.graphhopper.util.InstructionList;
import com.graphhopper.util.Parameters.Routing;
import com.graphhopper.util.PointList;
import com.graphhopper.util.shapes.GHPoint;
......@@ -55,6 +58,7 @@ import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* This movement strategy uses the data from osm and navigates the nodes throught streets to the destination
......@@ -81,6 +85,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private String movementType; //car, bike or foot
private String defaultMovement;
private String navigationalType; //fastest,
private String blockedAreas; // default null
private static double latLower; //Values from -90 to 90; always smaller than latUpper
private static double latUpper; //Values from -90 to 90
private static double lonLeft; //Values from -180 to 180; Always smaller than lonRight
......@@ -93,6 +98,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
*/
private double tolerance = 1;
@XMLConfigurableConstructor({"blockedAreas"})
public RealWorldStreetsMovement(String blockedAreas) {
this();
this.setBlockedAreas(blockedAreas);
}
public RealWorldStreetsMovement() {
worldDimensions = Binder.getComponentOrNull(Topology.class)
.getWorldDimensions();
......@@ -100,13 +111,12 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
latUpper = GPSCalculation.getLatUpper();
lonLeft = GPSCalculation.getLonLeft();
lonRight = GPSCalculation.getLonRight();
}
private void init() {
hopper = new GraphHopper().forServer();
hopper.setOSMFile(osmFileLocation);
hopper = new GraphHopperOSM().forServer();
hopper.setDataReaderFile(osmFileLocation);
// where to store graphhopper files?
if (uniqueFolders) {
Monitor.log(RealWorldStreetsMovement.class, Level.WARN,
......@@ -118,12 +128,27 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
hopper.setGraphHopperLocation(graphFolderFiles + "/"
+ osmFileLocation.hashCode() + movementType);
}
hopper.setEncodingManager(new EncodingManager(movementType));
hopper.importOrLoad();
hopper.setEncodingManager(EncodingManager.create(movementType));
// if we have blocked areas defined, the CH in Graphhopper needs to be disabled!
// this also requires a new import
if(blockedAreas != null && !blockedAreas.isEmpty()) {
hopper.setCHEnabled(false);
}
// try to load a cached import. If the cached import was with a different CH_ENABLED setting then now specified, this will fail.
// in this case, clean cache and re-import.
try {
hopper.importOrLoad();
} catch (Exception e) {
System.err.println("[RealWorldStreetMovement] GraphHopper graph file must be imported again!");
hopper.clean();
hopper.importOrLoad();
}
index = hopper.getLocationIndex();
init = true;
}
}
@Override
public Either<PositionVector, Boolean> nextPosition(
......@@ -168,7 +193,15 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
setWeighting(navigationalType).
setVehicle(movementType).
setLocale(Locale.GERMANY);
GHResponse rsp = hopper.route(req);
// blocks one or multiple given areas from being used by the routing
// https://github.com/graphhopper/graphhopper/blob/master/docs/web/api-doc.md#flexible
if(blockedAreas != null && !blockedAreas.isEmpty()) {
req.getHints().put(Routing.BLOCK_AREA, blockedAreas);
}
GHResponse rsp = hopper.route(req);
//If the requested point is not in the map data, simple return the destination as next point
if(rsp.hasErrors()) {
Monitor.log(this.getClass(), Monitor.Level.ERROR, "Routing request for Host %s with starting point (" +
......@@ -223,8 +256,9 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
RouteSegmentImpl segment = null;
PointList points = instr.getPoints();
String name = instr.getName();
if (name.isEmpty()) {
name = Integer.toString(instr.getPoints().toGHPoint(0).hashCode());
if (name.isEmpty()) {
name = Integer.toString(instr.getPoints().get(0).hashCode());
//name = Integer.toString(instr.getPoints().toGHPoint(0).hashCode()); @deprecated for old GraphHopper version
}
for (GHPoint point : points) {
if (segment == null) {
......@@ -399,4 +433,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
public void setCreateUniqueFolders(boolean uniqueFolders) {
this.uniqueFolders = uniqueFolders;
}
public void setBlockedAreas(String blockedAreas) {
if(!blockedAreas.isEmpty()) {
this.blockedAreas = blockedAreas;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment