Skip to content

Do not consider turn cost support of other encoders when selecting traversal mode - #1705

Merged
easbar merged 6 commits into
masterfrom
issue_1698_traversal_mode
Aug 30, 2019
Merged

easbar merged 6 commits into
masterfrom
issue_1698_traversal_mode

Conversation

@easbar

@easbar easbar commented Aug 28, 2019 •

Copy link
Copy Markdown
Member

This is supposed to be a minimal fix to #1698.

Instead of deriving an 'overall' default traversal mode for all encoders every request checks whether or not the selected encoder supports turn costs and selects the traversal mode based on this (in case no edge_based parameter is sent along with the request).

Fixes #1698, but also related to #1637 and #1702.

@easbar

easbar commented Aug 28, 2019

Copy link
Copy Markdown
Member Author

I think the thing that now bothers me the most is the asymmetry between CH and non-CH: For CH we always use node-based unless edge-based=true is set explicitly. For non-CH we use edge-based as soon as the encoder has |turn_costs=true (and we can go back to node-based by explicitly setting edge_based=false). This also means that with the same settings we might get turn cost support in the one case and no turn cost support in the other (when switching CH on/off).


TraversalMode tMode = encoder.supports(TurnWeighting.class) ? TraversalMode.EDGE_BASED : TraversalMode.NODE_BASED;

String tModeStr = hints.get("traversal_mode", tMode.toString());

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I remove this traversal_mode parameter to avoid further confusion ? Right now it almost does the same as the edge_based parameter and I did not find documentation for it anywhere ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's do this.

@easbar easbar changed the title Do not consider turn cost support of other encoder when selecting traversal mode Do not consider turn cost support of other encoder when selecting traversal modes Aug 28, 2019
@karussell karussell added this to the 0.13 milestone Aug 28, 2019
@karussell

Copy link
Copy Markdown
Member

Should we add this to changes file and mention that edge_base parameter is/was equivalent?

@karussell

Copy link
Copy Markdown
Member

Hmmh, this PR is actually a breaking change for all users that do not yet support edge-based routing for CH but have turn_costs enabled.

@easbar

easbar commented Aug 28, 2019 •

Copy link
Copy Markdown
Member Author

this PR is actually a breaking change f

is it ? in which case ? note that for CH selection we only look at the edge_based request parameter currently (and not at the tMode variable...)

@karussell

karussell commented Aug 28, 2019 •

Copy link
Copy Markdown
Member

Maybe I have misunderstood something :D

Assume I have one vehicle car with turn costs and I have (node-based) CH enabled.

(1) Then request from A to B is per CH (node based) and

(2) if I disable CH it is edge based with turn costs.

Not intuitive, yes. But this was the best we could do for a long time :)

Now, with this change, wouldn't the case (1) fail as the edge based algorithm is selected for CH? And it succeeds only if an additional parameter edge_based=false is specified?

@easbar

easbar commented Aug 28, 2019

Copy link
Copy Markdown
Member Author

Now, with this change, wouldn't the edge based algorithm be selected for CH case (1)

No, I do not think so, but let me add a test to make sure. This of course is an important case.

@easbar

easbar commented Aug 28, 2019

Copy link
Copy Markdown
Member Author

Is this the case you had in mind ? c458149

I think it is fine. Why ? Because tMode is determined to be edge_based at the beginning of GraphHopper#calcPaths, but the CH preparation is later selected solely by the edge_based parameter... (also ugly :))

@easbar

easbar commented Aug 28, 2019

Copy link
Copy Markdown
Member Author

Build failed with

A[PI limit reached. Reset in 14699 seconds]>

anyway, I will re-trigger it again tomorrow

@easbar easbar changed the title Do not consider turn cost support of other encoder when selecting traversal modes Do not consider turn cost support of other encoders when selecting traversal mode Aug 28, 2019
@easbar easbar added the bug label Aug 28, 2019
@easbar

easbar commented Aug 29, 2019

Copy link
Copy Markdown
Member Author

@michaz the GraphHopper#getTraversalMode method is used in map-matching (in MatchingResource and MatchCommand), but can be replaced with

graphHopper.getEncodingManager().needsTurnCostsSupport() ? TraversalMode.EDGE_BASED : TraversalMode.NODE_BASED

?!

Also added this to changelog

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member

Yes! Thank you! In MapMatching, I would also be happy with just always using EDGE_BASED, if it can do strictly more than NODE_BASED. The less combinatorics, the better.

