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
Reduce TraversalModes to edge- and node-based. #1520
What about TraversalMode.EDGE_BASED_1DIR ? Does it have any valid use-case ? It does edge-based routing, but does not differentiate between the two possible directions an edge (identified by its ID) is encountered (so it only uses one 'state' for each edge (instead of two), thats the 1DIR part of the name). It can model turn restrictions and costs, but for example it cannot find a path with a p-turn. The javadocs say that it is
Strictly not recommended as it could lead to 'route not found' for bidirectional algorithms.
I think if there is a required p-turn it can also lead to route not found for standard Dijkstra ? On the other hand according to the javadocs it is
As fast as node-based
Would be interesting to know if anybody is actively using TraversalMode.EDGE_BASED_1DIR and for which purpose ?
Yes, 1DIR is really nice but only theoretically. I think in practise the only good solution for edge-based algorithm is bidirectional landmarks with 2DIR. IMO we can remove two of the four modes.
Ok, TraversalMode.EDGE_BASED_1DIR was removed with #1606. Next one on the list will be TraversalMode.EDGE_BASED_2DIR_UTURN and then we can eventually rename EDGE_BASED_2DIR to EDGE_BASED. I think removing the u-turn mode is mostly about removing/replacing TraversalMode#hasUTurnSupport. Instead of checking something like
if (traversalMode.hasUTurnSupport() && edgeA==edgeB)
or
if (traversalMode.hasUTurnSupport() && turnCostExtension.isUTurn(edgeA, edgeB)
we should just 'calculate' the turn costs and by default return infinity if edgeA==edgeB or turnCostExtension.isUTurn(edgeA, edgeB). @karussell do you remember why this was not done like this from the beginning ? I never understood why instead these explicit u-turn checks were introduced. Maybe I am missing something here ? If one wants to enable/allow u-turns (possibly only under certain conditions, like smaller roads etc.) it would still be possible to do this in the calcTurnWeight method (and this would probably be even more flexible than explicit u-turn checks within the algorithms).
Actually I am thinking about deprecating and/or removing TurnWeighting completely and as a replacement adding a calcTurnWeight method to Weighting (probably with a default implementation in AbstractWeighting). There are a few cases where we only want to calculate the turn costs (NOT edge costs plus turn costs), this was already mentioned in #269. Therefore I think the focus should be on a calcTurnWeight(inEdge, viaNode, outEdge) method instead of calcWeight(edgeState, reverse, prevOrNextEdgeId), but of course we can keep the latter as a convenience method that uses the other one. Similar would be a calcTurnTime method. I guess we have to start doing this refactoring a bit to fully become aware of all of its implications.
Regarding TurnWeighting there are quite a few related issues:
I never understood why instead these explicit u-turn checks were introduced. Maybe I am missing something here ?
I do not now. Maybe this is still an artifact from the early days somehow where turn costs were under development. Another reason could be a faster decision? Isn't the current procedure to always call calcWeight and then calcTurnWeight - i.e. the first call would be unnecessary in case of an infinite turn weight? But I think we can just swap this order and also have this optimization not only for U-turns.
BTW: I'm still not sure if we really need calcTurnWeight. I know we already discussed this in
Ah good point. Yes it might be better to first calculate the turn costs, but not sure if this plays a big role and pretty sure we can apply such optimization on a lower level.
I'm still not sure if we really need calcTurnWeight.
Yes, good question. I think it would make sense to have a convention that 'turn weight' is always measured in time-units. If this is so we can use it for both weight- and time-calculation. For weightings that are not based on time (like curvature, energy, shortest weighting, or shortestfastestweighting) one would have to use some conversion factor that balances the edge-weight with the turn-weight contributions.
Or in other words I think we do not need calcTurnWeight. Let's just use calcTurnTime and how this contributes to a given weighting is up to the author of the weighting.
However, we should not have to add edge-weights to turn-times, this would look confusing:
and to prevent this having something like weighting.calcWeight(edge, reverse, prevOrNext) still makes sense I guess.
Would these 3 issues still exist if the calcTurnWeight/Time is within the Weighting?
No I think they would be solved, except the one with the loop-case. That one we could probably deal with at a central place in calcTurnWeight/Time and further loop-related changes (also mentioned in #1611) should go with another issue.
Oh, I think I have to correct myself here: I was only thinking about the case where we calculate edgeWeight+turnWeight. If this is encapsulated in a calcWeight method in Weighting sure we can take the turn time and add it to the total weight with whatever conversion factor we like (for example when thinking about how much turn times should contribute to curvature weighting etc.). But what about the cases where calcTurnWeight/Time is called in isolation (for example at the meeting point of a bidirectional search). In this case we would only be left with calcTurnTime and the conversion would not be specific to the weighting. So now I am back to thinking we do need calcTurnTimeandcalcTurnWeight.
However, we should not have to add edge-weights to turn-times, this would look confusing:
So maybe still call it calcTurnWeight but make it clear that it returns a value measured in time-units ?
This is a good argument :) ... still we would have to do the same for the time: calcMillis = time + calcTurnWeight? So maybe we have to live with two methods? (or calcTurnWeightInMillis ;) just joking!)
So now I am back to thinking we do need calcTurnTime and calcTurnWeight.
👍
and to prevent this having something like weighting.calcWeight(edge, reverse, prevOrNext) still makes sense I guess.
Activity
easbar commentedon May 3, 2019
What about
TraversalMode.EDGE_BASED_1DIR? Does it have any valid use-case ? It does edge-based routing, but does not differentiate between the two possible directions an edge (identified by its ID) is encountered (so it only uses one 'state' for each edge (instead of two), thats the 1DIR part of the name). It can model turn restrictions and costs, but for example it cannot find a path with a p-turn. The javadocs say that it isI think if there is a required p-turn it can also lead to route not found for standard Dijkstra ? On the other hand according to the javadocs it is
Would be interesting to know if anybody is actively using
TraversalMode.EDGE_BASED_1DIRand for which purpose ?karussell commentedon May 3, 2019
Yes, 1DIR is really nice but only theoretically. I think in practise the only good solution for edge-based algorithm is bidirectional landmarks with 2DIR. IMO we can remove two of the four modes.
easbar commentedon May 25, 2019
Ok,
TraversalMode.EDGE_BASED_1DIRwas removed with #1606. Next one on the list will beTraversalMode.EDGE_BASED_2DIR_UTURNand then we can eventually renameEDGE_BASED_2DIRtoEDGE_BASED. I think removing the u-turn mode is mostly about removing/replacingTraversalMode#hasUTurnSupport. Instead of checking something likeor
we should just 'calculate' the turn costs and by default return infinity if
edgeA==edgeBorturnCostExtension.isUTurn(edgeA, edgeB). @karussell do you remember why this was not done like this from the beginning ? I never understood why instead these explicit u-turn checks were introduced. Maybe I am missing something here ? If one wants to enable/allow u-turns (possibly only under certain conditions, like smaller roads etc.) it would still be possible to do this in thecalcTurnWeightmethod (and this would probably be even more flexible than explicit u-turn checks within the algorithms).Actually I am thinking about deprecating and/or removing
TurnWeightingcompletely and as a replacement adding acalcTurnWeightmethod toWeighting(probably with a default implementation inAbstractWeighting). There are a few cases where we only want to calculate the turn costs (NOT edge costs plus turn costs), this was already mentioned in #269. Therefore I think the focus should be on acalcTurnWeight(inEdge, viaNode, outEdge)method instead ofcalcWeight(edgeState, reverse, prevOrNextEdgeId), but of course we can keep the latter as a convenience method that uses the other one. Similar would be acalcTurnTimemethod. I guess we have to start doing this refactoring a bit to fully become aware of all of its implications.Regarding
TurnWeightingthere are quite a few related issues:karussell commentedon May 26, 2019
I do not now. Maybe this is still an artifact from the early days somehow where turn costs were under development. Another reason could be a faster decision? Isn't the current procedure to always call calcWeight and then calcTurnWeight - i.e. the first call would be unnecessary in case of an infinite turn weight? But I think we can just swap this order and also have this optimization not only for U-turns.
BTW: I'm still not sure if we really need calcTurnWeight. I know we already discussed this in
#1586 (review) and #1590 (comment)
but I'm unsure what to do now. Personally I would prefer to just have one method calcTurnTime if no difference is necessary.
I have no preference
Would these 3 issues still exist if the calcTurnWeight/Time is within the Weighting?
easbar commentedon May 27, 2019
Ah good point. Yes it might be better to first calculate the turn costs, but not sure if this plays a big role and pretty sure we can apply such optimization on a lower level.
Yes, good question. I think it would make sense to have a convention that 'turn weight' is always measured in time-units. If this is so we can use it for both weight- and time-calculation. For weightings that are not based on time (like curvature, energy, shortest weighting, or shortestfastestweighting) one would have to use some conversion factor that balances the edge-weight with the turn-weight contributions.
Or in other words I think we do not need
calcTurnWeight. Let's just usecalcTurnTimeand how this contributes to a given weighting is up to the author of the weighting.However, we should not have to add edge-weights to turn-times, this would look confusing:
So maybe still call it
calcTurnWeightbut make it clear that it returns a value measured in time-units ?I was wondering how many times we will do something like this:
and to prevent this having something like
weighting.calcWeight(edge, reverse, prevOrNext)still makes sense I guess.No I think they would be solved, except the one with the loop-case. That one we could probably deal with at a central place in
calcTurnWeight/Timeand further loop-related changes (also mentioned in #1611) should go with another issue.easbar commentedon May 27, 2019
Oh, I think I have to correct myself here: I was only thinking about the case where we calculate edgeWeight+turnWeight. If this is encapsulated in a
calcWeightmethod inWeightingsure we can take the turn time and add it to the total weight with whatever conversion factor we like (for example when thinking about how much turn times should contribute to curvature weighting etc.). But what about the cases wherecalcTurnWeight/Timeis called in isolation (for example at the meeting point of a bidirectional search). In this case we would only be left withcalcTurnTimeand the conversion would not be specific to the weighting. So now I am back to thinking we do needcalcTurnTimeandcalcTurnWeight.karussell commentedon May 27, 2019
This is a good argument :) ... still we would have to do the same for the time:
calcMillis = time + calcTurnWeight? So maybe we have to live with two methods? (orcalcTurnWeightInMillis;) just joking!)👍
This is true 👍
easbar commentedon Jun 27, 2019
Update: the u-turn mode has been removed in #1640 and the
TraversalModes are now reduced toNODE_BASEDandEDGE_BASED.Leaving this open for now because of the issue about moving
calcTurnWeight/TimetoWeighting.easbar commentedon Dec 9, 2019
Closing in favor of #1820