Skip to content

LM preparation might run with turn costs even though its node-based #1960

Closed

Description

@easbar

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)).

Activity

  1. added this to the 1.0 milestone on Mar 18, 2020
  2. 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
  3. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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 Weighting
    boolean hasTurnCosts() {
        return turnCostProvider != 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

  4. karussell commented on Mar 19, 2020

    @karussell
    Member

    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.

  5. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    I like the first approach.

    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).

  6. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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,

    To me it would also make sense to have something like

    if (!traversalMode.isEdgeBased() && weighting.hasTurnCosts())
        throw new IllegalArgumentException("Node-based routing does not work with turn costs");

    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?

  7. karussell commented on Mar 19, 2020

    @karussell
    Member

    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?

    Yes, sounds good.

  8. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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().

  9. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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.

  10. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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.

  11. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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.

  12. karussell commented on Mar 19, 2020

    @karussell
    Member

    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?)

  13. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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...

  14. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    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...

  15. karussell commented on Mar 19, 2020

    @karussell
    Member

    Isn't this exactly what we do?

    (I meant for an existing Weighting but having it immutable is more important like you said)

    So let's do this via the hints (?)

  16. easbar commented on Mar 19, 2020

    @easbar
    MemberAuthor

    Ok lets go with the hints for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions