Skip to content

Route request fails if edge_based is not set to false and there is a turn cost encoder #1698

Closed

Description

@easbar

If we use multiple encoders out of which one has turn_costs=true, e.g. foot,car|turn_costs=true, we have EncodingManager#needsTurnCostsSupport()===true and the GraphHopper#traversalMode field will be EDGE_BASED (see GraphHopper#setEncodingManager). This traversalMode field is then used to determine the traversal mode in GraphHopper#calcPaths.

It can be overwritten using the edge_based or the traversal_mode parameters, but since these are optional it might remain EDGE_BASED even when using a vehicle without turn costs (like foot). So we use edge-based routing for foot, just because there is another encoder with turn_costs=true.

This used to be odd behavior, but with #1696 this is now even more problematic because we now get an exception in this case.

I think we should remove the GraphHopper#traversalMode field entirely, because it seems very counter-intuitive to determine the 'default' traversal mode based on the presence of some encoder that supports turn costs.

Related: #1637

Activity

  1. michaz commented on Aug 27, 2019

    @michaz
    Member

    Why can't I do edge-based routing when I don't have turn costs?

    I mean, I know I can only have turn costs when I do edge-based routing, but why the other way round?

  2. easbar commented on Aug 27, 2019

    @easbar
    MemberAuthor

    When we do not use a TurnWeighting u-turns will not have any cost (because instead of using manual u-turn checks the u-turn costs are now applied in TurnWeighting).

    Is there a need for edge-based routing when there are no turn costs ? If yes should "no turn costs" also mean "u-turns are allowed (and free)" ? We can probably support this when we remove TurnWeighting, #1520 #1820.

  3. michaz commented on Aug 27, 2019

    @michaz
    Member

    Is there a need for edge-based routing when there are no turn costs ?

    Not sure if need, but I'm currently doing it in one experiment and it works nicely, when I just want to enumerate (directed) edges rather than nodes. (With the previous version.)

    If yes should "no turn costs" also mean "u-turns are allowed (and free)"

    Yeees. At least that's what I would think is consistent. I mean, with node-based traversal, you can't have U-turns on shortest paths because.. well, you've already been there. But with (directed) edges.. No problem.

    I like that this is an actual weight now, and not a hard constraint, but I think a default of 0 would be no problem, would it?

  4. michaz commented on Aug 27, 2019

    @michaz
    Member

    Alternatively, it could be (conceptually) infinity and behave like before. :)

  5. easbar commented on Aug 27, 2019

    @easbar
    MemberAuthor

    when I just want to enumerate (directed) edges rather than nodes.

    you mean you are looking at the discovered edges when running dijkstra or something ?

    I don't think there is a real reason to not be able to run an edge-based algorithm without turn costs. I just spent an hour wondering why I was always getting u-turns (although I was using edge_based=true) until I figured out that my encoder did not use turn_costs=true and thought it would be better to get an error in this case (#1696). To make it crystal clear we would need edge_based=true&turn_costs=false ?. I think there are a few places where we do not clearly make a distinction between edge_based=true and (the hypothetical) turn_costs=true (as request parameter).

  6. michaz commented on Aug 27, 2019

    @michaz
    Member

    I'm not even sure why edge_based is on the API at all. I mean, from that layer, it's an implementation detail. We must know when we need to use which algorithm. In particular, when there are non-zero turn-costs.

    Why do we let the user decide that?

  7. michaz commented on Aug 27, 2019

    @michaz
    Member

    On the other hand, on the Java layer, it does make a difference, because there I get different things into my shortest-path tree.

  8. michaz commented on Aug 27, 2019

    @michaz
    Member

    you mean you are looking at the discovered edges when running dijkstra or something ?

    Yeah, exactly.

  9. easbar commented on Aug 28, 2019

    @easbar
    MemberAuthor

    I'm not even sure why edge_based is on the API at all.

    I think I agree. edge_based is also very technical and its rather counter-intuitive one has to set edge_based=true to enable 'turn costs'. Maybe this parameter should be called turn_costs=true. But then how would you enable edge based routing without turn costs ?

    To make matters a bit more complicated there is also a traversal_mode parameter (but it is overwritten by the edge_based parameter)...

  10. easbar commented on Aug 28, 2019

    @easbar
    MemberAuthor

    I opened #1702 for the question about edge-based without turn_costs. The (probably more urgent) issue here is to prevent the error that we are currently getting without setting edge_based=false.

  11. easbar commented on Aug 28, 2019

    @easbar
    MemberAuthor

    Puh this all seems rather tricky (sorry long post)...

    When we make a request we basically have these parameters that are relevant to the algorithm selection (I am leaving out the traversal_mode parameter for now, because it does not do anything the edge_based parameter cannot do).

    • edge_based=true/false/not set
    • choose a vehicle
    • enable/disable CH

    Choosing the vehicle makes a difference, because we check encoder.supports(TurnWeighting.class), which is the same as checking whether or not the encoder was specified with |turn_costs=true, and use the result to determine the algorithm.

    But what do we even expect ? Let's have a look at this table:

    edge_based encoder supports turn costs expected without CH expected with CH
    not set false what should be the default ? node-based ? node-based! (there is no edge-based CH)
    not set true what should be the default? edge-based because the encoder supports turn costs ? what should be the default ? node-based because its faster ?
    false false node-based node-based
    false true node-based node-based
    true false error ? or edge-based without turn costs ? error! (no CH profile)
    true true edge-based, with turn costs edge-based, with turn costs

    With CH we are a bit more constrained than without: When an encoder supports turn costs there can be two different CH profiles (one for edge-based and one for node-based). So we can still ask whether or not the chosen encoder/vehicle supports turn costs or not, but just because we use car|turn_costs=true it does not mean that we are (only) interested in edge-based routing, because we have to specify it like this even when we want both node- and edge-based CH... Therefore using this information to determine the traversal mode for the algorithm seems wrong to me.

    In the current state it is even more intricate: The traversalMode field in GraphHopper asks whether or not some of the encoders supports turn costs (this is what this issue is about), but in my opinion this should not be considered at all and even without this its not entirely clear to me what we expect in the different cases.

    I think it is important that specifying ch.disable=true/false does not change whether or not turn costs are applied or not (the algorithm should just do the same except faster/slower). So from this point of view it seems reasonable to use the expectations we have for CH ?!

    I am hoping we can simplify the whole matter when we no longer look at the vehicle to determine the traversal mode: So what if we did this:

    • edge_based=false -> node-based routing
    • edge_based=true -> edge-based routing

    Looks simple, but what are the corner cases ?

    1. did not specify edge_based at all
    2. edge_based=true/false and CH is enabled, but no corresponding profile is present
    3. edge_based=true but no turn cost extension for this vehicle

    regarding 1): if edge_based is not specified we need to use some default. node-based is faster, edge-based supports turn-costs, IMO we cannot know what is the 'better' default. So lets make this configurable in config.yml via a new property defaultTraversalMode. Maybe we can add a special value auto that determines a good default (like in 2) and 3)). btw to have 'not specified' with a post request (#1689) we need to allow null.

    regarding 2): when there is no CH profile for the settings that were used we should simply get an error. but there is an ugly special case: e.g. when only one profile is used (say car|edge) and the default for edge_based is different to this (say edge_based=false) we get an error, this is #1637.

    regarding 3): throw an error.

    tldr

    To make the algorithm selection consistent between CH/non-CH and make the behavior more transparent I suggest to:

    WDY ? I am rather unsure tbh...

  12. michaz commented on Aug 29, 2019

    @michaz
    Member

    Actually, I think ch.disable should go away as well. Or at least be demoted to something unimportant, where there's never an error if this option isn't specified at all. The default should be picked based on what's possible and necessary to satisfy the user's question.

    So when the user asks for least-cost path with turn costs on bikes, then we should pick our fastest algorithm that supports least-cost paths with turn costs on bikes. Only if answering the user's question isn't possible should there be an error.

    I define "different algorithms" as "different ways of solving the same problem (same input -> same output)". I'm not sure why the API user should have an important voice in picking the algorithm. It is fine as a technical parameter, of course, for experiments, debugging, and such. But they should never be required to set it to get a specific result.

  13. devemux86 commented on Aug 29, 2019

    @devemux86
    Contributor

    I think ch.disable should go away as well.

    GraphHopper documentation mentions several cases which can work only without CH (e.g. heading, alternative routes).

    The default should be picked based on what's possible and necessary to satisfy the user's question.

    So mean that the requests can be inspected and the proper mode be selected afterwards based on their parameters?

  14. michaz commented on Aug 29, 2019

    @michaz
    Member

    GraphHopper documentation mentions several cases which can work only without CH (e.g. heading, alternative routes).

    Exactly my point.

    If you look at Google's API, for instance -- they don't mention the algorithms they use. They just mention the problems they solve. So you can pick "our best estimate of travel time, considering current traffic", which probably requires a much more expensive algorithm, so it is more expensive.

    But you pick the problem you want to solve, not the way it is solved.

    So mean that the requests can be inspected and the proper mode be selected afterwards based on their parameters?

    Yep.

  15. added a commit that references this issue on Aug 30, 2019
    49b9e1d
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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions