Skip to content

Select appropriate CH profile when no weighting or vehicle is given - #1790

Merged
easbar merged 4 commits into
masterfrom
missing_vehicle_or_weighting
Nov 12, 2019
Merged

easbar merged 4 commits into
masterfrom
missing_vehicle_or_weighting

Conversation

@easbar

@easbar easbar commented Nov 12, 2019 •

Copy link
Copy Markdown
Member

Fixes #1788 .

This PR reworks the CH profile selection logic and now also handles the cases where the weighting or the vehicle is missing. It now works like this: A request comes in with or without vehicle,weighting,edge_based,u_turn_costs. Missing values are treated as wildcards (match everything). This means that we do not need to specify anything on the request as long as there is only one possible match. When there are multiple matches we throw an error (with one exception, see in code).

The CH profile selection got much simpler. The error responses are now more generic and maybe even more informative. For example if no CH profile matches the request we get:

Cannot find matching CH profile for your request.
requested:  fastest|*|edge_based=true|u_turn_costs=40
available: [fastest|car|edge_based=false|u_turn_costs=-1, fastest|car|edge_based=true|u_turn_costs=30, fastest|car|edge_based=true|u_turn_costs=50]

And when there are are too many matches we get something like:

There are multiple CH profiles matching your request. Use the `weighting`,`vehicle`,`edge_based` and/or `u_turn_costs` parameters to be more specific.
requested:  *|car|edge_based=true|u_turn_costs=*
matched:   [fastest|car|edge_based=true|u_turn_costs=30, fastest|car|edge_based=true|u_turn_costs=50]
available: [fastest|car|edge_based=false|u_turn_costs=-1, fastest|car|edge_based=true|u_turn_costs=30, fastest|car|edge_based=true|u_turn_costs=50]

Here * represents a wildcard, e.g. if the vehicle/weighting/edge_based/u_turn_costs are not given.

if (preparations.isEmpty())
throw new IllegalStateException("No preparations added to this decorator");

// if no weighting or vehicle is specified for this request and there is only one preparation, use it

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.

This was very ugly: If the weighting was missing it was added to the map in CH(!)AlgoFactoryDecorator and LMAlgoFactoryDecorator relied on the CH decorator to add it before we got here...If we did not pay attention to the missing weighting here (now that we no longer add the weighting in the CH decorator) we would get normal AStar instead of LM, see GraphHopperIT#testFlexMode_631.

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.

Uh, sounds ugly.

@easbar

easbar commented Nov 12, 2019

Copy link
Copy Markdown
Member Author

Btw I first tried fixing #1788 in the same kind of style we selected the CH profile so far (see first commit), but I think the new version is much simpler (=better)

@easbar easbar added this to the 1.0 milestone Nov 12, 2019
@easbar
easbar merged commit 524aaea into master Nov 12, 2019

@karussell karussell left a comment

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.

Nice, that looks also like less code 👍

setPreparationThreads(1);
setCHProfilesAsStrings(Arrays.asList(getDefaultProfile()));
// use fastest by default
setCHProfilesAsStrings(Collections.singletonList("fastest"));

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.

What if there is no fastest weighting like just shortest?

@easbar easbar Nov 12, 2019 •

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.

This is not about the CH profile that is selected when a request comes in. The 'default' "fastest" here simply means that if we enable CH on GraphHopper it will use "fastest" for preparation unless we specify some prepare.ch.weightings.

Speaking of the CH profile selection at time of a request: If only shortest is prepared and we do not specify a weighting shortest will be used.

Does this answer your question ?

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.

Ah, thanks!

GHRequest req = new GHRequest(p, q);
// note that we do *not* set the weighting on the request, it will be determined automatically from the
// CH profile, see #1788
req.setWeighting("fastest");

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.

I do not understand this comment as req.setWeighting is called. Can you explain :) ?

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.

Oh thanks for the review! Yes this is a mistake, I probably added this line there and back while testing, will remove it.

if (preparations.isEmpty())
throw new IllegalStateException("No preparations added to this decorator");

// if no weighting or vehicle is specified for this request and there is only one preparation, use it

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.

Uh, sounds ugly.

@easbar
easbar deleted the missing_vehicle_or_weighting branch November 20, 2019 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request fails when not setting the weighting and/or the vehicle with CH and finite u-turn costs

2 participants