Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/files/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.3.0
PrepareContractionHierarchies.setPeriodicUpdates is now in percentage not in absolute counts
gpx export via API or HTTP (route?type=gpx)
breaking: The web response, Path.time and GHResponse.time change to milliseconds and 'long' (instead of seconds and double)

Expand Down
79 changes: 47 additions & 32 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
import com.graphhopper.routing.RoutingAlgorithm;
import com.graphhopper.routing.ch.PrepareContractionHierarchies;
import com.graphhopper.routing.util.*;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.storage.*;
import com.graphhopper.storage.index.*;
import com.graphhopper.util.*;

import java.io.File;
import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -48,6 +49,7 @@ public static void main( String[] strs ) throws Exception
if (args.getBool("graph.testIT", false))
tests.start();
}

private final Logger logger = LoggerFactory.getLogger(getClass());
// for graph:
private GraphStorage graph;
Expand All @@ -68,16 +70,18 @@ public static void main( String[] strs ) throws Exception
private boolean doPrepare = true;
private boolean chEnabled = true;
private String chWeighting = "fastest";
private int periodicUpdates = 3;
private int periodicUpdates = 20;
private int lazyUpdates = 10;
private int neighborUpdates = 20;
private int logMessages = 20;
// for OSM import:
private String osmFile;
private EncodingManager encodingManager;
private long expectedCapacity = 100;
private double wayPointMaxDistance = 1;
private int workerThreads = -1;
private int defaultSegmentSize = -1;
private boolean enableTurnRestrictions = false;
private boolean enableInstructions = true;
private boolean calcPoints = true;
private boolean fullyLoaded = false;
Expand Down Expand Up @@ -209,6 +213,24 @@ public boolean isCHEnabled()
return chEnabled;
}

/**
* @return if import of turn restrictions is enabled
*/
public boolean isEnableTurnRestrictions()
{
return enableTurnRestrictions;
}

/**
* This method specifies if the import should include turn restrictions if available
*/
public GraphHopper setEnableTurnRestrictions( boolean b )
{
ensureNotLoaded();
enableTurnRestrictions = b;
return this;
}

