Repository navigation
Removes TraversalMode.EDGE_BASED_2DIR_UTURN - #1640
Conversation
| } | ||
| if (weighting instanceof TurnWeighting) { | ||
| time += ((TurnWeighting) weighting).calcTurnWeight(inEdge, viaNode, outEdge) * 1000; | ||
| // bugfix: should be cleaned up with u-turn refactoring #1520 |
There was a problem hiding this comment.
this is no longer needed, because calcTurnWeight now includes u-turn costs.
| @Override | ||
| public void visit(EdgeIteratorState edge, boolean reverse, int prevOrNextEdgeId) { | ||
| distance += edge.getDistance(); | ||
| // a one-way loop that is not a shortcut cannot possibly be read in the 'right' direction, because |
There was a problem hiding this comment.
I have changed calcMillis such that loops are read in fwd direction only so this is no longer needed here. This change is not strictly related to removing the u-turn mode though.
| * times slower than node based. | ||
| */ | ||
| EDGE_BASED_2DIR_UTURN(true, true); | ||
| EDGE_BASED(true); |
There was a problem hiding this comment.
Should we keep EDGE_BASED_2DIR as alias for EDGE_BASED for better compatibility with user code ?
There was a problem hiding this comment.
I'm for removing (as it is easy to do on the user code side)
| public class AlternativeRouteTest { | ||
| private final FlagEncoder carFE = new CarFlagEncoder(); | ||
| private final EncodingManager em = EncodingManager.create(carFE); | ||
| private final TurnCostExtension turnCostExtension = new TurnCostExtension(); |
There was a problem hiding this comment.
This test was using edge-based traversal mode but without TurnWeighting I had to adjust this otherwise the routes would contain u-turns. This is somewhat nasty unfortunately.
There was a problem hiding this comment.
Should we write this in the changelog that using edge-based alternative routes is now only possible with enabled turn costs?
| continue; | ||
| } | ||
| // minor speed up | ||
| // todonow: really ? |
There was a problem hiding this comment.
Yes, I think so. It was basically copied from Dijkstra where we introduced this a long time ago:
There was a problem hiding this comment.
Ok I removed my todo comment. Isochrone uses node-based traversal, so it is not really related to this PR (?).
There was a problem hiding this comment.
Ah no, the same check was applied for other algorithms via AbstractRoutingAlgorithm#accept. First I thought this is only harmful because it prevents u-turns regardless of the u-turn costs configured in TurnWeighting, but for node-based traversal this check is ok and saves us calculating some edge-weights etc.
-> I have included this check in accept again, but only for node-based traversal.
karussell
left a comment
There was a problem hiding this comment.
Thanks, this looks good! Nice that so many things could be removed!
Have just some cosmetic requests
| * times slower than node based. | ||
| */ | ||
| EDGE_BASED_2DIR_UTURN(true, true); | ||
| EDGE_BASED(true); |
There was a problem hiding this comment.
I'm for removing (as it is easy to do on the user code side)
| * todo: this should be cleaned up in #1520. | ||
| */ | ||
| public double calcTurnWeight(int edgeFrom, int nodeVia, int edgeTo) { | ||
| if (edgeFrom == EdgeIterator.NO_EDGE || edgeTo == EdgeIterator.NO_EDGE) { |
There was a problem hiding this comment.
Do you think the EdgeIterator.isValid is more clear here (and in the calcMillis)?
| if (edgeFrom == EdgeIterator.NO_EDGE || edgeTo == EdgeIterator.NO_EDGE) { | ||
| return 0; | ||
| } | ||
| if (turnCostExt.isUTurn(edgeFrom, edgeTo)) { |
There was a problem hiding this comment.
If there is an explicit turn cost stored in the data - then it will be overwritten from this. Should we document this?
I guess this problem was already the case before this PR but the intention was that it should be picked from the data IMO (at least the name setDefaultUTurnCost implies this ;))
There was a problem hiding this comment.
Yes this has always been like this and this is why I changed the name from defaultUTurnCost to uTurnCost. Maybe we should check if this is really important for performance. It saves us from looking up the turn cost value from turn cost extension when edgeFrom==edgeTo, but this is only a fraction of all turns (we still look up the value for all pairs of edges where edgeFrom!=edgeTo). If we want to do something like default left-turn costs or similar we would not be able to do it the same way, because in this case it would be required to check, e.g. for a turn restriction on a left turn.
I added a comment about this in the TurnWeighting constructor.
| public TurnWeighting setDefaultUTurnCost(double costInSeconds) { | ||
| defaultUTurnCost = costInSeconds; | ||
| public TurnWeighting setUTurnCost(double costInSeconds) { | ||
| uTurnCost = costInSeconds; |
There was a problem hiding this comment.
Maybe we remove this setter and move it to a new constructor?
| TurnWeighting result = new TurnWeighting(new FastestWeighting(encoder), tcs); | ||
| if (!Double.isInfinite(uTurnCosts)) { | ||
| result.setUTurnCost(uTurnCosts); | ||
| } |
There was a problem hiding this comment.
Can this be moved into the new constructor?
There was a problem hiding this comment.
yes this was unnecessary anyway.
| continue; | ||
| } | ||
| // minor speed up | ||
| // todonow: really ? |
There was a problem hiding this comment.
Yes, I think so. It was basically copied from Dijkstra where we introduced this a long time ago:
|
Thanks for the review! |
This PR removes
TraversalMode.EDGE_BASED_2DIR_UTURNand renamesTraversalMode.EDGE_BASED_2DIRtoTraversalMode.EDGE_BASED, see #1520.So far we were able to set turn costs for each junction via
TurnCostExtensionand wrap aWeightingwithTurnWeighting, which applies turn costs incalcMillis/calcWeight. To make sure the turn costs are considered when calculating routes the routing algorithms need to be passed thisTurnWeighting. For u-turns we can choose a default cost which is defined within theTurnWeightingobject. So far this default u-turn cost was set to40sand to prevent u-turns there were explicit u-turn checks within the algorithms that were or were not applied depending on theTraversalModewe used.I do not see a good reason why there are these explicit u-turn checks and have thus changed the code in this PR such that:
TurnWeighting).So for routing with turn costs but without u-turns we previously did this:
and now we do this:
For routing with turn costs and including u-turns we previously did this:
and now we do this:
Note that we now have to choose
TraversalMode.EDGE_BASEDand useTurnWeightingto enable turn costs and exclude u-turns. If we useTraversalMode.EDGE_BASED, with a normalWeightingthe resulting route might include u-turns. This is the price we pay for removing the explicit u-turn checks I think.Another issue was that
TurnWeighting#calcTurnWeightdid not include the default u-turn costs and returned 0 for u-turns (unless set explicitly). I have changed this so u-turn costs are included now.The default u-turn costs overwrite any manually set u-turn cost in
TurnCostExtensionand there is no way to apply specific u-turn costs on a per-junction basis. Checking for explicit turn costs inTurnCostExtensionbefore applying the default u-turn costs would be expensive. It is probably rare that one needs to set explicit u-turn costs, but if one wants to set default left-turn costs (or similar) this is a problem. To make this more clear I have renameddefaultUTurnCosttouTurnCost.I think this PR is a step in the right direction, because 'applying turn costs' is no longer spread over different parts of the code (traversal mode/explicit u-turn checks + turn weighting), but maybe we should go further and remove
TurnWeightingentirely. I will open another issue/PR for this.