-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 Strings to add CH profiles to GraphBuilder #1861
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The savings seems to be minimal especially as you then often have to call:
weighting = chGraph.getCHProfile().getWeighting();
Or is this already work in-sync with #493?
.create(); | ||
chProfile = graph.getCHGraph().getCHProfile(); | ||
weighting = chProfile.getWeighting(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. here.
Kind of: When we use
Hmm, I think this .setCHProfileStrings("car|fastest|edge")
Weighting w = chGraph.getCHProfile().getWeighting(); is a lot better and shorter than this: Weighting w = new FastestWeighting(encoder, new DefaultTurnCostProvider(encoder, graph.getTurnCostStorage());
graph.addCHGraph(CHProfile.edge(w));
graph.create(1000); but you do not like it because of less type-safety? |
I just have no strong opinion here. Feel free to merge it :) The problem of type safety or refactoring safety is not too big as you already indicated that we mainly use this in tests :) |
Yes this is meant to be used mainly in tests. At some point we should extract the 'create a weighting and corresponding CH profiles etc.' part from |
This is a little spin-off from https://github.com/graphhopper/graphhopper/tree/remove_turn_weighting. Whats the issue here? In #1820 I want to move the turn weight calculation into
AbstractWeighting
instead of (as we do so far) wrappingWeighting
s intoTurnWeighting
. This requires passing the turn weight stuff into the weighting constructors (which is also a good thing: the turn cost configuration must be defined at the time the weighting is created as is the case when including the turn weighting in configurable weightings). However, this means to create aWeighting
we need theTurnCostStorage
already, which on the other hand is not available as long as there is no graph. The ugly part here is that to create a graph we already need the weightings to addCHGraphs
, which we can see looking at the current usage ofGraphBuilder
:With the turn cost stuff this becomes:
So I thought its useful to use a string representation to add the CH profiles and create the CH profiles in
GraphBuilder#build()
when the turn cost storage is available:Obviously this is limited to some hard-coded weightings in
GraphBuilder
, then again these are sufficient for the testing purposes (whereGraphBuilder
is mainly used) and of course one can always use the more verbose and flexible way above.I don't know its a bit of a workaround because really I think there is no reason we cannot add CHGraphs after
GraphHopperStorage
has been created, but this seems like a bigger undertaking and not sure if its worth atm, especially since I think the string method above is nice and readable (just not type-safe).Any thoughts?