Repository navigation
Select appropriate CH profile when no weighting or vehicle is given - #1790
Conversation
| 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 |
There was a problem hiding this comment.
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.
|
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) |
karussell
left a comment
There was a problem hiding this comment.
Nice, that looks also like less code 👍
| setPreparationThreads(1); | ||
| setCHProfilesAsStrings(Arrays.asList(getDefaultProfile())); | ||
| // use fastest by default | ||
| setCHProfilesAsStrings(Collections.singletonList("fastest")); |
There was a problem hiding this comment.
What if there is no fastest weighting like just shortest?
There was a problem hiding this comment.
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 ?
| 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"); |
There was a problem hiding this comment.
I do not understand this comment as req.setWeighting is called. Can you explain :) ?
There was a problem hiding this comment.
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 |
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:
And when there are are too many matches we get something like:
Here
*represents a wildcard, e.g. if the vehicle/weighting/edge_based/u_turn_costs are not given.