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
{{ message }}
Repository navigation
Edge-based bidirectional algorithms do not agree with Dijkstra when there is a loop and turn restrictions. #1592
Here is a graph involving a loop and some turn restrictions for which the edge-based bidirectional algorithms do not agree with Dijkstra / do not find the optimal path:
The problem here is that the forward and backward seach uses different edge keys when they discover the loop edge 1-1. This is because of the reverse parameter here:
The forward search uses createEdgeKey(1,1,5,false)=10 while the backward search uses createEdgeKey(1,1,5,true)=11. For non-loop edges it has to be this way to differentiate the two possible directions of an edge, but for a loop the reverse parameter changes the edge key simply depending on which search (fwd/bwd) found it. Because of the different edge keys the according SPTEntry is not found by the opposite search and the best path is not updated for the loop edge (here the traversalId is the edge key):
In principle this would not be a problem because when the search continues one step further the best path will be updated for the next edge, but in the present case the search stops before this happens, because the (suboptimal) path 0-6-4-3 is found just before and the search ends.
changed the title [-]Bidirectional algorithms do not agree with Dijkstra when there is a loop and turn restrictions.[/-][+]Edge-based bidirectional algorithms do not agree with Dijkstra when there is a loop and turn restrictions.[/+]on Apr 11, 2019
I wonder if we could make the result of createEdgeKey independent of the reverse parameter in case the two node ids are equal ?
This would make both 'directions' of the loop be treated equal, but there is no way to differentiate the two directions anyway #1525 which is why we started to exclude the loop edges during the import already #1531.
Ok adjusting createEdgeKey such that it returns the same value for loops regardless of the reverse flag is part one of the puzzle. The second problem is here:
// we detected a u-turn at meeting point, skip if not supported
return;
If entry.adjNode == entryOther.adjNode the best path is not updated, because this situation is interpreted as being a u-turn. However this can happen in two different cases:
there is in fact a u-turn and we have been using TraversalMode.EDGE_BASED_1DIR
we have encountered a loop edge at the meeting point (the situation discussed here)
The best path may only be rejected in the first case.
Or maybe to put it another way I think u-turns should be handled by using infinite turn costs instead of doing explicit u-turn checks at several different places. Simply removing EDGE_BASED_2DIR_UTURN might be possible, but I think it would be nicer to do this together with the above mentioned u-turn cleanup and also this is not related to the present issue.
Activity
easbar commentedon Apr 11, 2019
The problem here is that the forward and backward seach uses different edge keys when they discover the loop edge 1-1. This is because of the
reverseparameter here:graphhopper/core/src/main/java/com/graphhopper/util/GHUtility.java
Lines 461 to 470 in 7b71a24
The forward search uses
createEdgeKey(1,1,5,false)=10 while the backward search usescreateEdgeKey(1,1,5,true)=11. For non-loop edges it has to be this way to differentiate the two possible directions of an edge, but for a loop thereverseparameter changes the edge key simply depending on which search (fwd/bwd) found it. Because of the different edge keys the accordingSPTEntryis not found by the opposite search and the best path is not updated for the loop edge (here the traversalId is the edge key):graphhopper/core/src/main/java/com/graphhopper/routing/AbstractBidirAlgo.java
Lines 240 to 243 in 7b71a24
In principle this would not be a problem because when the search continues one step further the best path will be updated for the next edge, but in the present case the search stops before this happens, because the (suboptimal) path 0-6-4-3 is found just before and the search ends.
So the bug requires:
I wonder if we could make the result of
createEdgeKeyindependent of thereverseparameter in case the two node ids are equal ?[-]Bidirectional algorithms do not agree with Dijkstra when there is a loop and turn restrictions.[/-][+]Edge-based bidirectional algorithms do not agree with Dijkstra when there is a loop and turn restrictions.[/+]easbar commentedon Apr 11, 2019
This would make both 'directions' of the loop be treated equal, but there is no way to differentiate the two directions anyway #1525 which is why we started to exclude the loop edges during the import already #1531.
easbar commentedon May 3, 2019
Ok adjusting
createEdgeKeysuch that it returns the same value for loops regardless of thereverseflag is part one of the puzzle. The second problem is here:graphhopper/core/src/main/java/com/graphhopper/routing/AbstractBidirAlgo.java
Lines 251 to 257 in 7b71a24
If
entry.adjNode == entryOther.adjNodethe best path is not updated, because this situation is interpreted as being a u-turn. However this can happen in two different cases:TraversalMode.EDGE_BASED_1DIRThe best path may only be rejected in the first case.
karussell commentedon May 3, 2019
So we can simplify code just by throwing away 1DIR? If I understand this correctly, then let's remove this (#1520)
easbar commentedon May 3, 2019
Yes the first case is specific to 1DIR and if we remove this TraversalMode we no longer need special handling for it in AbstractBidirAlgo.
easbar commentedon May 3, 2019
Do you mean we should remove 1DIR in the PR for this issue already ? I do not think it requires many changes to remove it.
easbar commentedon May 3, 2019
Not so many changes needed at least in core repo, just tried it:
easbar@81d14b5
karussell commentedon May 3, 2019
This sounds good.
Maybe we could even remove EDGE_BASED_2DIR_UTURN too, i.e. fix #1520 and then fix this here?
easbar commentedon May 3, 2019
Ok will add to the PR.
Hmm I think this requires a little more thought, I would prefer doing this separately.
easbar commentedon May 3, 2019
Or maybe to put it another way I think u-turns should be handled by using infinite turn costs instead of doing explicit u-turn checks at several different places. Simply removing EDGE_BASED_2DIR_UTURN might be possible, but I think it would be nicer to do this together with the above mentioned u-turn cleanup and also this is not related to the present issue.
karussell commentedon May 3, 2019
Ok 👍
Fixes missing best path update for bidir algos when there is a loop a…