Skip to content

Commit 69acd13

Browse files
author
Peter
committed
Merge branch 'master' of git+ssh://github.com/graphhopper/graphhopper
2 parents cf1291b + 3beffe7 commit 69acd13

22 files changed

+1163
-552
lines changed

core/src/main/java/com/graphhopper/GraphHopper.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
import com.graphhopper.routing.RoutingAlgorithm;
2323
import com.graphhopper.routing.ch.PrepareContractionHierarchies;
2424
import com.graphhopper.routing.util.*;
25-
import com.graphhopper.routing.util.EncodingManager;
2625
import com.graphhopper.storage.*;
2726
import com.graphhopper.storage.index.*;
2827
import com.graphhopper.util.*;
28+
2929
import java.io.File;
3030
import java.io.IOException;
31+
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

@@ -48,6 +49,7 @@ public static void main( String[] strs ) throws Exception
4849
if (args.getBool("graph.testIT", false))
4950
tests.start();
5051
}
52+
5153
private final Logger logger = LoggerFactory.getLogger(getClass());
5254
// for graph:
5355
private GraphStorage graph;
@@ -79,6 +81,7 @@ public static void main( String[] strs ) throws Exception
7981
private double wayPointMaxDistance = 1;
8082
private int workerThreads = -1;
8183
private int defaultSegmentSize = -1;
84+
private boolean enableTurnRestrictions = false;
8285
private boolean enableInstructions = true;
8386
private boolean calcPoints = true;
8487
private boolean fullyLoaded = false;
@@ -210,6 +213,24 @@ public boolean isCHEnabled()
210213
return chEnabled;
211214
}
212215

