17
17
*/
18
18
package com .graphhopper .routing ;
19
19
20
+ import com .graphhopper .GraphHopper ;
20
21
import com .graphhopper .reader .PrinctonReader ;
21
- import com .graphhopper .routing .ch .PrepareContractionHierarchies ;
22
22
import com .graphhopper .routing .util .EncodingManager ;
23
23
import com .graphhopper .routing .util .FlagEncoder ;
24
+ import com .graphhopper .routing .util .HintsMap ;
24
25
import com .graphhopper .routing .util .TestAlgoCollector .AlgoHelperEntry ;
25
26
import com .graphhopper .routing .util .TraversalMode ;
26
- import com .graphhopper .routing .weighting .ShortestWeighting ;
27
27
import com .graphhopper .routing .weighting .Weighting ;
28
- import com .graphhopper .storage .*;
28
+ import com .graphhopper .storage .CHGraph ;
29
+ import com .graphhopper .storage .Directory ;
30
+ import com .graphhopper .storage .GraphBuilder ;
31
+ import com .graphhopper .storage .GraphHopperStorage ;
29
32
import com .graphhopper .storage .index .LocationIndex ;
30
33
import com .graphhopper .storage .index .LocationIndexTree ;
31
34
import com .graphhopper .util .Parameters ;
44
47
45
48
/**
46
49
* Try algorithms, indices and graph storages with real data
47
- * <p>
48
50
*
49
51
* @author Peter Karich
50
52
*/
51
53
public class RoutingAlgorithmIT {
52
- public static List <AlgoHelperEntry > createAlgos (GraphHopperStorage ghStorage , LocationIndex idx , boolean withCH ,
53
- TraversalMode tMode , Weighting weighting ) {
54
- List <AlgoHelperEntry > prepare = new ArrayList <AlgoHelperEntry >();
55
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , new AlgorithmOptions (ASTAR , weighting , tMode ), idx ));
54
+ public static List <AlgoHelperEntry > createAlgos (final GraphHopper hopper , final HintsMap hints , TraversalMode tMode ) {
55
+ GraphHopperStorage ghStorage = hopper .getGraphHopperStorage ();
56
+ LocationIndex idx = hopper .getLocationIndex ();
57
+
58
+ String addStr = "" ;
59
+ if (tMode .isEdgeBased ())
60
+ addStr = "turn|" ;
61
+
62
+ FlagEncoder encoder = hopper .getEncodingManager ().getEncoder (hints .getVehicle ());
63
+ Weighting weighting = hopper .createWeighting (hints , encoder , hopper .getGraphHopperStorage ());
64
+
65
+ HintsMap defaultHints = new HintsMap ().put (Parameters .CH .DISABLE , true )
66
+ .setVehicle (hints .getVehicle ()).setWeighting (hints .getWeighting ());
67
+
68
+ AlgorithmOptions defaultOpts = AlgorithmOptions .start (new AlgorithmOptions ("" , weighting , tMode )).hints (defaultHints ).build ();
69
+
70
+ List <AlgoHelperEntry > prepare = new ArrayList <>();
71
+ prepare .add (new AlgoHelperEntry (ghStorage , AlgorithmOptions .start (defaultOpts ).algorithm (ASTAR ).build (), idx , "astar|beeline|" + addStr + weighting ));
56
72
// later: include dijkstraOneToMany
57
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , new AlgorithmOptions ( DIJKSTRA , weighting , tMode ), idx ));
73
+ prepare .add (new AlgoHelperEntry (ghStorage , AlgorithmOptions . start ( defaultOpts ). algorithm ( DIJKSTRA ). build (), idx , "dijkstra|" + addStr + weighting ));
58
74
59
- final AlgorithmOptions astarbiOpts = new AlgorithmOptions ( ASTAR_BI , weighting , tMode );
75
+ AlgorithmOptions astarbiOpts = AlgorithmOptions . start ( defaultOpts ). algorithm ( ASTAR_BI ). build ( );
60
76
astarbiOpts .getHints ().put (ASTAR_BI + ".approximation" , "BeelineSimplification" );
61
- final AlgorithmOptions dijkstrabiOpts = new AlgorithmOptions (DIJKSTRA_BI , weighting , tMode );
62
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , astarbiOpts , idx ));
63
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , dijkstrabiOpts , idx ));
64
-
65
- if (withCH ) {
66
- final AlgorithmOptions chOpts = AlgorithmOptions .start (dijkstrabiOpts ).build ();
67
- chOpts .getHints ().put (Parameters .CH .DISABLE , true );
68
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , chOpts , idx ));
69
-
70
- final AlgorithmOptions astarCH = AlgorithmOptions .start (astarbiOpts ).build ();
71
- astarCH .getHints ().put (Parameters .CH .DISABLE , true );
72
- prepare .add (new AlgoHelperEntry (ghStorage , ghStorage , astarCH , idx ));
77
+ AlgorithmOptions dijkstrabiOpts = AlgorithmOptions .start (defaultOpts ).algorithm (DIJKSTRA_BI ).build ();
78
+ prepare .add (new AlgoHelperEntry (ghStorage , astarbiOpts , idx , "astarbi|beeline|" + addStr + weighting ));
79
+ prepare .add (new AlgoHelperEntry (ghStorage , dijkstrabiOpts , idx , "dijkstrabi|" + addStr + weighting ));
80
+
81
+ // add additional preparations if CH preparation are enabled
82
+ if (hopper .getCHFactoryDecorator ().isEnabled ()) {
83
+ final HintsMap chHints = new HintsMap (defaultHints ).put (Parameters .CH .DISABLE , false );
84
+ Weighting pickedWeighting = null ;
85
+ for (Weighting tmpWeighting : hopper .getCHFactoryDecorator ().getWeightings ()) {
86
+ if (tmpWeighting .equals (weighting )) {
87
+ pickedWeighting = tmpWeighting ;
88
+ break ;
89
+ }
90
+ }
91
+ if (pickedWeighting == null )
92
+ throw new IllegalStateException ("Didn't find weighting " + hints .getWeighting () + " in " + hopper .getCHFactoryDecorator ().getWeightings ());
93
+
94
+ prepare .add (new AlgoHelperEntry (ghStorage .getGraph (CHGraph .class , pickedWeighting ),
95
+ AlgorithmOptions .start (dijkstrabiOpts ).hints (chHints ).build (), idx , "dijkstrabi|ch|prepare|" + hints .getWeighting ()) {
96
+ @ Override
97
+ public RoutingAlgorithmFactory createRoutingFactory () {
98
+ return hopper .getAlgorithmFactory (chHints );
99
+ }
100
+ });
101
+
102
+ prepare .add (new AlgoHelperEntry (ghStorage .getGraph (CHGraph .class , pickedWeighting ),
103
+ AlgorithmOptions .start (astarbiOpts ).hints (chHints ).build (), idx , "astarbi|ch|prepare|" + hints .getWeighting ()) {
104
+ @ Override
105
+ public RoutingAlgorithmFactory createRoutingFactory () {
106
+ return hopper .getAlgorithmFactory (chHints );
107
+ }
108
+ });
73
109
}
74
110
75
111
return prepare ;
@@ -81,20 +117,32 @@ public void testPerformance() throws IOException {
81
117
int noJvmWarming = N / 4 ;
82
118
83
119
Random rand = new Random (0 );
84
- EncodingManager eManager = new EncodingManager ("car" );
85
- FlagEncoder encoder = eManager .getEncoder ("car" );
86
- GraphHopperStorage graph = new GraphBuilder (eManager ).create ();
120
+ final EncodingManager eManager = new EncodingManager ("car" );
121
+ final GraphHopperStorage graph = new GraphBuilder (eManager ).create ();
87
122
88
123
String bigFile = "10000EWD.txt.gz" ;
89
124
new PrinctonReader (graph ).setStream (new GZIPInputStream (PrinctonReader .class .getResourceAsStream (bigFile ))).read ();
90
- Collection <AlgoHelperEntry > prepares = createAlgos (graph , null , false , TraversalMode .NODE_BASED ,
91
- new ShortestWeighting (encoder ));
125
+ GraphHopper hopper = new GraphHopper () {
126
+ {
127
+ setCHEnabled (false );
128
+ setEncodingManager (eManager );
129
+ loadGraph (graph );
130
+ }
131
+
132
+ @ Override
133
+ protected LocationIndex createLocationIndex (Directory dir ) {
134
+ return new LocationIndexTree (graph , dir );
135
+ }
136
+ };
137
+
138
+ Collection <AlgoHelperEntry > prepares = createAlgos (hopper , new HintsMap ().setWeighting ("shortest" ).setVehicle ("car" ), TraversalMode .NODE_BASED );
139
+
92
140
for (AlgoHelperEntry entry : prepares ) {
93
141
StopWatch sw = new StopWatch ();
94
142
for (int i = 0 ; i < N ; i ++) {
95
143
int node1 = Math .abs (rand .nextInt (graph .getNodes ()));
96
144
int node2 = Math .abs (rand .nextInt (graph .getNodes ()));
97
- RoutingAlgorithm d = entry .createAlgo (graph );
145
+ RoutingAlgorithm d = entry .createRoutingFactory (). createAlgo (graph , entry . getAlgorithmOptions () );
98
146
if (i >= noJvmWarming )
99
147
sw .start ();
100
148
0 commit comments