/**
* This method specifies if the import should include way names to be able to return
* instructions for a route.
Expand Down Expand Up @@ -376,19 +398,14 @@ public GraphHopper init( CmdArgs args ) throws IOException
// prepare CH
doPrepare = args.getBool("prepare.doPrepare", doPrepare);
String chShortcuts = args.get("prepare.chShortcuts", "fastest");
chEnabled = "true".equals(chShortcuts)
|| "fastest".equals(chShortcuts) || "shortest".equals(chShortcuts);
chEnabled = "true".equals(chShortcuts) || "fastest".equals(chShortcuts) || "shortest".equals(chShortcuts);
if (chEnabled)
setCHShortcuts(chShortcuts);

if (args.has("prepare.updates.periodic"))
periodicUpdates = args.getInt("prepare.updates.periodic", periodicUpdates);

if (args.has("prepare.updates.lazy"))
lazyUpdates = args.getInt("prepare.updates.lazy", lazyUpdates);

if (args.has("prepare.updates.neighbor"))
neighborUpdates = args.getInt("prepare.updates.neighbor", neighborUpdates);
periodicUpdates = args.getInt("prepare.updates.periodic", periodicUpdates);
lazyUpdates = args.getInt("prepare.updates.lazy", lazyUpdates);
neighborUpdates = args.getInt("prepare.updates.neighbor", neighborUpdates);
logMessages = args.getInt("prepare.logmessages", logMessages);

// osm import
wayPointMaxDistance = args.getDouble("osmreader.wayPointMaxDistance", wayPointMaxDistance);
Expand All @@ -404,8 +421,7 @@ public GraphHopper init( CmdArgs args ) throws IOException

private void printInfo()
{
logger.info("version " + Constants.VERSION
+ "|" + Constants.BUILD_DATE + " (" + Constants.getVersions() + ")");
logger.info("version " + Constants.VERSION + "|" + Constants.BUILD_DATE + " (" + Constants.getVersions() + ")");
logger.info("graph " + graph.toString() + ", details:" + graph.toDetailsString());
}

Expand Down Expand Up @@ -459,11 +475,8 @@ protected OSMReader importOSM( String _osmFile ) throws IOException
}

logger.info("start creating graph from " + osmFile);
OSMReader reader = new OSMReader(graph, expectedCapacity).
setWorkerThreads(workerThreads).
setEncodingManager(encodingManager).
setWayPointMaxDistance(wayPointMaxDistance).
setEnableInstructions(enableInstructions);
OSMReader reader = new OSMReader(graph, expectedCapacity).setWorkerThreads(workerThreads).setEncodingManager(encodingManager)
.setWayPointMaxDistance(wayPointMaxDistance).setEnableInstructions(enableInstructions);
logger.info("using " + graph.toString() + ", memory:" + Helper.getMemInfo());
reader.doOSM2Graph(osmTmpFile);
return reader;
Expand Down Expand Up @@ -514,6 +527,8 @@ public boolean load( String graphHopperFolder )

if (chEnabled)
graph = new LevelGraphStorage(dir, encodingManager);
else if (enableTurnRestrictions)
graph = new GraphHopperStorage(dir, encodingManager, new TurnCostStorage());
else
graph = new GraphHopperStorage(dir, encodingManager);

Expand Down Expand Up @@ -544,7 +559,8 @@ protected void initCHPrepare()
createWeighting(chWeighting, encoder));
tmpPrepareCH.setPeriodicUpdates(periodicUpdates).
setLazyUpdates(lazyUpdates).
setNeighborUpdates(neighborUpdates);
setNeighborUpdates(neighborUpdates).
setLogMessages(logMessages);

prepare = tmpPrepareCH;
prepare.setGraph(graph);
Expand All @@ -571,7 +587,8 @@ public GHResponse route( GHRequest request )

if (!encodingManager.supports(request.getVehicle()))
{
rsp.addError(new IllegalArgumentException("Vehicle " + request.getVehicle() + " unsupported. Supported are: " + getEncodingManager()));
rsp.addError(new IllegalArgumentException("Vehicle " + request.getVehicle() + " unsupported. Supported are: "
+ getEncodingManager()));
return rsp;
}

Expand All @@ -593,20 +610,21 @@ public GHResponse route( GHRequest request )
if (chEnabled)
{
if (prepare == null)
throw new IllegalStateException("Preparation object is null. CH-preparation wasn't done or did you forgot to call disableCHShortcuts()?");
throw new IllegalStateException(
"Preparation object is null. CH-preparation wasn't done or did you forgot to call disableCHShortcuts()?");

if (request.getAlgorithm().equals("dijkstrabi"))
algo = prepare.createAlgo();
else if (request.getAlgorithm().equals("astarbi"))
algo = ((PrepareContractionHierarchies) prepare).createAStar();
else
rsp.addError(new IllegalStateException("Only dijkstrabi and astarbi is supported for LevelGraph (using contraction hierarchies)!"));
rsp.addError(new IllegalStateException(
"Only dijkstrabi and astarbi is supported for LevelGraph (using contraction hierarchies)!"));

} else
{
Weighting weighting = createWeighting(request.getWeighting(), encoder);
prepare = NoOpAlgorithmPreparation.createAlgoPrepare(graph, request.getAlgorithm(),
encoder, weighting);
prepare = NoOpAlgorithmPreparation.createAlgoPrepare(graph, request.getAlgorithm(), encoder, weighting);
algo = prepare.createAlgo();
}

Expand Down Expand Up @@ -732,21 +750,18 @@ protected void cleanUp()
int n = graph.getNodes();
// calculate remaining subnetworks
int remainingSubnetworks = preparation.findSubnetworks().size();
logger.info("edges: " + graph.getAllEdges().getMaxId()
+ ", nodes " + n + ", there were " + preparation.getSubNetworks()
+ " subnetworks. removed them => " + (prev - n)
+ " less nodes. Remaining subnetworks:" + remainingSubnetworks);
logger.info("edges: " + graph.getAllEdges().getMaxId() + ", nodes " + n + ", there were " + preparation.getSubNetworks()
+ " subnetworks. removed them => " + (prev - n) + " less nodes. Remaining subnetworks:" + remainingSubnetworks);
}

private void flush()
{
logger.info("flushing graph " + graph.toString() + ", details:" + graph.toDetailsString() + ", "
+ Helper.getMemInfo() + ")");
logger.info("flushing graph " + graph.toString() + ", details:" + graph.toDetailsString() + ", " + Helper.getMemInfo() + ")");
graph.flush();
fullyLoaded = true;
}

void close()
public void close()
{
if (graph != null)
graph.close();
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/graphhopper/reader/OSMElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public boolean hasInternalTag( String key )
return iProperties.containsKey(key);
}

@SuppressWarnings("unchecked")
public <T> T getInternalTag( String key, T defaultValue )
{
if (iProperties == null)
Expand Down
Loading