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
LM preparation might run with turn costs even though its node-based #1960
Here: #1949 (comment) we decided to run the LM preparation with node-based graph traversal to make sure there are no turn costs. However, this is not sufficient to disable turn costs. Since the LM preparation runs node-based we cannot include turn costs, but therefore we also have to make sure that the weighting does not return any turn weights (or we have to make the calcWeight method in the algorithm(s)(at least the one for LM preparation) aware of the traversal mode (do not include turn costs for node-based)).
changed the title [-]Disabling turn costs for LM preparation is not working properly[/-][+]LM preparation might run with turn costs even though its node-based[/+]on Mar 18, 2020
Generally, when we run the routing algorithms in node-based mode we do not explicitly make sure that prevOrNextEdgeId==NO_EDGE when calculating the weights, so things can go wrong if we run node-based but our weighting returns finite turn weights. The question is if we should consider this a 'usage error', i.e. our policy would be that we have to make sure that whenever something is running node-based the turn weights must be zero, or if the algorithms should be able to handle this and make sure that whenever some weights are calculated prevOrNextEdgeId is set to NO_EDGE. For the first approach it would be nice to at least somehow check if the turn weights are zero, maybe something like
// in WeightingbooleanhasTurnCosts() {
returnturnCostProvider != NO_TURN_COST_PROVIDER;
}
?
Here is a fix that follows the first approach (make sure the (node-based) LM preparation is running with a weighting that does not have turn costs): 7f33249
And here is a fix that follows the second approach (make sure the prevOrNextEdgeId is NO_EDGE (but we might have to do this in more places then)): 87fe273
Ok thanks for your opinion, I was going back and forth between both and cannot really decide which one I like better. Its certainly a bit ugly that we have to be careful to not run a weighting with non-zero turn costs with node-based algorithms, but checking the traversal mode within the algorithms is also ugly (but we already do this anyway sometimes).
And do you think this is improved if we use do new PMap().put("turn_cost_provider", NO_TURN_COST_PROVIDER)? Then the preparation explicitly decides which provider to use.
I was quite happy with moving the turn cost provider creation into createWeighting(), because the turn weights 'belong' to the weighting so the method creating the weighting should also control this, I thought. What we are dealing with here is really a special case, because the profile shall have turn costs (at request time the weighting to be created should have turn costs) and only during preparation time we do not want turn costs (to keep the weights low and because we did not implement edge-based landmark calculation so far).
It is a bit unfortunate that we cannot let the preparation decide: "hey Weighting class, please throw away your turn cost provider for a moment" :) ... or could we create a new Weighting instance based on the provided one and specify the no_turn_cost_provider? Similar to what we do for the LandmarkStorage.lmSelectionWeighting
I mean even if we took the first approach adding such a check would be a bit more solid?
Hm but how would this help? There is no Weighting (just a weighting strring) up to the point where we call createWeighting. And for LM (different to CH) we already create a new Weighting instance per request. So first for the preparation we want to create the weighting without turn costs (hence the __disable_turn_costs parameter passed to createWeighting). Then for routing requests we want to create weightings with turn costs (which we do since the createWeighting method checks profile.isTurnCosts().
Ah sorry you probably meant to create the weighting in createWeighting as usual (no special handling) and then somehow disable the turn costs just for the Landmark preparation (because Landmark preparation is the only place that should 'know' that it needs to disable turn costs). Well, we could also do the second approach I suggested, but only in LandmarkExplorer. But then I am wondering why do we not just do it in all algorithms. Using a Weighting with turn costs really makes no sense with node-based because when we do calcWeightWithTurnWeight(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) we get 'some' prevOrNextEdgeId, but that does not mean we are updating the spt entries in the right order and maybe it would be just more correct to pass NO_EDGE after all.
hey Weighting class, please throw away your turn cost provider for a moment" :) ... or could we create a new Weighting instance based on the provided one and specify the no_turn_cost_provider?
In principle we could use weighting.setTurnCostProvider() and we do not even have to reset it after the LM preparation, because it will not be used afterwards. However, e.g. for CH this would be a problem at the moment because the weighting is meant to be immutable and is re-used inbetween requests.
tldr: If you do not like the __disable_turn_costs hook in createWeighting (which obviously is a bit of a hack) I think I will try to make sure that we always pass NO_EDGE as prevOrNextEdge in all algorithms if traversalMode is node-based.
But why should algorithms, if traversed via node-based mode, have no access to the real prevOrNextEdge? (I have no use case for this yet, but it still sounds wrong to hide this info)
I think the clean way would be force the no_turn_cost_provider somehow. And as the hack looks relative small we can for now do this and see how far we can go? (maybe the name should be more like lm_preparation_without_turn_costs?)
But why should algorithms, if traversed via node-based mode, have no access to the real prevOrNextEdge? (I have no use case for this yet, but it still sounds wrong to hide this info)
Well they kind of do. Look at AbstractNonCHBidirAlgo#calcWeight for example. This method has access to the current SPTEntry (currEdge), so even more than the previous edge id. The only thing we need to do is to not pass getIncomingEdge(currEdge) into calcWeightWithTurnWeight as prevOrNextEdgeId. Or even better: Do not call calcWeightWithTurnWeight but only calcEdgeWeight in case its node-based. In this case the algorithm would not pass the prevOrNextEdgeId to the weighting yes, but like you say what is that good for unless we have an edge-based algorithm and turn costs? If there is some fancy use case for it one can still overwrite calcWeight.
maybe the name should be more like lm_preparation_without_turn_costs?
This way it would be more obvious that this is meant to be used for lm preparation yes. Then again createWeighting does not need to know anything about LM, all it does is provide a special hook to manually disable the turn cost provider creation. Still, it might be better to rename so its clear that this hook exists but should not necessarily be used for other use-cases...
I think the clean way would be force the no_turn_cost_provider somehow.
Isn't this exactly what we do? Would you prefer a boolean disableTurnCosts parameter in createWeighting()? I used the hintsMap, because in almost any case it will be false. If Java supported this this would be a good use-case for a default parameter maybe, we could also overload the method, but that seemed a bit too much to me...
Activity
[-]Disabling turn costs for LM preparation is not working properly[/-][+]LM preparation might run with turn costs even though its node-based[/+]easbar commentedon Mar 19, 2020
Generally, when we run the routing algorithms in node-based mode we do not explicitly make sure that
prevOrNextEdgeId==NO_EDGEwhen calculating the weights, so things can go wrong if we run node-based but our weighting returns finite turn weights. The question is if we should consider this a 'usage error', i.e. our policy would be that we have to make sure that whenever something is running node-based the turn weights must be zero, or if the algorithms should be able to handle this and make sure that whenever some weights are calculatedprevOrNextEdgeIdis set toNO_EDGE. For the first approach it would be nice to at least somehow check if the turn weights are zero, maybe something like?
Here is a fix that follows the first approach (make sure the (node-based) LM preparation is running with a weighting that does not have turn costs): 7f33249
And here is a fix that follows the second approach (make sure the
prevOrNextEdgeIdisNO_EDGE(but we might have to do this in more places then)): 87fe273karussell commentedon Mar 19, 2020
I like the first approach.
And do you think this is improved if we use do
new PMap().put("turn_cost_provider", NO_TURN_COST_PROVIDER)?Then the preparation explicitly decides which provider to use.
easbar commentedon Mar 19, 2020
Ok thanks for your opinion, I was going back and forth between both and cannot really decide which one I like better. Its certainly a bit ugly that we have to be careful to not run a weighting with non-zero turn costs with node-based algorithms, but checking the traversal mode within the algorithms is also ugly (but we already do this anyway sometimes).
I was quite happy with moving the turn cost provider creation into
createWeighting(), because the turn weights 'belong' to the weighting so the method creating the weighting should also control this, I thought. What we are dealing with here is really a special case, because the profile shall have turn costs (at request time the weighting to be created should have turn costs) and only during preparation time we do not want turn costs (to keep the weights low and because we did not implement edge-based landmark calculation so far).easbar commentedon Mar 19, 2020
To me it would also make sense to have something like
But so far I cannot think of a nice way to add
hasTurnCosts()(but maybe it would be ok the way I suggested above?)I mean even if we took the first approach adding such a check would be a bit more solid?
karussell commentedon Mar 19, 2020
It is a bit unfortunate that we cannot let the preparation decide: "hey Weighting class, please throw away your turn cost provider for a moment" :) ... or could we create a new Weighting instance based on the provided one and specify the no_turn_cost_provider? Similar to what we do for the LandmarkStorage.lmSelectionWeighting
Yes, sounds good.
easbar commentedon Mar 19, 2020
Hm but how would this help? There is no
Weighting(just a weighting strring) up to the point where we callcreateWeighting. And for LM (different to CH) we already create a newWeightinginstance per request. So first for the preparation we want to create the weighting without turn costs (hence the__disable_turn_costsparameter passed tocreateWeighting). Then for routing requests we want to create weightings with turn costs (which we do since the createWeighting method checksprofile.isTurnCosts().easbar commentedon Mar 19, 2020
Ah sorry you probably meant to create the weighting in
createWeightingas usual (no special handling) and then somehow disable the turn costs just for the Landmark preparation (because Landmark preparation is the only place that should 'know' that it needs to disable turn costs). Well, we could also do the second approach I suggested, but only inLandmarkExplorer. But then I am wondering why do we not just do it in all algorithms. Using aWeightingwith turn costs really makes no sense with node-based because when we docalcWeightWithTurnWeight(Weighting weighting, EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId)we get 'some'prevOrNextEdgeId, but that does not mean we are updating the spt entries in the right order and maybe it would be just more correct to passNO_EDGEafter all.easbar commentedon Mar 19, 2020
In principle we could use
weighting.setTurnCostProvider()and we do not even have to reset it after the LM preparation, because it will not be used afterwards. However, e.g. for CH this would be a problem at the moment because the weighting is meant to be immutable and is re-used inbetween requests.easbar commentedon Mar 19, 2020
tldr: If you do not like the
__disable_turn_costshook increateWeighting(which obviously is a bit of a hack) I think I will try to make sure that we always passNO_EDGEasprevOrNextEdgein all algorithms if traversalMode is node-based.karussell commentedon Mar 19, 2020
But why should algorithms, if traversed via node-based mode, have no access to the real
prevOrNextEdge? (I have no use case for this yet, but it still sounds wrong to hide this info)I think the clean way would be force the no_turn_cost_provider somehow. And as the hack looks relative small we can for now do this and see how far we can go? (maybe the name should be more like
lm_preparation_without_turn_costs?)easbar commentedon Mar 19, 2020
Well they kind of do. Look at
AbstractNonCHBidirAlgo#calcWeightfor example. This method has access to the currentSPTEntry(currEdge), so even more than the previous edge id. The only thing we need to do is to not passgetIncomingEdge(currEdge)intocalcWeightWithTurnWeightasprevOrNextEdgeId. Or even better: Do not callcalcWeightWithTurnWeightbut onlycalcEdgeWeightin case its node-based. In this case the algorithm would not pass theprevOrNextEdgeIdto theweightingyes, but like you say what is that good for unless we have an edge-based algorithm and turn costs? If there is some fancy use case for it one can still overwritecalcWeight.This way it would be more obvious that this is meant to be used for lm preparation yes. Then again
createWeightingdoes not need to know anything about LM, all it does is provide a special hook to manually disable the turn cost provider creation. Still, it might be better to rename so its clear that this hook exists but should not necessarily be used for other use-cases...easbar commentedon Mar 19, 2020
Isn't this exactly what we do? Would you prefer a
boolean disableTurnCostsparameter increateWeighting()? I used the hintsMap, because in almost any case it will be false. If Java supported this this would be a good use-case for a default parameter maybe, we could also overload the method, but that seemed a bit too much to me...karussell commentedon Mar 19, 2020
(I meant for an existing Weighting but having it immutable is more important like you said)
So let's do this via the hints (?)
easbar commentedon Mar 19, 2020
Ok lets go with the hints for now :)