Repository navigation
Extract profile selection - #1949
Conversation
# Conflicts: # core/src/main/java/com/graphhopper/GraphHopper.java # core/src/main/java/com/graphhopper/routing/lm/LMPreparationHandler.java
| // to allow e.g. changing the u_turn_costs per request (we have to use the minimum weight settings ( | ||
| // = no turn costs) for the preparation) | ||
| // todonow: is it too ugly this way? | ||
| Weighting weighting = createWeighting(profile, new PMap().put("__disable_turn_costs", true)); |
There was a problem hiding this comment.
Any opinion here? createWeighting normally uses a DefaultTurnCostProvider if profile.isTurnCosts()==true. But for LM we always want to enforce not using turn costs for the preparation, but to me it seemed like this does not justify adding an extra parameter, so I am using the pmap workaround here...
There was a problem hiding this comment.
I would not do this here and just force the usage of no turn cost provider in LM. IMO this is something implementation specific?
There was a problem hiding this comment.
What do you mean? You mean we should always set turn_costs: false for all profiles with LM? But then we cannot use turn costs with LM...
There was a problem hiding this comment.
Ah you mean somehow disabling the turn costs in PrepareLandmarks? Yes that would be the right thing to do, but how? PrepareLandmarks just gets a Weighting, but how would it disable the turn costs then?
There was a problem hiding this comment.
Ah you mean somehow disabling the turn costs in PrepareLandmarks?
Yes. Isn't it already ignored when we do traversalMode = TraversalMode.NODE_BASED in LandmarkStorage?
There was a problem hiding this comment.
Ah yes thats a good point. Yes that should fix it 👍 -> done
| FlagEncoder encoder = encodingManager.getEncoder(vehicle); | ||
| HintsMap hintsMap = new HintsMap(); | ||
| RouteResource.initHints(hintsMap, uriInfo.getQueryParameters()); | ||
| hintsMap.put(Parameters.CH.DISABLE, true); |
There was a problem hiding this comment.
Is it fine to overwrite ch/lm.disable here or should we throw an error?
There was a problem hiding this comment.
Isn't the none-CH case the default now? But yeah, I think I had to do this for the /custom endpoint too.
There was a problem hiding this comment.
Hm, no graphHopper.resolveProfile(hintsMap) will give us a CH profile or error if it does not exist, so we have to explicitly disable CH/LM to obtain the profile no matter whether a CH/LM profile for these hints exists or not.
There was a problem hiding this comment.
So, if there is a profile without CH, then this will work without the parameter, but if the profile is listed in profiles_ch then we need the disabling parameter?
The problem is, what if we add a new algorithm xy? Then in theory I would expect that the profile selection remains unchanged and we only specify profiles_xy: [car_xy], i.e. an existing profile car will still work without the algorithm xy. Not sure if this is good as it increases the profile count further.
There was a problem hiding this comment.
So, if there is a profile without CH, then this will work without the parameter, but if the profile is listed in profiles_ch then we need the disabling parameter?
Yes, or to put it differently if we put ch.disable=true as we do here we get the profile matching our hints no matter what LM/CH preparations there are (and for isochrones we are not even using them). But you are right the profile selection depends on the available LM/CH preparations (it always did).
The problem is, what if we add a new algorithm xy? Then in theory I would expect that the profile selection remains unchanged
But why? If there is a new algorithm we likely want to use it? If the selection remained unchanged what would the new algorithm be good for? In this sense I think its better not to expose the algorithm selection such that it can always be changed internally. As a user of the API I am generally not interested which algorithm is used to solve my problem. What I think is problematic though, that sometimes it can be hard to figure out which algorithm needs to be used, because for certain parameters only certain algorithms work (for example blocked areas etc.).
There was a problem hiding this comment.
Ok, regarding the parameter setting and I think I better understand this now: we have to do it here to avoid a failure if LM or CH is configured.
| Boolean edgeBased = getEdgeBased(hintsMap); | ||
| Integer uTurnCosts = getUTurnCosts(hintsMap); | ||
| return (edgeBased == null || p.isEdgeBased() == edgeBased) && | ||
| (uTurnCosts == null || p.getWeighting().getTurnCostProvider().getName().equals(uTurnCosts.toString())) && |
There was a problem hiding this comment.
I do not like how we rely on the turn cost provider name to contain the u-turn costs here, but so far I do not have a better idea to do this. Also this is only needed to cover a (probably exotic) case: Multiple edge-based profiles with different u-turn costs. Once we have the profile request parameter we 'only' need to support this u-turn costs comparison here for legacy reasons, so this makes me even more want to get rid of it.
There was a problem hiding this comment.
Yes, probably we have to accept that ProfileResolver is mainly for backward compatibility? The bigger problem is the new getTurnCostProvider method, which I would prefer to be private. But I also do not see how.
There was a problem hiding this comment.
Yes, I would like to remove/not add getTurnCostProvider as well. But how else can we check what u-turn costs a weighting is using? Maybe we can skip this selection rule and throw an error if there are multiple edge-based weightings for the given weighting and vehicle. In this case one would have to use the profile parameter when using multiple edge-based CH preparations with different u-turn costs.
There was a problem hiding this comment.
Yes, probably we have to accept that ProfileResolver is mainly for backward compatibility?
Yes absolutely, maybe not yet in this PR but ProfileResolver only exists for backward-compatibility.
There was a problem hiding this comment.
In this case one would have to use the profile parameter when using multiple edge-based CH preparations with different u-turn costs.
This sounds not too bad.
| createWeighting(profile, new PMap()); | ||
| } catch (IllegalArgumentException e) { | ||
| // todonow: update, what are we really checking here? | ||
| throw new IllegalArgumentException("The profile '" + profile.getName() + "' was configured with an unknown weighting '" + profile.getWeighting() + "'"); |
There was a problem hiding this comment.
Ah ok. The graph being null problem when running this check should also be already fixed with this: 639bd9a
There was a problem hiding this comment.
Aha, where did you stumble over this?
There was a problem hiding this comment.
Well its required for this branch because the turn cost provider is created in createWeighting now (and thus there is a call to ghStorage.getTurnCostStorage()).
|
@easbar I just noticed when I merged this PR into another PR: why has the hopper.createWeighting(profileConfig, hints) method a separate |
|
No its not identical. The idea is that hints are the hints we get from a request (in addition to the selected profile). For example in case we select a profile with short_fastest weighting the |
|
Ok, I see. So all hints unrelated to the profile like which algo (e.g. ch/lm.disable) go into that extra hint. |
|
Yes, exactly. But we might have to add some 'merging' rules (like take the distance factor from profile.hints, but if hints also has it overwrite it). This will be similar to using server-custom-models and overwriting with request-custom-models? |
Hmmh, this is a bit ugly. I think we should either make the difference really strict or use only one HintsMap. Because otherwise we end up looking into two maps for all internal usage. For CustomModel this is a bit different as we can do the merging part without internal knowledge because the "CustomRequest" is automatically serialized into a CustomModel via jackson as it has only up-front-known parameters. For example: |
What do you mean?
This is not possible imo, because the two maps are two different things: One contains the parameters that were configured on the server side and the other contains the parameters passed in with the request by the user.
Yes, and I think this is exactly what we want: There are two different sets of parameters and it should be up to 'us' or whoever implements the method what to do (how to create a weighting) with these parameters.
Why are we supposed to do this without internal knowledge about the profile? I understand |
|
Ah, ok. So the "general query hints" are the only thing we need and use inside the Weighting but still the profile.hints could modify this "general query hints" if necessary (?) And the current location where this "overwrite" happens is in GraphHopper.createWeighting. I see ... I had planned (for the CustomModel) the "overwrite" to happen before that method to keep the params of that method low. |
|
Yes there are query hints and properties given in the profile. Ok, we could do the overwrite before
Ok if this is somehow required for |
Yes, maybe this is a good idea. The problem at the moment is that hints only allows "flat" But maybe a simpler solution could be to allow |
|
Sure yes we can change this to |
….hints, see discussion in #1949
This PR aims to extract all the code that is related to selecting the routing profile using the different request parameters like
vehicleandweighting. The idea is that here we put all this code into a single place (ProfileResolver) and as a follow-up we can then put thisProfileResolverin front ofGraphHopper#calcPathsetc. (c.f. #1859).Fixes #1800.