Repository navigation
Implements a simple version of stall-on-demand for CH queries. - #1179
Conversation
| // if using none-bidirectional algorithm make sure you exclude CH routing | ||
| final String algoStr = ch ? Algorithms.DIJKSTRA_BI : Algorithms.ASTAR_BI; | ||
| put(prefix + ".guessed_algorithm", algoStr); | ||
| String guessed_algorithm = ch ? ("".equals(algoStr) ? DIJKSTRA_BI : algoStr) : Algorithms.ASTAR_BI; |
There was a problem hiding this comment.
Getting the guessed algorithm string seems rather messy (?) ;)
|
Wow, cool - will try! |
|
Wow, really nice & thanks a lot! I can confirm this is a huge improvement from 3.9ms to 2.7ms in my case (measurement of Germany & car) |
| private PriorityQueue<SPTEntry> pqOpenSetFrom; | ||
| private PriorityQueue<SPTEntry> pqOpenSetTo; | ||
| protected PriorityQueue<SPTEntry> pqOpenSetFrom; | ||
| protected PriorityQueue<SPTEntry> pqOpenSetTo; |
There was a problem hiding this comment.
Can we make it package protected instead? As it is not final this is a bit unsafe to allow subclasses access to it.
| public static final String DIJKSTRA_BI = "dijkstrabi"; | ||
| /** | ||
| * Bidirectional Dijkstra making use of stall-on-demand optimization | ||
| */ |
There was a problem hiding this comment.
A new internal parameter is ok for tests and comparison etc, but I wouldn't make this official in the Parameters class as I think we have to make SOD the default :)
| + " time:" + Helper.round2(sodRsp.getBest().getTime() / 1000) + ", original: " + Helper.round2(stdRsp.getBest().getTime() / 1000) | ||
| + " points:" + sodRsp.getBest().getPoints().size() + ", original: " + stdRsp.getBest().getPoints().size(); | ||
|
|
||
| if (Math.abs(1 - sodRsp.getBest().getRouteWeight() / stdRsp.getBest().getRouteWeight()) > 0.000001) |
There was a problem hiding this comment.
Ah, really nice that you did this test too!
|
|
||
| void fillEdges(SPTEntry currEdge, PriorityQueue<SPTEntry> prioQueue, | ||
| IntObjectMap<SPTEntry> bestWeightMap, EdgeExplorer explorer, boolean reverse) { | ||
| protected void fillEdges(SPTEntry currEdge, PriorityQueue<SPTEntry> prioQueue, |
There was a problem hiding this comment.
This should not be necessary IMO
There was a problem hiding this comment.
If we want to use package private and still use this method (and pqOpenSetFrom/To) we need to move DijkstraBidirectionCHWithSOD to the same package as DijkstraBidirectionRef. In this case I would also move DijkstraBidirectionCH and AStarBidirectionCH from PrepareContractionHierarchies to com.graphhopper.routing. I would find this cleaner anyway ;)
|
BTW: for disabled instructions the improvement is even bigger: 2.9ms vs. 1.5ms! |
|
Seem impressive results! |
|
Wow this sounds very impressive! If I understand this correctly we only stall a node when we are sure that the path via this node is worse than a previously found path. We do this by checking the current weight + the weight to one of the next edges is higher than the previously calculated best weight. Could it happen that we due to this incorrectly stall a node and might not find the best path anymore? Probably this situation is impossible because of the hierarchy and due to this it is guaranteed that we always find the best path? |
|
Thanks for testing everyone! |
Thanks for the answer. I thought that this would work due to the hierarchical properties of CH, but I couldn't proof it myself :).
Ah that's interesting, so the stalling only happens for one direction. That makes sense. |
…algorithms to routing package.
|
|
||
| @Override | ||
| public String getName() { | ||
| return "dijkstrabinosod|ch"; |
There was a problem hiding this comment.
If the version with stall on demand becomes the default, maybe change the class names as well ?
There was a problem hiding this comment.
Should we use a more readable name dijkstrabi_no_sod?
There was a problem hiding this comment.
or even dijkstrabi|ch|no_sod?
|
|
||
| @Override | ||
| public String getName() { | ||
| return "dijkstrabinosod|ch"; |
There was a problem hiding this comment.
Should we use a more readable name dijkstrabi_no_sod?
|
|
||
| @Override | ||
| public String getName() { | ||
| return "dijkstrabinosod|ch"; |
There was a problem hiding this comment.
or even dijkstrabi|ch|no_sod?
| printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1, ""); | ||
| printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_sod_no_instr", vehicleStr, false, -1, DIJKSTRA_BI_SOD); | ||
| printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true, -1); | ||
| printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1); |
There was a problem hiding this comment.
also here I would test 1. with SOD 2. without SOD and 3. with SOD and no instructions instead of running two queries per printTimeOfRouteQuery call
|
some integration tests are failing now that sod is used by default, will have a look ;) |
Stall on demand can prevent finding a shortest path if the weight of an edge depends on the driving direction as with Motorcycle or Bike2 weightings.
When checking the stall on demand condition so far the wrong edge direction was used to calculate the weight of the incoming edge.
| * Uses a very simple version of stall-on-demand (SOD) for CH queries to prevent exploring nodes that can not be part | ||
| * of a shortest path. When a node that is about to be settled is stallable it is not expanded, but no further search | ||
| * for neighboring stallable nodes is performed. | ||
| */ |
There was a problem hiding this comment.
Feel free to add an @author tag here.
| * @author Peter Karich | ||
| */ | ||
| public class PrepareContractionHierarchies extends AbstractAlgoPreparation implements RoutingAlgorithmFactory { | ||
| public static final String STALL_ON_DEMAND = "stall_on_demand"; |
There was a problem hiding this comment.
Should this better go into the Parameters class?
There was a problem hiding this comment.
Or should we probably hide this config and do not even make it public? (At least it needs the ch. prefix)
There was a problem hiding this comment.
it was in Parameters.Algorithms before :) Maybe Parameters.CH would be a good place for it ?
There was a problem hiding this comment.
I think it is useful to be able to deactivate it for example in the Measurement class
There was a problem hiding this comment.
:D ... oh ... so yes, lets keep it here but reduce visibility? I currently do not see a case where it would make sense to disable stalling except for debugging and performance measurements. And then we could use the pure string without introducing some public usable constants.
There was a problem hiding this comment.
I usually prefer constants so I can search for usages, but you probably want to keep the public API as small as possible to reduce compatibility problems in future versions I guess. In this case yes I would make the constant private or remove it and just use the string value where it is needed.
There was a problem hiding this comment.
Yes, exactly. The only solution would be package protected but would not help much here.
|
Looks like I am too used to IntelliJ's organize imports feature ... |
|
Great PR, thanks for the awesome work. Just to make sure, this does not change the graph generation in any way, meaning, if I imported a graph before that PR, this graph is still perfectly valid and functional? From looking at the code, I would assume that this should be the case, just wanted to make sure. |
|
Yes a previous graph should still work, the graph pre-processing is the same and only the query algorithm is changed. |
This is a simple version of stall-on-demand that leads to a 1.5x speed up of CH queries on the osm map for Germany. Also see discussion in: #240.
I put the stall-on-demand version of the bidirectional ch dijkstra into a separate class, because PrepareContractionHierarchies already seems very large (?). I thought it would be better to leave it up to configuration whether stall-on-demand is used or not. I also added some measurement tests for stall on demand in the measurement class. Not sure if this is really needed, but for testing it is helpful at the moment. I might test some of the more aggressive versions of stall on demand if I find the time.