Hiya, so I have been following along in those examples. I suppose the difference is that I have already setup a graph from my pbf file.
So am I correct in that I don’t need to set a GraphHopperStorage as it already exists? So all I need to do is reference my GraphHopper.loadExisting(); graph.
Also I’ve found that if I do getLocationIndex() from outside each algo call I get incorrect distance/time.
For example;
This gives me the correct distances (and is slow)
I have managed to fix the issue for the most part;
My solution was to stop producing a nodeIndex at the start. Instead I only fill the array with snaps.
for (GHPoint point : points) {
Snap fromSnap = Graphhopper.graphHopper.getLocationIndex().findClosest(point.getLat(), point.getLon(), EdgeFilter.ALL_EDGES);
nodeSnap.add(fromSnap);
}
Then when I use the algo to calcPath I use the nodeSnap getClosestNode() instead of the nodeIndex. Path path = algo.calcPath(nodeSnap.get(i).getClosestNode(), nodeSnap.get(y).getClosestNode());
This gives the expected results but I am still having issues with multi-thread errors even with nodeSnap being a synronizedList List<Snap> nodeSnap = Collections.synchronizedList(new ArrayList<Snap>());
Really super unsure why it doesn’t like doing it before hand…
All in all, it is a lot faster to pre-process the Snaps outside of the algo, even with a single thread. Is there something in algo.calcPath that isn’t thread safe? Dunno…
Also, something to note;
It is slower to use QueryGraph queryGraph = QueryGraph.create(Graph, List<Snap>snaps);
Just use QueryGraph queryGraph = QueryGraph.create(Graph, Snap, Snap); for each iteration.
I will continue to make improvements where I can, I’m sure someone can see some glaringly obvious improvements so please offer any advice you have
What is important (and this is probably not very intuitive) is that QueryGraph.create()modifies the closest nodes of the snaps. And the reason it does this is that ‘creating’ the query graph means adding virtual nodes and edges to the graph. So without the query graph the virtual nodes that might be the closest do not even exist yet.
I suppose my confusion stemed from the query graph being created from the same base graph so was unsure why node indexes would change.
I was following the examples but couldn’t work out the difference between node indexes from the base graph and node indexes from the query graph.
Thanks for the explanation, it makes it a lot clearer