@@ -50,7 +50,9 @@ if (!index.loadExisting())
50
50
``` java
51
51
QueryResult fromQR = index. findClosest(latitudeFrom, longituteFrom, EdgeFilter . ALL_EDGES );
52
52
QueryResult toQR = index. findID(latitudeTo, longituteTo, EdgeFilter . ALL_EDGES );
53
- Path path = new Dijkstra (graph, encoder). calcPath(fromQR, toQR);
53
+ QueryGraph queryGraph = new QueryGraph (graph);
54
+ queryGraph. lookup(fromQR, toQR);
55
+ Path path = new Dijkstra (queryGraph, encoder). calcPath(fromQR. getClosestNode(), toQR. getClosestNode());
54
56
```
55
57
56
58
### Calculate Path without LocationIndex
@@ -69,13 +71,14 @@ GraphBuilder gb = new GraphBuilder(em).
69
71
setStore(true ).
70
72
setLevelGraph(true );
71
73
GraphStorage graph = gb. create();
72
- // Make a weighted edge between two nodes.
74
+ // Create a new edge between two nodes, set access, distance, speed, geometry, . .
73
75
EdgeIteratorState edge = graph. edge(fromId, toId);
74
76
...
75
77
76
78
// Prepare the graph for fast querying ...
77
- PrepareContractionHierarchies pch = new PrepareContractionHierarchies ();
78
- pch. setGraph(graph). doWork();
79
+ TraversalMode tMode = TraversalMode . NODE_BASED ;
80
+ PrepareContractionHierarchies pch = new PrepareContractionHierarchies (graph, encoder, weighting, tMode);
81
+ pch. doWork();
79
82
80
83
// flush after preparation!
81
84
graph. flush();
@@ -88,11 +91,16 @@ LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), new RAMDirecto
88
91
if (! index. loadExisting())
89
92
throw new IllegalStateException (" location2id index cannot be loaded!" );
90
93
91
- // create the algorithm using the PrepareContractionHierarchies object
92
- RoutingAlgorithm algorithm = pch. createAlgo();
93
-
94
94
// calculate path is identical
95
95
QueryResult fromQR = index. findClosest(latitudeFrom, longituteFrom, EdgeFilter . ALL_EDGES );
96
96
QueryResult toQR = index. findID(latitudeTo, longituteTo, EdgeFilter . ALL_EDGES );
97
- Path path = new Dijkstra (graph, encoder). calcPath(fromQR, toQR);
97
+ QueryGraph queryGraph = new QueryGraph (graph);
98
+ queryGraph. lookup(fromQR, toQR);
99
+
100
+ // create the algorithm using the PrepareContractionHierarchies object
101
+ AlgorithmOptions algoOpts = AlgorithmOptions . start().
102
+ algorithm(AlgorithmOptions . DIJKSTRA_BI ). traversalMode(tMode). flagEncoder(encoder). weighting(weighting).
103
+ build();
104
+ RoutingAlgorithm algorithm = pch. createAlgo(queryGraph, algoOpts);
105
+ Path path = algorithm. calcPath(fromQR. getClosestNode(), toQR. getClosestNode());
98
106
```
0 commit comments