216+
/**
217+
* @return if import of turn restrictions is enabled
218+
*/
219+
public boolean isEnableTurnRestrictions()
220+
{
221+
return enableTurnRestrictions;
222+
}
223+
224+
/**
225+
* This method specifies if the import should include turn restrictions if available
226+
*/
227+
public GraphHopper setEnableTurnRestrictions( boolean b )
228+
{
229+
ensureNotLoaded();
230+
enableTurnRestrictions = b;
231+
return this;
232+
}
233+
213234
/**
214235
* This method specifies if the import should include way names to be able to return
215236
* instructions for a route.
@@ -377,8 +398,7 @@ public GraphHopper init( CmdArgs args ) throws IOException
377398
// prepare CH
378399
doPrepare = args.getBool("prepare.doPrepare", doPrepare);
379400
String chShortcuts = args.get("prepare.chShortcuts", "fastest");
380-
chEnabled = "true".equals(chShortcuts)
381-
|| "fastest".equals(chShortcuts) || "shortest".equals(chShortcuts);
401+
chEnabled = "true".equals(chShortcuts) || "fastest".equals(chShortcuts) || "shortest".equals(chShortcuts);
382402
if (chEnabled)
383403
setCHShortcuts(chShortcuts);
384404

@@ -401,8 +421,7 @@ public GraphHopper init( CmdArgs args ) throws IOException
401421

402422
private void printInfo()
403423
{
404-
logger.info("version " + Constants.VERSION
405-
+ "|" + Constants.BUILD_DATE + " (" + Constants.getVersions() + ")");
424+
logger.info("version " + Constants.VERSION + "|" + Constants.BUILD_DATE + " (" + Constants.getVersions() + ")");
406425
logger.info("graph " + graph.toString() + ", details:" + graph.toDetailsString());
407426
}
408427

@@ -456,11 +475,8 @@ protected OSMReader importOSM( String _osmFile ) throws IOException
456475
}
457476

458477
logger.info("start creating graph from " + osmFile);
459-
OSMReader reader = new OSMReader(graph, expectedCapacity).
460-
setWorkerThreads(workerThreads).
461-
setEncodingManager(encodingManager).
462-
setWayPointMaxDistance(wayPointMaxDistance).
463-
setEnableInstructions(enableInstructions);
478+
OSMReader reader = new OSMReader(graph, expectedCapacity).setWorkerThreads(workerThreads).setEncodingManager(encodingManager)
479+
.setWayPointMaxDistance(wayPointMaxDistance).setEnableInstructions(enableInstructions);
464480
logger.info("using " + graph.toString() + ", memory:" + Helper.getMemInfo());
465481
reader.doOSM2Graph(osmTmpFile);
466482
return reader;
@@ -511,6 +527,8 @@ public boolean load( String graphHopperFolder )
511527

512528
if (chEnabled)
513529
graph = new LevelGraphStorage(dir, encodingManager);
530+
else if (enableTurnRestrictions)
531+
graph = new GraphHopperStorage(dir, encodingManager, new TurnCostStorage());
514532
else
515533
graph = new GraphHopperStorage(dir, encodingManager);
516534

@@ -569,7 +587,8 @@ public GHResponse route( GHRequest request )
569587

570588
if (!encodingManager.supports(request.getVehicle()))
571589
{
572-
rsp.addError(new IllegalArgumentException("Vehicle " + request.getVehicle() + " unsupported. Supported are: " + getEncodingManager()));
590+
rsp.addError(new IllegalArgumentException("Vehicle " + request.getVehicle() + " unsupported. Supported are: "
591+
+ getEncodingManager()));
573592
return rsp;
574593
}
575594

@@ -591,20 +610,21 @@ public GHResponse route( GHRequest request )
591610
if (chEnabled)
592611
{
593612
if (prepare == null)
594-
throw new IllegalStateException("Preparation object is null. CH-preparation wasn't done or did you forgot to call disableCHShortcuts()?");
613+
throw new IllegalStateException(
614+
"Preparation object is null. CH-preparation wasn't done or did you forgot to call disableCHShortcuts()?");
595615

596616
if (request.getAlgorithm().equals("dijkstrabi"))
597617
algo = prepare.createAlgo();
598618
else if (request.getAlgorithm().equals("astarbi"))
599619
algo = ((PrepareContractionHierarchies) prepare).createAStar();
600620
else
601-
rsp.addError(new IllegalStateException("Only dijkstrabi and astarbi is supported for LevelGraph (using contraction hierarchies)!"));
621+
rsp.addError(new IllegalStateException(
622+
"Only dijkstrabi and astarbi is supported for LevelGraph (using contraction hierarchies)!"));
602623

603624
} else
604625
{
605626
Weighting weighting = createWeighting(request.getWeighting(), encoder);
606-
prepare = NoOpAlgorithmPreparation.createAlgoPrepare(graph, request.getAlgorithm(),
607-
encoder, weighting);
627+
prepare = NoOpAlgorithmPreparation.createAlgoPrepare(graph, request.getAlgorithm(), encoder, weighting);
608628
algo = prepare.createAlgo();
609629
}
610630

@@ -730,16 +750,13 @@ protected void cleanUp()
730750
int n = graph.getNodes();
731751
// calculate remaining subnetworks
732752
int remainingSubnetworks = preparation.findSubnetworks().size();
733-
logger.info("edges: " + graph.getAllEdges().getMaxId()
734-
+ ", nodes " + n + ", there were " + preparation.getSubNetworks()
735-
+ " subnetworks. removed them => " + (prev - n)
736-
+ " less nodes. Remaining subnetworks:" + remainingSubnetworks);
753+
logger.info("edges: " + graph.getAllEdges().getMaxId() + ", nodes " + n + ", there were " + preparation.getSubNetworks()
754+
+ " subnetworks. removed them => " + (prev - n) + " less nodes. Remaining subnetworks:" + remainingSubnetworks);
737755
}
738756

739757
private void flush()
740758
{
741-
logger.info("flushing graph " + graph.toString() + ", details:" + graph.toDetailsString() + ", "
742-
+ Helper.getMemInfo() + ")");
759+
logger.info("flushing graph " + graph.toString() + ", details:" + graph.toDetailsString() + ", " + Helper.getMemInfo() + ")");
743760
graph.flush();
744761
fullyLoaded = true;
745762
}

0 commit comments

Comments
 (0)