22
22
import com .graphhopper .routing .RoutingAlgorithm ;
23
23
import com .graphhopper .routing .ch .PrepareContractionHierarchies ;
24
24
import com .graphhopper .routing .util .*;
25
- import com .graphhopper .routing .util .EncodingManager ;
26
25
import com .graphhopper .storage .*;
27
26
import com .graphhopper .storage .index .*;
28
27
import com .graphhopper .util .*;
28
+
29
29
import java .io .File ;
30
30
import java .io .IOException ;
31
+
31
32
import org .slf4j .Logger ;
32
33
import org .slf4j .LoggerFactory ;
33
34
@@ -48,6 +49,7 @@ public static void main( String[] strs ) throws Exception
48
49
if (args .getBool ("graph.testIT" , false ))
49
50
tests .start ();
50
51
}
52
+
51
53
private final Logger logger = LoggerFactory .getLogger (getClass ());
52
54
// for graph:
53
55
private GraphStorage graph ;
@@ -79,6 +81,7 @@ public static void main( String[] strs ) throws Exception
79
81
private double wayPointMaxDistance = 1 ;
80
82
private int workerThreads = -1 ;
81
83
private int defaultSegmentSize = -1 ;
84
+ private boolean enableTurnRestrictions = false ;
82
85
private boolean enableInstructions = true ;
83
86
private boolean calcPoints = true ;
84
87
private boolean fullyLoaded = false ;
@@ -210,6 +213,24 @@ public boolean isCHEnabled()
210
213
return chEnabled ;
211
214
}
212
215
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
+
213
234
/**
214
235
* This method specifies if the import should include way names to be able to return
215
236
* instructions for a route.
@@ -377,8 +398,7 @@ public GraphHopper init( CmdArgs args ) throws IOException
377
398
// prepare CH
378
399
doPrepare = args .getBool ("prepare.doPrepare" , doPrepare );
379
400
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 );
382
402
if (chEnabled )
383
403
setCHShortcuts (chShortcuts );
384
404
@@ -401,8 +421,7 @@ public GraphHopper init( CmdArgs args ) throws IOException
401
421
402
422
private void printInfo ()
403
423
{
404
- logger .info ("version " + Constants .VERSION
405
- + "|" + Constants .BUILD_DATE + " (" + Constants .getVersions () + ")" );
424
+ logger .info ("version " + Constants .VERSION + "|" + Constants .BUILD_DATE + " (" + Constants .getVersions () + ")" );
406
425
logger .info ("graph " + graph .toString () + ", details:" + graph .toDetailsString ());
407
426
}
408
427
@@ -456,11 +475,8 @@ protected OSMReader importOSM( String _osmFile ) throws IOException
456
475
}
457
476
458
477
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 );
464
480
logger .info ("using " + graph .toString () + ", memory:" + Helper .getMemInfo ());
465
481
reader .doOSM2Graph (osmTmpFile );
466
482
return reader ;
@@ -511,6 +527,8 @@ public boolean load( String graphHopperFolder )
511
527
512
528
if (chEnabled )
513
529
graph = new LevelGraphStorage (dir , encodingManager );
530
+ else if (enableTurnRestrictions )
531
+ graph = new GraphHopperStorage (dir , encodingManager , new TurnCostStorage ());
514
532
else
515
533
graph = new GraphHopperStorage (dir , encodingManager );
516
534
@@ -569,7 +587,8 @@ public GHResponse route( GHRequest request )
569
587
570
588
if (!encodingManager .supports (request .getVehicle ()))
571
589
{
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 ()));
573
592
return rsp ;
574
593
}
575
594
@@ -591,20 +610,21 @@ public GHResponse route( GHRequest request )
591
610
if (chEnabled )
592
611
{
593
612
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()?" );
595
615
596
616
if (request .getAlgorithm ().equals ("dijkstrabi" ))
597
617
algo = prepare .createAlgo ();
598
618
else if (request .getAlgorithm ().equals ("astarbi" ))
599
619
algo = ((PrepareContractionHierarchies ) prepare ).createAStar ();
600
620
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)!" ));
602
623
603
624
} else
604
625
{
605
626
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 );
608
628
algo = prepare .createAlgo ();
609
629
}
610
630
@@ -730,16 +750,13 @@ protected void cleanUp()
730
750
int n = graph .getNodes ();
731
751
// calculate remaining subnetworks
732
752
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 );
737
755
}
738
756
739
757
private void flush ()
740
758
{
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 () + ")" );
743
760
graph .flush ();
744
761
fullyLoaded = true ;
745
762
}
0 commit comments