You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
do a chgraph.optimize after preparation to make shortcuts more compact. Shortcuts for one node should come after each other. And as we have called disconnect one edge is only used from one node.
special case if just distance&time is necessary, then we do not need to call Path.extract but have the distance&time store in every shortcut
combine with landmarks (currently A* makes CH slower => try same approach we do for edge based CH where we use something similar but not same as usual A* heuristic)
After discussing with @kodonnell (here) it is likely that we traverse unnecessary nodes in CH. Probably 'stall on demand' is the solution. See the overly long shortest path tree of the CH algorithm where the small green dots are start&end:
BTW: Comparing bidir. A* and Dijkstra for CH reveals that the overhead of A* is too much and the nodes difference (<5%) is too small to be competitive.
Wow, that's surprising for such close query points! Though I guess it kind of makes sense - by removing nodes it means that your average remaining node has more edges (I think) and hence more to explore.
I might be able to justify working on these optimisations for my employer (as we've got to route a lot of records). With that in mind, what do you think is best to work on - largest gain in performance vs time to implement (for someone who's still not super familiar with CH etc.)? Stall on demand sounds like it gives quite significant performance gains, so maybe that?
Stall on demand sounds like it gives quite significant performance gains, so maybe that?
Not the simplest one but sounds promising. Depending on your requirements e.g. if you just need distance there are other optimization possible and nice to have where the boost can be of same significance.
Also there are different algorithms which use CH as a preprocessing step (like transit node routing) which kind of convert the routing into a "table lookup process" and have a significant preprocessing overhead but the query time is or can be orders of magnitude faster (according to the papers)
Basically map matching cellular data (i.e. separated by long times/distances), and the outcome is the points/edges travelled (and we'll infer timestamps after that). Alternate routes would be nice, but it doesn't sound feasible to make that fast. (Though we may be be able to create e.g. 1000 slightly randomised CH graphs, to get a similar-ish effect - this is feasible with NZ data, which is relatively small.)
other optimization possible
The ones above, or others? Should we discuss here or somewhere else?
transit node routing
I saw that too. Is that on the roadmap for GH? Or would one create a separate tool (like map-matching)?
Alternate routes would be nice, but it doesn't sound feasible to make that fast.
There are papers to pre-create some via-points which would work for CH too and fast.
other optimization possible
The ones above, or others?
Others like storing not only the weight in the shortcut but also distance and time and then avoid path extraction giving at least a '2x' boost (just compare routing with and without Path.extract()).
Is that on the roadmap for GH? Or would one create a separate tool (like map-matching)?
Everything related to routing should go into GH core. But even for the map matching I'm not 100% sure :) #792
Should we discuss here or somewhere else?
Topic specific here, otherwise in our forum (which I found a bit more convenient as they do not trigger so many emails ;))
There are papers to pre-create some via-points which would work for CH too and fast.
Side issue, but you might find this interesting. For now, we're just trying to get fast map-matching working - if that works, we'll add alternatives (and maybe traffic).
storing not only the weight in the shortcut
OK, I'll look into it. Could you maybe update your original post to include this option (and any more), including your best guess at importance and difficulty? I'll probably do some feasibility tests first on our end, so I know how much more speed we'd like.
transit node routing
I'll move to #841 as it's not directly related to CH performance.
For now, we're just trying to get fast map-matching working - if that works, we'll add alternatives (and maybe traffic).
With 'we' you mean graphhopper community or your company? Regardless of the choice I would be really excited if graphhopper is involved :)
Could you maybe update your original post to include this option (and any more)
including your best guess at importance and difficulty?
I'll probably do some feasibility tests first on our end, so I know how much more speed we'd like.
We have big interests in this as well, so this is 'important' from my perspective, but community can of course define a different 'importance' via their PRs :)
Difficulty: shouldn't be that hard if you know CH a bit and GH a bit, but a bit more complex to digg into all deeper w/o knowledge. No idea. Storing distance&time in shortcuts is simple. A bit problematic could be to calculate time&distance (not only weight) while exploring the shortest path tree (SPT) and keep it as fast (this involves #831). Additionally one has to keep an eye on the memory usage and/or make this 'avoid extract'-thing optional.
With 'we' you mean graphhopper community or your company? Regardless of the choice I would be really excited if graphhopper is involved :)
I hadn't thought of that = ) At this stage I was thinking open source, but I should probably check. There may be commercial interest (I'm not sure anyone's doing it with this type of data on this scale), so we'll see.
'important'
Sorry, I meant how much it's likely to increase performance - so the community can gauge what might be worth working on etc.
keep an eye on the memory usage
Is it acceptable that some use cases use more memory. Obviously we want to be efficient, but I still think it'd be valuable to be able to do more awesome things, even if they could run on mobile devices etc.
I guess a factor of two, again you can test this for your use case if you do not calculate the full path and avoid calling 'extract()' and just pick the weight.
Is it acceptable that some use cases use more memory.
It surely is :), but then it needs to be configurable which often makes things complex too.
I have implemented an experimental (not yet well integrated) version of the stall on demand optimization 5ddf7c0b6e894b6412426c9ba7c2de6d2979e14e. Unfortunately the results are rather disappointing so far. For example the query time for this query on the europe_germany map using algorithm=dijstrabisod (for stall on demand) is longer than for the algorithm without stall on demand (algorithm=dijkstrabi). This is not suprising if we look at some of the statistics of the algorithm. I have simply logged the number of 'touched' nodes i.e. the size of bestWeightMapFrom/To and the number of stalled nodes at the end of the query. For the above query I find:
without stall on demand:
forward search: 1452 touched nodes
backward search: 892 touched nodes
with stall on demand:
forward search: 1433 touched nodes (531 stalled)
backward search: 795 touched nodes (989 stalled)
At least for the queries I tested on the europe_germany map) the number of touched nodes is only slightly reduced by the stalling optimization and thus the overhead for the stalling procedure is too large to achieve faster queries. Generally the number of touched nodes seems very small and right now I am wondering if there would be some cases with significantly more nodes where the stalling might be useful.
Looks interesting. Sorry, I know nothing about the stalling algorithm, but a couple of questions:
are you using CH? If yes, then try without. I remember CH can touch more nodes (generally only for shorter routes I think) but it'd be interesting to compare.
did you use the measurement class to determine the performance between the two?
some possible micro-optimizations (which you need to test - partly as you should always test optimizations - especially as I'm no pro! - and partly as I haven't read/understood your algorithm/code fully):
what about converting stalledNodesTo and stalledNodesFrom to a double array that'll contain the full number of nodes? (This only works as the node IDs are sequential integers.) Then instead of e.g. stalledNodesTo.put(node, value) do stalledNodesTo[node] = value. This might (?) use a lot more memory (but less GC), and might (?) actually be slower (to allocate a large array - unless you can reuse the algorithm), but it should (?) make your gets/sets much faster, and given you do them quite often it might (?) make the algo faster. Given all the ?, you should test with the measurement class = ) Ah - you might want to check out DjikstraOneToMany which I think might use arrays similarly.
can you reuse Queue<SPTEntry> fifo = new LinkedList<>() in runStallingProcess i.e. only create it once for the algorithm, not in each runStallingProcess call? It gets cleared each time anyway, so save the expense of creating one each time.
what about converting GHBitSet visited = new GHBitSetImpl() in runStallingProcess to an integer array (that contains the number of nodes - as above) and making it a property of the algo, i.e. shared between the runStallingProcess calls. To make it re-useable (and avoid having to zero it at the end of each function call), you could then replace the condition visited.contains(nodes) with visited[node] == numCallsOfRunStallingProcess where the latter variable is incremented each time it's called (there might be some natural parameter in the algo you can use - e.g. the number of nodes touched?). When you update, instead of visited.add(node) do visited[node] = numCallsOfRunStallingProcess. This way, the array becomes reusable (without having to clear), you only instantiate once, and you get faster get/set operations.
that all said, if the stalling isn't reducing the number of reached nodes (is this configurable somehow - i.e. can you more 'aggressively' stall?) then maybe it'll only be useful for large queries. In this case, you could create a combined algorithm: if distance between points < X (configurable) use normal CH, otherwise use stall-in-demand.
Nice & thanks @ammagamma ! You can also debug the visited nodes more visually via the MiniGraphUI - this way I got a better understanding of all the algorithms :)
Generally the number of touched nodes seems very small and right now I am wondering if there would be some cases with significantly more nodes where the stalling might be useful.
Hmmh, it is really strange that in the papers they speak about a measureable improvement (50-100%). But I also have found that some results in papers were not reproducable or did not result in an improvement like the dynamic landmark selection. Did you measure this via the Measurement class? If not, please try this and we test CH routing with and without instructions there.
int size = Math.min(Math.max(200, graph.getNodes() / 10), 150_000);
Here you should use the same config as for CH algos: more in the area of 2K
calculatePotentialStallingDistance
Here you seem to mix distance and weight which could lead to strange results. (for car weight=time, for bike weight=time&priority).
Yes, stall on demand is an optimization specially for hierarchical algorithms (like CH (or highway node routing)).
In the literature one can find quite a few different versions of stall on demand, that for example differ in how many nodes are stalled. There is definitely a trade-off between a light-weight search for stallable nodes and a reduced number of visited nodes. My previous implementation used a rather heavy stalling process, which did not lead to a very good speed-up. It also had a few other issues (like using distance instead of weight as @karussell and some more). I have now written a simpler variant of stall on demand that simply prevents expanding a node if it is stallable, see here: #1179. Using the measurement class I find for the map of Germany:
without stall on demand:
routingCH.mean=4.6382589894
routingCH.sum=23191.294947
routingCH.visited_nodes_mean=1289.0619
with stall on demand:
routingCH_sod.mean=3.104524608
routingCH_sod.sum=15522.62304
routingCH_sod.visited_nodes_mean=498.87756
So on this map the new (simpler) version of stall on demand reduces the visited nodes by 62% and yields a speed up factor of about x1.5.
Of course there are still some possible improvements like a more (but not too) aggressive stalling process that searches for more stallable nodes after stalling the current node, which I have not tested yet. Also the ordering of the edges plays a role, because stall on demand needs to differentiate between incoming and outgoing edges.
@kodonnell thank you also for the low level suggestions, but in the new version they do no longer play a role (for now) because none of the previously used data structures are needed anymore.
Activity
karussell commentedon Oct 18, 2016
After discussing with @kodonnell (here) it is likely that we traverse unnecessary nodes in CH. Probably 'stall on demand' is the solution. See the overly long shortest path tree of the CH algorithm where the small green dots are start&end:
BTW: Comparing bidir. A* and Dijkstra for CH reveals that the overhead of A* is too much and the nodes difference (<5%) is too small to be competitive.
improved usage for new query method, with old defaults
kodonnell commentedon Oct 18, 2016
Wow, that's surprising for such close query points! Though I guess it kind of makes sense - by removing nodes it means that your average remaining node has more edges (I think) and hence more to explore.
I might be able to justify working on these optimisations for my employer (as we've got to route a lot of records). With that in mind, what do you think is best to work on - largest gain in performance vs time to implement (for someone who's still not super familiar with CH etc.)? Stall on demand sounds like it gives quite significant performance gains, so maybe that?
karussell commentedon Oct 18, 2016
Not the simplest one but sounds promising. Depending on your requirements e.g. if you just need distance there are other optimization possible and nice to have where the boost can be of same significance.
karussell commentedon Oct 18, 2016
Also there are different algorithms which use CH as a preprocessing step (like transit node routing) which kind of convert the routing into a "table lookup process" and have a significant preprocessing overhead but the query time is or can be orders of magnitude faster (according to the papers)
kodonnell commentedon Oct 18, 2016
Basically map matching cellular data (i.e. separated by long times/distances), and the outcome is the points/edges travelled (and we'll infer timestamps after that). Alternate routes would be nice, but it doesn't sound feasible to make that fast. (Though we may be be able to create e.g. 1000 slightly randomised CH graphs, to get a similar-ish effect - this is feasible with NZ data, which is relatively small.)
The ones above, or others? Should we discuss here or somewhere else?
I saw that too. Is that on the roadmap for GH? Or would one create a separate tool (like map-matching)?
karussell commentedon Oct 18, 2016
There are papers to pre-create some via-points which would work for CH too and fast.
Others like storing not only the weight in the shortcut but also distance and time and then avoid path extraction giving at least a '2x' boost (just compare routing with and without
Path.extract()).Everything related to routing should go into GH core. But even for the map matching I'm not 100% sure :) #792
Topic specific here, otherwise in our forum (which I found a bit more convenient as they do not trigger so many emails ;))
karussell commentedon Oct 18, 2016
Everything related to routing is on the roadmap ;)
kodonnell commentedon Oct 18, 2016
Side issue, but you might find this interesting. For now, we're just trying to get fast map-matching working - if that works, we'll add alternatives (and maybe traffic).
OK, I'll look into it. Could you maybe update your original post to include this option (and any more), including your best guess at importance and difficulty? I'll probably do some feasibility tests first on our end, so I know how much more speed we'd like.
I'll move to #841 as it's not directly related to CH performance.
karussell commentedon Oct 18, 2016
Interesting, thanks for the pointer.
With 'we' you mean graphhopper community or your company? Regardless of the choice I would be really excited if graphhopper is involved :)
We have big interests in this as well, so this is 'important' from my perspective, but community can of course define a different 'importance' via their PRs :)
Difficulty: shouldn't be that hard if you know CH a bit and GH a bit, but a bit more complex to digg into all deeper w/o knowledge. No idea. Storing distance&time in shortcuts is simple. A bit problematic could be to calculate time&distance (not only weight) while exploring the shortest path tree (SPT) and keep it as fast (this involves #831). Additionally one has to keep an eye on the memory usage and/or make this 'avoid extract'-thing optional.
kodonnell commentedon Oct 18, 2016
I hadn't thought of that = ) At this stage I was thinking open source, but I should probably check. There may be commercial interest (I'm not sure anyone's doing it with this type of data on this scale), so we'll see.
Sorry, I meant how much it's likely to increase performance - so the community can gauge what might be worth working on etc.
Is it acceptable that some use cases use more memory. Obviously we want to be efficient, but I still think it'd be valuable to be able to do more awesome things, even if they could run on mobile devices etc.
karussell commentedon Oct 19, 2016
I guess a factor of two, again you can test this for your use case if you do not calculate the full path and avoid calling 'extract()' and just pick the weight.
It surely is :), but then it needs to be configurable which often makes things complex too.
easbar commentedon Apr 27, 2017
I have implemented an experimental (not yet well integrated) version of the stall on demand optimization 5ddf7c0b6e894b6412426c9ba7c2de6d2979e14e. Unfortunately the results are rather disappointing so far. For example the query time for this query on the
europe_germanymap usingalgorithm=dijstrabisod(for stall on demand) is longer than for the algorithm without stall on demand (algorithm=dijkstrabi). This is not suprising if we look at some of the statistics of the algorithm. I have simply logged the number of 'touched' nodes i.e. the size of bestWeightMapFrom/To and the number of stalled nodes at the end of the query. For the above query I find:without stall on demand:
forward search: 1452 touched nodes
backward search: 892 touched nodes
with stall on demand:
forward search: 1433 touched nodes (531 stalled)
backward search: 795 touched nodes (989 stalled)
At least for the queries I tested on the
europe_germanymap) the number of touched nodes is only slightly reduced by the stalling optimization and thus the overhead for the stalling procedure is too large to achieve faster queries. Generally the number of touched nodes seems very small and right now I am wondering if there would be some cases with significantly more nodes where the stalling might be useful.kodonnell commentedon Apr 27, 2017
Looks interesting. Sorry, I know nothing about the stalling algorithm, but a couple of questions:
stalledNodesToandstalledNodesFromto a double array that'll contain the full number of nodes? (This only works as the node IDs are sequential integers.) Then instead of e.g.stalledNodesTo.put(node, value)dostalledNodesTo[node] = value. This might (?) use a lot more memory (but less GC), and might (?) actually be slower (to allocate a large array - unless you can reuse the algorithm), but it should (?) make your gets/sets much faster, and given you do them quite often it might (?) make the algo faster. Given all the?, you should test with the measurement class = ) Ah - you might want to check outDjikstraOneToManywhich I think might use arrays similarly.Queue<SPTEntry> fifo = new LinkedList<>()inrunStallingProcessi.e. only create it once for the algorithm, not in eachrunStallingProcesscall? It gets cleared each time anyway, so save the expense of creating one each time.GHBitSet visited = new GHBitSetImpl()inrunStallingProcessto an integer array (that contains the number of nodes - as above) and making it a property of the algo, i.e. shared between therunStallingProcesscalls. To make it re-useable (and avoid having to zero it at the end of each function call), you could then replace the conditionvisited.contains(nodes)withvisited[node] == numCallsOfRunStallingProcesswhere the latter variable is incremented each time it's called (there might be some natural parameter in the algo you can use - e.g. the number of nodes touched?). When you update, instead ofvisited.add(node)dovisited[node] = numCallsOfRunStallingProcess. This way, the array becomes reusable (without having to clear), you only instantiate once, and you get faster get/set operations.karussell commentedon Apr 28, 2017
Nice & thanks @ammagamma ! You can also debug the visited nodes more visually via the MiniGraphUI - this way I got a better understanding of all the algorithms :)
Hmmh, it is really strange that in the papers they speak about a measureable improvement (50-100%). But I also have found that some results in papers were not reproducable or did not result in an improvement like the dynamic landmark selection. Did you measure this via the Measurement class? If not, please try this and we test CH routing with and without instructions there.
Here you should use the same config as for CH algos: more in the area of 2K
Here you seem to mix distance and weight which could lead to strange results. (for car weight=time, for bike weight=time&priority).
@kodonnell
I think this is feasable only for CH
@ammagamma indeed I've read somewhere about different strategies. But I guess you already use the aggressive variant?
easbar commentedon Oct 6, 2017
Thanks for your comments.
Yes, stall on demand is an optimization specially for hierarchical algorithms (like CH (or highway node routing)).
In the literature one can find quite a few different versions of stall on demand, that for example differ in how many nodes are stalled. There is definitely a trade-off between a light-weight search for stallable nodes and a reduced number of visited nodes. My previous implementation used a rather heavy stalling process, which did not lead to a very good speed-up. It also had a few other issues (like using distance instead of weight as @karussell and some more). I have now written a simpler variant of stall on demand that simply prevents expanding a node if it is stallable, see here: #1179. Using the measurement class I find for the map of Germany:
without stall on demand:
routingCH.mean=4.6382589894
routingCH.sum=23191.294947
routingCH.visited_nodes_mean=1289.0619
with stall on demand:
routingCH_sod.mean=3.104524608
routingCH_sod.sum=15522.62304
routingCH_sod.visited_nodes_mean=498.87756
graph statistics:
graph.nodes=8438035
graph.edges=10722314
graph.valid_edges=10296649
graph.size_in_MB=925
So on this map the new (simpler) version of stall on demand reduces the visited nodes by 62% and yields a speed up factor of about x1.5.
Of course there are still some possible improvements like a more (but not too) aggressive stalling process that searches for more stallable nodes after stalling the current node, which I have not tested yet. Also the ordering of the edges plays a role, because stall on demand needs to differentiate between incoming and outgoing edges.
easbar commentedon Oct 6, 2017
@kodonnell thank you also for the low level suggestions, but in the new version they do no longer play a role (for now) because none of the previously used data structures are needed anymore.
karussell commentedon Jul 22, 2021
We can probably close here as all of the listed items were either implemented or tried without success.
easbar commentedon Jul 22, 2021
Yes, let's close here for now.
Move gear button from CustomModelBox into Search (graphhopper#240)