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
Route request fails if edge_based is not set to false and there is a turn cost encoder #1698
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.
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.
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?
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).
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.
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)...
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.
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 ?
did not specify edge_based at all
edge_based=true/false and CH is enabled, but no corresponding profile is present
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:
remove all the encoder.supports(TurnWeighting.class) checks that are used to determine the traversal mode. This includes the traversalMode field in GraphHopper (I mentioned already).
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.
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?
Activity
michaz commentedon Aug 27, 2019
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?
easbar commentedon Aug 27, 2019
When we do not use a
TurnWeightingu-turns will not have any cost (because instead of using manual u-turn checks the u-turn costs are now applied inTurnWeighting).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.michaz commentedon Aug 27, 2019
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.)
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?
michaz commentedon Aug 27, 2019
Alternatively, it could be (conceptually) infinity and behave like before. :)
easbar commentedon Aug 27, 2019
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 useturn_costs=trueand thought it would be better to get an error in this case (#1696). To make it crystal clear we would neededge_based=true&turn_costs=false?. I think there are a few places where we do not clearly make a distinction betweenedge_based=trueand (the hypothetical)turn_costs=true(as request parameter).michaz commentedon Aug 27, 2019
I'm not even sure why
edge_basedis 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?
michaz commentedon Aug 27, 2019
On the other hand, on the Java layer, it does make a difference, because there I get different things into my shortest-path tree.
michaz commentedon Aug 27, 2019
Yeah, exactly.
easbar commentedon Aug 28, 2019
I think I agree.
edge_basedis also very technical and its rather counter-intuitive one has to setedge_based=trueto enable 'turn costs'. Maybe this parameter should be calledturn_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_modeparameter (but it is overwritten by theedge_basedparameter)...easbar commentedon Aug 28, 2019
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.easbar commentedon Aug 28, 2019
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_modeparameter for now, because it does not do anything theedge_basedparameter cannot do).edge_based=true/false/not setChoosing 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:
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=trueit 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
traversalModefield inGraphHopperasks 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/falsedoes 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 routingedge_based=true-> edge-based routingLooks simple, but what are the corner cases ?
edge_basedat allregarding 1): if
edge_basedis 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 inconfig.ymlvia a new propertydefaultTraversalMode. Maybe we can add a special valueautothat determines a good default (like in 2) and 3)). btw to have 'not specified' with a post request (#1689) we need to allownull.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 foredge_basedis different to this (sayedge_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:
encoder.supports(TurnWeighting.class)checks that are used to determine the traversal mode. This includes thetraversalModefield inGraphHopper(I mentioned already).traversalModerequest parameter (save it for later, Route request fails if edge_based is not set to false and there is a turn cost encoder #1698)defaultTraversalModewith anautooption to `config.yml'WDY ? I am rather unsure tbh...
michaz commentedon Aug 29, 2019
Actually, I think
ch.disableshould 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.
devemux86 commentedon Aug 29, 2019
GraphHopper documentation mentions several cases which can work only without CH (e.g. heading, alternative routes).
So mean that the requests can be inspected and the proper mode be selected afterwards based on their parameters?
michaz commentedon Aug 29, 2019
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.
Yep.
Do not consider turn cost support of other encoders when selecting tr…