Skip to content

Commit 6bc36a5

Browse files
author
Peter
committed
fixing low level docs
1 parent a8352d2 commit 6bc36a5

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/core/low-level-api.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ if (!index.loadExisting())
5050
```java
5151
QueryResult fromQR = index.findClosest(latitudeFrom, longituteFrom, EdgeFilter.ALL_EDGES);
5252
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());
5456
```
5557

5658
### Calculate Path without LocationIndex
@@ -69,13 +71,14 @@ GraphBuilder gb = new GraphBuilder(em).
6971
setStore(true).
7072
setLevelGraph(true);
7173
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, ..
7375
EdgeIteratorState edge = graph.edge(fromId, toId);
7476
...
7577

7678
// 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();
7982

8083
// flush after preparation!
8184
graph.flush();
@@ -88,11 +91,16 @@ LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), new RAMDirecto
8891
if (!index.loadExisting())
8992
throw new IllegalStateException("location2id index cannot be loaded!");
9093

91-
// create the algorithm using the PrepareContractionHierarchies object
92-
RoutingAlgorithm algorithm = pch.createAlgo();
93-
9494
// calculate path is identical
9595
QueryResult fromQR = index.findClosest(latitudeFrom, longituteFrom, EdgeFilter.ALL_EDGES);
9696
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());
98106
```

0 commit comments

Comments
 (0)