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
Setting different speeds for both directions can cause problems with loops #1631
Routing can fail if we use MotorCycleEncoder instead of CarFlagEncoder and there are loops (for OSM they are excluded during import though), because motorcycle allows setting different speeds for both directions. See this branch: motorcycle_edge_based_ch_bug
The test only shows the problem for edge-based CH, but I am not sure if it could be a problem for other (edge-based ?) algorithms as well, not sure if this is fully covered by tests.
The test only shows the problem for edge-based CH, but I am not sure if it could be a problem for other (edge-based ?) algorithms as well, not sure if this is fully covered by tests.
Yes, this is a problem for all edge-based algorithms and its nothing specific to edge-based CH. We cannot reliably use different speeds for the two directions for loops. The current solution is still that loops are excluded during the import. Here is a recent commit where RandomizedRoutingTest fails sometimes (run it many times): eda2b53
Interestingly the test is 'fixed' by bbb15df, but this is only because with this commit the speeds aren't properly set to different values due to a changed randomGraph method, see this comment: #2202 (comment)
In our current model loops with different properties for the two directions are not well defined. Every edge has an edge ID, a base node ID (A) and an adj node ID (B). A loop is an edge where A=B. The direction of an edge is the </> relation between A and B, but since A=B a loop has only one direction. Therefore setting different edge properties for the 'fwd' and 'bwd' direction of a loop is just wrong. Currently there are a few places (like DefaultEdgeFilter) where we do special handling for loop edges, but these would not be necessary if we did not use direction-dependent properties for loop edges in the first place. Can we somehow deny setting different values for fwd/bwd directions on loops? We probably need to enforce 'storeTwoDirections=false' for loops or something?
This should not be confused with loop shortcuts in edge-based CH. The direction of these loop shortcuts is actually well defined, because of the first/last orig edges.
... or we even reject setReverse entirely for loops? (but then the calling code always needs to check for loops). Right now we are already in the situation where we have to check 'storeTwoDirections' before calling setReverse
we get loop.get(property) == false (even though we just set it to true.
Reject setReverse for loops altogether. This way we are forced to check if an edge is a loop before calling setReverse which seems reasonable to me. But what about getReverse? Again we could reject it for loops, but then we even have to check for loops when calling the getter. This seems cumbersome to me. We could forward loop.getReverse() to loop.get(), or set the reverse property also when we call loop.set(). The usage would be like this:
Probably only an error if the property has support for one value per direction?
This is another good question. Currently we have this in set(property, boolean fwd, boolean bwd):
if (!property.isStoreTwoDirections())
throw new IllegalArgumentException("EncodedValue " + property.getName() + " supports only one direction");
But why is it not also an error to call setReverse when !property.isStoreTwoDirections. Isn't it like when we only have one direction there is no 'reverse' property so we can only use get/set (and not getReverse/setReverse)?
Yes, second options sounds reasonable. And you would then remove the special handling for loops on import?
Ok and yes hopefully we can remove the special handling then. However, we probably need another special handling then. In case there are actual loops in OSM with different speeds for the two directions or different geometries etc. (does this exist?) we actually have to add two loops (one for each direction). And right now I am wondering if this can cause other problems, like turning from one loop to the other etc.
we actually have to add two loops (one for each direction).
Probably we need to do this for all loops, because otherwise we won't be able to e.g. block one direction dynamically... But once we start adding two loop edges for all loop ways, maybe we can just as well split all loop ways into two edges like we currently do and stop using loops in BaseGraph altogether?!
But why is it not also an error to call setReverse when !property.isStoreTwoDirections.
We can try this and see if test succeed. Maybe the problem was that our code is in general "direction-dependent" and calls setReverse explicitly even if not stored separately.
maybe we can just as well split all loop ways into two edges like we currently do and stop using loops in BaseGraph altogether?!
Ok. If it makes so many problems and we already avoid this in the import, why not :) ?
Ok. If it makes so many problems and we already avoid this in the import, why not :) ?
I put in a lot of effort to make e.g. edge-based CH work with base-graph loops (shortcut loops are always necessary). And for all I know it is working, so we solved a lot of problems related to such loops already and maybe we can handle loops / deal with a base graph structure that allows loops. But with my current knowledge I think directed loops are ill-defined so there is still some work to get this right. At the same time right now I do not know about a single 'real' use-case for loop edges and this somewhat suggests that we maybe should just not spend time dealing with loops. Loop ways in OSM can be split into two edges. Loop edges used to represent stations in PT are only used because LocationIndex can only find edges, but these can be replaced by small loops as well (according to @michaz). Can you think of other potential use-cases for loops?
We allow setting different speeds, access etc. for the two directions of each edge (including loops)
When we traverse edges using EdgeExplorer we process one edge ID at a time. Each edge ID represents two directions (two edge keys). The routing algorithms typically only consider one of these directions (only outgoing edges for the forward search, only incoming edges for the backward search), i.e. they call get(speedEnc) or getReverse(speedEnc) but not both.
For loops we need to consider both directions. This is why we already adjusted the DefaultEdgeFilter so it accepts loops if only one of the two directions is accessible:
However, given only an edgeID it is unclear which direction should be considered to calculate e.g. the weight.
For the weight calculation we blindly call get/getReverse for the forward/backward search and since for loops we always get the same direction in some cases we get the wrong one. Actually there is not even a 'correct' direction and for loops we would have to consider both directions or take the minimum of the forward and backward weight.
I think it is not worth it to mess around with loops any longer and we should just remove them from our graph model altogether.
Removing loops seems rather simple, because we already exclude them in OSMReader and all the tests that fail when we reject loops are testing whether we can deal with loops if they exist. The real issue is the PT module where we use loops here:
Activity
easbar commentedon Jun 1, 2019
The test only shows the problem for edge-based CH, but I am not sure if it could be a problem for other (edge-based ?) algorithms as well, not sure if this is fully covered by tests.
easbar commentedon Dec 13, 2020
Yes, this is a problem for all edge-based algorithms and its nothing specific to edge-based CH. We cannot reliably use different speeds for the two directions for loops. The current solution is still that loops are excluded during the import. Here is a recent commit where
RandomizedRoutingTestfails sometimes (run it many times): eda2b53Interestingly the test is 'fixed' by bbb15df, but this is only because with this commit the speeds aren't properly set to different values due to a changed
randomGraphmethod, see this comment: #2202 (comment)Add comment about #1631 for tests
easbar commentedon Feb 28, 2021
In our current model loops with different properties for the two directions are not well defined. Every edge has an edge ID, a base node ID (A) and an adj node ID (B). A loop is an edge where A=B. The direction of an edge is the
</>relation between A and B, but since A=B a loop has only one direction. Therefore setting different edge properties for the 'fwd' and 'bwd' direction of a loop is just wrong. Currently there are a few places (likeDefaultEdgeFilter) where we do special handling for loop edges, but these would not be necessary if we did not use direction-dependent properties for loop edges in the first place. Can we somehow deny setting different values for fwd/bwd directions on loops? We probably need to enforce 'storeTwoDirections=false' for loops or something?This should not be confused with loop shortcuts in edge-based CH. The direction of these loop shortcuts is actually well defined, because of the first/last orig edges.
easbar commentedon Mar 1, 2021
Maybe we could replace, for example:
with
? i.e. for loop edges we set the opposite direction always to the same value that is being set automatically?
easbar commentedon Mar 1, 2021
... or we even reject setReverse entirely for loops? (but then the calling code always needs to check for loops). Right now we are already in the situation where we have to check 'storeTwoDirections' before calling setReverse
easbar commentedon Mar 15, 2021
We have a few options:
we get
loop.get(property) == false(even though we just set it totrue.setReversefor loops altogether. This way we are forced to check if an edge is a loop before callingsetReversewhich seems reasonable to me. But what aboutgetReverse? Again we could reject it for loops, but then we even have to check for loops when calling the getter. This seems cumbersome to me. We could forwardloop.getReverse()toloop.get(), or set the reverse property also when we callloop.set(). The usage would be like this:Any opinions about this? I have a small preference for the second option.
karussell commentedon Mar 15, 2021
Yes, second options sounds reasonable. And you would then remove the special handling for loops on import?
Probably only an error if the property has support for one value per direction?
easbar commentedon Mar 15, 2021
This is another good question. Currently we have this in
set(property, boolean fwd, boolean bwd):But why is it not also an error to call
setReversewhen!property.isStoreTwoDirections. Isn't it like when we only have one direction there is no 'reverse' property so we can only use get/set (and not getReverse/setReverse)?Ok and yes hopefully we can remove the special handling then. However, we probably need another special handling then. In case there are actual loops in OSM with different speeds for the two directions or different geometries etc. (does this exist?) we actually have to add two loops (one for each direction). And right now I am wondering if this can cause other problems, like turning from one loop to the other etc.
easbar commentedon Mar 15, 2021
Probably we need to do this for all loops, because otherwise we won't be able to e.g. block one direction dynamically... But once we start adding two loop edges for all loop ways, maybe we can just as well split all loop ways into two edges like we currently do and stop using loops in
BaseGraphaltogether?!karussell commentedon Mar 16, 2021
We can try this and see if test succeed. Maybe the problem was that our code is in general "direction-dependent" and calls setReverse explicitly even if not stored separately.
Ok. If it makes so many problems and we already avoid this in the import, why not :) ?
easbar commentedon Mar 16, 2021
I put in a lot of effort to make e.g. edge-based CH work with base-graph loops (shortcut loops are always necessary). And for all I know it is working, so we solved a lot of problems related to such loops already and maybe we can handle loops / deal with a base graph structure that allows loops. But with my current knowledge I think directed loops are ill-defined so there is still some work to get this right. At the same time right now I do not know about a single 'real' use-case for loop edges and this somewhat suggests that we maybe should just not spend time dealing with loops. Loop ways in OSM can be split into two edges. Loop edges used to represent stations in PT are only used because LocationIndex can only find edges, but these can be replaced by small loops as well (according to @michaz). Can you think of other potential use-cases for loops?
easbar commentedon Mar 16, 2021
Just to be clear what the real issue is:
EdgeExplorerwe process one edge ID at a time. Each edge ID represents two directions (two edge keys). The routing algorithms typically only consider one of these directions (only outgoing edges for the forward search, only incoming edges for the backward search), i.e. they callget(speedEnc)orgetReverse(speedEnc)but not both.DefaultEdgeFilterso it accepts loops if only one of the two directions is accessible:graphhopper/core/src/main/java/com/graphhopper/routing/util/DefaultEdgeFilter.java
Lines 58 to 68 in e9a2f9b
I think it is not worth it to mess around with loops any longer and we should just remove them from our graph model altogether.
Removing loops seems rather simple, because we already exclude them in
OSMReaderand all the tests that fail when we reject loops are testing whether we can deal with loops if they exist. The real issue is the PT module where we use loops here:graphhopper/reader-gtfs/src/main/java/com/graphhopper/gtfs/GtfsReader.java
Line 125 in 7cbb248
graphhopper/reader-gtfs/src/main/java/com/graphhopper/gtfs/GtfsReader.java
Line 571 in 7cbb248
enable bidir tests (#1631)