New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use regular weighting if no CH weighting is available #631
Use regular weighting if no CH weighting is available #631
Conversation
I just had this issue, after rerunning the tests, this was solved. Has been also reported in #625
|
Makes Sense. I updated this PR. (And created a Merge Conflict with my latest PR ...). Should fix #491, I guess. |
Thanks! The control flow is via try-catch and more implicit. I would avoid this and specify the String perRequestCHFlexibleMode = request.getHints().get("ch.flexible_mode", false);
if(perRequestCHFlexibleMode && !chFlexibleMode) {
rsp.addError(new some exception);
return Collections.emptyList();
}
if (chEnabled && !perRequestCHFlexibleMode) ... Which means the slow requests are explicitely wanted not only from the server side but also expected from the client side. Also we need test for this and the exception ... I can add those. BTW: in JSON and URL we do not use camel case but in java params we do like e.g. |
@karussell I updated my branch. I am not sure if we really should add the flexible mode to the request as well. This is an overhead on the client-side. Clients have to figure if the should query the flexible mode or the speed mode. |
Thanks!
Yes, sure. But with this the client decides e.g. if he wants more speed or more features (roughly speaking). How should we handle such a logic on the server side? |
Well, we could query if there is CHWeighting that matches, if not just use a NON-CHWeighting. In this way we could work around the try catch exception stuff. On the other hand, this might slow down requests out of nothing (from a user perspective). So I am not sure which solution is preferred. |
I mean there are currently also cases like turn restrictions and heading which are not supported by CH where the client should be able to force flexibility mode even if the weighting supports CH.
Exactly that is the reason I think that the overhead on the client side is okay, as the client then knows it needs to handle larger response times and potentially notify the user. |
Yes probably you are right. |
I am currently looking into this. I found that if we use a weighting that was prepared for ch and query the flexible mode (e.g. for TurnRestrictiions) we get an exception since the graph is expecting CHEdges. Any ideas what to do in this case? Should we ignore that case for now? Here is the StackTrace:
|
Do you mean if we set |
@karussell exactly. Thanks for the hint. There is already a CHAlgorithmFactory registered for that weighting. We could create a new tempFactory for that case. We could check |
Ah, thanks - this is indeed very ugly. Maybe instead of replacing we should chain the factories? E.g. if no matching algorithm is found in CH factory ( |
@karussell What do you mean by replacing and chaining? Maybe we could add a property to the AbstractWeighting that defines if the weighting is CH or not. We could change the equals method of the AbstractWeighting to also match that property. Therefore, we could have different Factories for CH and Non-Ch. What do you think? |
With chaining I mean that E.g. class PrepareContractionHierarchies {
...
public RoutingAlgorithm createAlgo( Graph graph, AlgorithmOptions opts ){
if(opts.getHints().get("flexibility", false)) {
super.createAlgo(graph, opts);
} else {
/* do CH stuff */
}
}
} Or instead the map we should have a list and create a more sophisticated "parameter matching" selecting the appropriate factory/algorithm.
There is and should be no difference between a CH and a flexible weighting :/ |
Ah ok, now I get your idea. The benefit would be that we do not have to change the GraphHopper class
Also possible, but might become to complex if there will be a lot of new factories? Not sure.
Yes you are right. But then the mapping from weighting to algoFactory is not correct? Maybe we should be map the combination of weighting and ch to one factory. Or extend the factory. |
Can you please review my changes here? I've introduced a new decorator interface making the request to factory matching more customizable, interesting for future additions of new algorithms and every factory can 'enhance' or even replace the currently used factory. The costs are that all is now a bit more complex. And although the Weighting.match method is now 'cleaner' (takes just one parameter) it does the check also against the strings and not the objects. Not sure if this is an improvement :). This takes me to another issue. The point where we need 'strings' (fastest/shortest/car/...) and where 'real objects' is very tricky, as e.g. we need real The I made sure that the case where you got an exception now works via As we need no preparation for measurement now I've introduced this setting in the |
This works for some other stuff I'm currently working on but the decorator stuff is then a bit duplicated. But this improvement can be done in another issue once we then really have multiple decorators :) update: I would like to merge if someone else could have a quick look at it :) |
Sorry for the delayed review. I like the decorator approach.
But there was no changed behavior here, right?
Not sure as well ;)
Maybe we could wrap it? Returning
|
Not sure how you meant this. There are two things that I do not like much:
Hmmh, this way we would have yet another method in the GraphHopper class. Maybe we can move the "
okay :) |
Yes, I had an idea about unifying both Weightings, by creating a magic
Would be nice, but would this work? I mean we need to know the weighting of the request before getting the decorator, right? Maybe we should set this as fallback in the Request/HintsMap? |
See the updated branch here, where I moved more CH related stuff into the decorator, also the thread pool stuff which really did not belong to the GraphHopper facade :). There is also Now the decorator serves no longer one purpose only - this might be separated later:
If there are no objections I'll merge this in the next days. |
Ah, forgot to rename the method Also picking the default weighting from the CH decorator even if this is disabled is probably not that ideal (but was identical before): if (request.getWeighting().isEmpty())
request.setWeighting(chFactoryDecorator.getDefaultWeighting()); |
Ok, renamed and moved further minor stuff into the CH related decorator |
@karussell Nice! Now the Decorator becomes pretty crowded and reliefs GraphHopper.java.
Thanks for choosing In general I like it. Probably we should merge this ASAP. What do you think? |
Good that you like it :) !
Yes, but the decorator can be splitted later and is really focussed on the CH part. Making it later easy to add others as well.
Yes, will do today (or early tomorrow)! |
Thanks again - merged! |
This PR allows to use weightings that are not prepared with CH to be used instead of throwing an Exception.
A possible use-case could be a routing that considers live-traffic, but in general most routes are calculated without considering live-traffic (this would be CH weighting).
In general, I think falling back to a regular weighting is better than throwing an exception (at least in most cases).
This fixes #491