That's why I was so sad at the idea that I could get an exception by choosing EDGE_BASED if some part further down thinks I don't need EDGE_BASED.

@easbar

easbar commented Aug 29, 2019

Copy link
Copy Markdown
Member Author

if it can do strictly more than NODE_BASED.

unfortunately not yet: heading (discussion in #1697), alternative routes (#1524), block edges/areas + its slower and most of all uses a lot more memory (especially for planet-wide)

The less combinatorics, the better.

I can tell ...

That's why I was so sad at the idea that I could get an exception by choosing EDGE_BASED if some part further down thinks I don't need EDGE_BASED

Well if you choose edge_based but the server is not prepared for it its better to get a warning than not ? But I also agree with your kind of thinking (choose behavior not algorithm) so if you choose turn_costs you should not get a warning (just a slow algorithm...)

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member

Sometimes I think half of the configuration confusion (not the implementation limitations) is "just" because a handful of things are historically inside-out or the wrong way round.

Like Alternatives: It's not only a different "algorithm", it's a different question to ask. On that layer, it has as little to do with regular shortest-path routing as map-matching.

I think the implementation of Alternatives should just use node-based routing if it knows it can't do it differently. And not rely on the outer layer to find out for it that node-based can't be configured when Alternatives is configured.

Maybe one day, a "Grand Redesign in the Sky" [Clean Code]. (Or maybe not, because I think most people think that almost always goes wrong.)

@michaz

michaz commented Aug 29, 2019

Copy link
Copy Markdown
Member

EDIT:

"just"

@easbar

easbar commented Aug 29, 2019 •

Copy link
Copy Markdown
Member Author

Regarding combinatorics, look at this:

This is already starting to explode (and the more flexible everything shall become the worse it is going to get). Right now the only way I see out of this mess is to:

  1. assign IDs to 'prepared profiles' that have to be passed back to the engine to specify what profile should be used. if this was on the top layer thats would be the opposite extreme of what you describe with "let user pick behavior not implementation". however, I think we need to put the "select profile based on user needs" logic in front of this. But for this to work we need:

  2. create some way to determine what user needs a profile can support (like 'does it support turn-costs' ? 'can I use this value of u-turn costs for it' ? 'does it allow heading' ? 'is it the fastest possible' ?)

So eventually we would first get a 'wish-list' from the user, then scan the available (CH) profiles and check if there is one that supports everything that was requested by the user. If there is no such profile fall back to some non-CH algorithm that supports everything. However, we still might need some low-level flags for debugging/testing etc. like ('do not fall back to dijkstra', 'enforce this algorithm' etc.)

@easbar

easbar commented Aug 29, 2019

Copy link
Copy Markdown
Member Author

Sometimes I think half of the configuration confusion (not the implementation limitations) is just because a handful of things are historically inside-out or the wrong way round.

I do not know the details of the alternative route implementations, but yes sometimes this might be the problem. Identifying the places where this confusion arises will sure help.

@easbar

easbar commented Aug 29, 2019

Copy link
Copy Markdown
Member Author

Maybe one day, a "Grand Redesign in the Sky" [Clean Code].

I think we should try to improve the current state rather than doing this, but for the flexible CH scenario we are still at the very beginning so its good to think about what would be 'ideal' (and then check how far this is from the current state).

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member

To get this to a point where we say "that's it!" would be a major project, including finding a terminology that we all agree on.

To me, "profile" means "cost function", i.e. "how much does a path cost, including everything", i.e. "what is the thing I want to minimize over all paths".

So it defines things like turn-costs, U-turn restrictions, other hard constraints, everything. Together with input points, headings etc., it's the optimization problem to solve. (Not to be confused with "optimization" as in tour planning.)

That's almost the same as your CHProfile, right? Except that when the required CHProfile isn't there, we can't use CH but can still route?

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member

And then there's an Algorithm, which is a solver for the optimization problem LeastCostPath(Profile, Input). It must support what the Profile requires.

E.g. if the Profile has turn costs, and turn costs don't work with CHNodeBased, then CHNodeBased doesn't support that profile (not the other way round).

The fastest Algorithm that supports what the Profile requires should be used. And it should be selected at startup time, not at query time, because the Algorithm knows what it needs to prepare to support the profile.

Also, at startup time, it can be determined what prepared data can be shared between profiles.

@easbar

easbar commented Aug 29, 2019

Copy link
Copy Markdown
Member Author

That's almost the same as your CHProfile, right?

Yes, I think so. And the reason for this is that almost everything that defines a 'profile' needs to be known at preparation time (for CH). For me a CHProfile is the set of conditions that I fixed when I ran the preparation.

Except that when the required CHProfile isn't there, we can't use CH but can still route?

Yes when a request comes in it defines the/your 'profile', then we have to check if there is a ch-profile that matches it, otherwise we cannot use CH

@michaz

michaz commented Aug 29, 2019

Copy link
Copy Markdown
Member

Nice. Almost there then.

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member

But can't this be simplified enormously if we just give every profile that a GraphHopper instance supports (not only every CHProfile; every profile) a name in the configuration file?

Then, at start time, we prepare the best thing that we can prepare for that profile(*), remember to use it, and that's it?

(* maybe the profile can override at configuration time (but not at query time) what algorithm it wants to be solved by)

@michaz

michaz commented Aug 29, 2019 •

Copy link
Copy Markdown
Member
profiles: {
  carFastestWithTurnCost: {
    linkCostSpecification: {...},
    turnCostSpecification: {...},
    extraHeadingRules: [default] false,
    hints: /* non-functional, only a hint at the algorithm I want to be solved by */ {
      ch: false
    }
  }
}

And then at the totally outermost layer, like in the web service, we pick one of these based on the query parameters. Or if we really want to over-engineer, put the rules for mapping query params to profile names in the config file.

But for ourselves, we can just use the profile name directly in the query, and it's still "problem, not process".

@michaz

michaz commented Aug 29, 2019

Copy link
Copy Markdown
Member

Perhaps the secret blocker here has been that we don't have hierarchical configuration files in the core yet.

@karussell

Copy link
Copy Markdown
Member

Is this the case you had in mind ? c458149

Yes, thanks! Perfect!

@easbar

easbar commented Aug 30, 2019

Copy link
Copy Markdown
Member Author

Hmm, many questions about profile configuration here :) Closing this here, maybe we can continue in issues dedicated to the discussion about the configuration etc. ? For example I opened #1708.

@easbar
easbar merged commit 49b9e1d into master Aug 30, 2019
@easbar
easbar deleted the issue_1698_traversal_mode branch August 30, 2019 13:23
@easbar

easbar commented Jan 30, 2020

Copy link
Copy Markdown
Member Author

But can't this be simplified enormously if we just give every profile that a GraphHopper instance supports (not only every CHProfile; every profile) a name in the configuration file?

@michaz The issue I am having with this is that the profiles may contain parameters. For example the ShortFastestWeighting has a distanceFactor, the DefaultTurnCostProvider has uTurnCosts (and in the future hopefully will have leftTurnCosts, for different roads etc.). There could be blocked_areas as well etc. In other words there is no complete discrete set of profiles we can specify in advance (and give a name to each).

Even if we gave a name to every profile (which otherwise sounds very promising to me) the difficulty would still be mapping the requests onto these profiles. Sure, at first sight this seems easy: As @karussell suggested we could maintain the order of the profiles and if for example vehicle=car is requested we search the list of profiles from top to bottom for profiles with vehicle=car and use the first match. Same with weighting for example. But what if weighting=short_fastest and distance_factor=0.3 (but distance_factor=0.15 was used for the preparation)? Is this a match? How do we even check whether it is a match or not? Which of the request parameters are we supposed to check? Its the same with turn costs: Without CH or even with LM its very easy (in theory) to calculate a single route with different configurations of left/right/u-turn costs etc. (its easy to imagine a weighting (or turn-weighting with tons of parameters), so this is something we should (be able to) support. But as soon as we support this and have all these configuration options how are we supposed to map this onto the CH profiles? Right now we are doing this for edge-weights (#1776) and the answer seems easy in this case: Whenever a CustomModel is sent with the request we just do not use CH. But this is not a good solution for turn costs (or distance_factor with ShortFastestWeighting) where there might be a prepared CH profile, but its just hard to find out if the request matches it.

And then at the totally outermost layer, like in the web service, we pick one of these based on the query parameters

I like the idea of moving this to the outermost layer, but doing the mapping (and this seems like the real problem to me) does not become easier this way (in fact I think it might be harder to do it like that because there might be less information about the profiles at this point?).

Maybe we can even remove all the request parameters that (together) make up the routing profile (currently vehicle,weighting,turn_costs,u_turn_costs) and replace them with a single profile parameter instead?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants