You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a few problems with having sth. like calcTurnWeight in AbstractWeighting and I do not yet know what are the most important things to consider for #1776.
TurnWeighting uses information that is only available after constructing the QueryGraph (c.f. Take routing algorithm factory out of PrepareContractionHierarchies #1819 (comment)). I think the quick fix here would be to keep using some kind of QueryWeighting that does this or to even include the logic from QueryGraphTurnCostStorage in AbstractWeighting.
I am not sure how AbstractWeighting should be able to obtain the turn cost information. For edge-weight calculation we always pass the required information to the weighting (using the edgeState parameter in Weighting), but for the turn weight it would be ugly to have something like calcTurnWeight(TurnCostProvider, inEdge, viaNode, outEdge) ? I think I would rather keep something like TurnCostProvider within AbstractWeighting (passed in the constructor), but then we can no longer create a Weighting without having the TurnCostStorage from the Graph (would this be ok?). With TurnCostProvider I mean just some interface with something like calcTurnWeight so we do not reveal stuff like TurnCostStorage to the Weighting.
What makes 1) and 2) even more serious is that we keep the Weighting objects within the CHProfile objects in the CHDecorator, so they need to be immutable and we cannot just use some kind of setTurnCostProvider on them. Maybe it would be useful to replace these Weighting objects with the information that is necessary to create them ("fastest|car" etc.) and treat the Weighting objects as throw-away temporary objects per request instead. This way it would probably become easier to set the turn cost stuff on the weightings. I think this is my preferred solution in the mid/long run: We create the weighting after QueryGraph has been built (and we have all the information about what weighting shall be used) and create the weighting only then. One thing I do not know is what this all the information will look like in the future (especially with Introduce configurable Weighting / CustomWeighting #1776).
Sorry my thoughts are a bit work in progress. I started to think in different directions and whatever I tried there did not seem to be an obvious way to remove TurnWeighting. Maybe you can provide some background what is important for #1776 ?
but then we can no longer create a Weighting without having the TurnCostStorage from the Graph (would this be ok?)
in createWeighting we know the GraphHopperStorage and use it e.g. for BlockAreaWeighting. So this dependency should probably be ok.
so they need to be immutable and we cannot just use some kind of setTurnCostProvider
But changing this is not required if I understand it properly as one CHProfile has only one "TurnCostProvider".
Maybe it would be useful to replace these Weighting objects with the information that is necessary to create them ("fastest|car" etc.)
Sounds good.
We create the weighting after QueryGraph has been built (and we have all the information about what weighting shall be used) and create the weighting only then
Hmmh, having QueryGraph before the Weighting will make problems with the BlockAreaWeighting use case ... see my update notice in the first comment of #729. In short: the LocationIndex is required for BlockAreaWeighting.
Maybe you can provide some background what is important for #1776 ?
Maybe we should start the refactoring from the other end and my conclusion to get rid of TurnWeighting was too fast. I basically tried to replace any EdgeFilter with a Weighting (like #729) and stumbled over a few TurnWeighting places where I didn't now how to proceed. Probably I will have to do it again to refresh my memory and to identify the exact issues.
Hmmh, having QueryGraph before the Weighting will make problems with the BlockAreaWeighting use case ...
To me this sounds like we should first use a Weighting+BaseGraph for LocationIndex lookup and such and then use a thin wrapper QueryWeighting+QueryGraph for the routing. Maybe there should be a concept of a 'weighted' graph (weighting+graph): Instead of doing weighting.calcWeight(edge), we would do edge.getWeight(), which internally passes the edgeState to the weighting (weighting.calcWeight(internalEdge)), just like here:
Another problematic dependency is that CHProfile is required to create GraphHopperStorage. So we cannot create a weighting or CHProfile referencing the turn cost storage (which is created by GraphHopperStorage). However, this dependency seems rather unnecessary to me. Do you remember why it exists ? I do not see a bigger problem in creating a GraphHopperStorage first and then adding CH graphs to it afterwards ? And would this not even be nice to have ? This way one could for example first create a 'normal' graph, read OSM etc. and later add CH preparations. Of course its important to make sure the properties file is always up to date and adding CH graphs should only be possible when we are using the same version as we used when we created the base graph etc. Once we are able to add CH graphs after creating GraphHopperStorage we should be able to create the weightings like this:
GraphHopperStorageghStorage = newGraphBuilder(encodingManager).withTurnCosts(true).create();
TurnCostStorageturnCostStorage = ghStorage.getTurnCostStorage();
TurnCostProviderturnCostProvider = newDefaultTurnCostProvider(turnCostStorage, uTurnCosts);
// the weighting includes the turn costs from the beginning, no need to wrap it into TurnWeighting laterWeightingweighting = newFastestWeighting(encoder, turnCostProvider);
CHProfilechProfile = CHProfile.edgeBased(weighting);
ghStorage.addCHGraph(chProfile);
// for query graph we will still need a small wrapper around the weighting so we can handle virtual nodes/edgesQueryGraphqueryGraph = newQueryGraph(ghStorage);
queryGraph.lookup(qrs);
Weightingweighting = newQueryWeighting(weighting, queryGraph.getTurnCostStorage);
Pathpath = newDijkstra(queryGraph, weighting, TraversalMode.EDGE_BASED).calcPath(4, 49);
Another way to include turn costs within the weightings we use for CH would be something like the following:
// the CH profile does no longer contain a weighting object, but rather a description of the weighting it shall useCHProfilechProfile = newCHProfile.edgeBased("fastest", "car", 40);
GraphHopperStorageghStorage = newGraphBuilder(em).setCHProfiles(chProfile)
.withTurnCosts(true).create();
// we need some (customizable) way of interpreting the CH profile and turn it into a weighting. the default implementation is only aware of some common vehicles and weightings, but for example has access to turn cost storage of a given graphCHWeightingFactoryweightingFactory = newDefaultCHWeightingFactory(ghStorage);
Weightingweighting = weightingFactory.createWeighting(chProfile);
// use the weighting for CH preparation and requests
Likely due to historic reasons. CH was strongly coupled to everything.
And would this not even be nice to have ?
I still fail to see a real use case for this. But yes, I think this was even requested from users.
Once we are able to add CH graphs after creating GraphHopperStorage we should be able to create the weightings like this
Looks good :)
Another way to include turn costs within the weightings we use for CH would be something like the following:
The disadvantage I see here is that we have two things (weightingFactory.createWeighting and GraphHopper.createWeighting) that convert parameters into a Weighting. But maybe this can be avoided.
The disadvantage I see here is that we have two things (weightingFactory.createWeighting and GraphHopper.createWeighting) that convert parameters into a Weighting. But maybe this can be avoided.
Yeah maybe this should just be (more or less) the same thing.
Do you have an idea yet how configurable weightings should be usable with CH (in the long run) ? Maybe we will be able to put the same weighting definition we can use per request with #1776 in config.yml to define the weighting used for CH preparation ?
I still fail to see a real use case for this. But yes, I think this was even requested from users.
Hmm maybe when you do a planet import + preparation for car and then you realize you need bike as well this will save you from doing the import + preparation for car again (?).
I did this (or the first part of this) the easy way for now: CHGraphs are now added to GraphHopperStorage after the constructor is called, but before create(), so we have access to the TurnCostStorage when calling addCHGraph(), but cannot add CHGraphs after the GH storage has been initialized / create or loadExisting was called: 402028f
Any idea what to do with FlagEncoder#supports(TurnWeighting.class) ? Maybe just add FlagEncoder#supportsTurnCosts() ? Whats the idea behind FlagEncoder#supports(Class<?> feature) ? Hmm the changelog for 0.4 says: encoder.supportTurnCost is replaced by encoder.supports(TurnWeighting.class) ...
I did this (or the first part of this) the easy way for now:
👍
Maybe we will be able to put the same weighting definition we can use per request with #1776 in config.yml to define the weighting used for CH preparation ?
Yes, the idea is exactly this: instead of providing the weighting config in the request body we put this section in a file and refer to it in the config.yml or embed it into config.yml. At least I implemented this in one of the flexible branches this way and it worked well, except that I had to add a yaml parser to the core (because when calling gh.load it needs to know the CH weighting), but we can probably avoid this with some interfacing.
Whats the idea behind FlagEncoder#supports
We used it in the past to see if certain FlagEncoders have support for e.g. turn cost or PriorityWeighting. We need to get rid of it, likely encodingManager, but as turn cost can be vehicle dependent it needs to be something like encodingManager.supportsTurnCostFor("car")?
Activity
easbar commentedon Dec 11, 2019
There are a few problems with having sth. like
calcTurnWeightinAbstractWeightingand I do not yet know what are the most important things to consider for #1776.TurnWeighting uses information that is only available after constructing the QueryGraph (c.f. Take routing algorithm factory out of
PrepareContractionHierarchies#1819 (comment)). I think the quick fix here would be to keep using some kind ofQueryWeightingthat does this or to even include the logic fromQueryGraphTurnCostStorageinAbstractWeighting.I am not sure how
AbstractWeightingshould be able to obtain the turn cost information. For edge-weight calculation we always pass the required information to the weighting (using theedgeStateparameter inWeighting), but for the turn weight it would be ugly to have something likecalcTurnWeight(TurnCostProvider, inEdge, viaNode, outEdge)? I think I would rather keep something likeTurnCostProviderwithinAbstractWeighting(passed in the constructor), but then we can no longer create aWeightingwithout having theTurnCostStoragefrom theGraph(would this be ok?). WithTurnCostProviderI mean just some interface with something likecalcTurnWeightso we do not reveal stuff likeTurnCostStorageto theWeighting.What makes 1) and 2) even more serious is that we keep the
Weightingobjects within theCHProfileobjects in theCHDecorator, so they need to be immutable and we cannot just use some kind ofsetTurnCostProvideron them. Maybe it would be useful to replace theseWeightingobjects with the information that is necessary to create them ("fastest|car"etc.) and treat theWeightingobjects as throw-away temporary objects per request instead. This way it would probably become easier to set the turn cost stuff on the weightings. I think this is my preferred solution in the mid/long run: We create the weighting afterQueryGraphhas been built (and we have all the information about what weighting shall be used) and create the weighting only then. One thing I do not know is what thisall the informationwill look like in the future (especially with Introduce configurable Weighting / CustomWeighting #1776).Sorry my thoughts are a bit work in progress. I started to think in different directions and whatever I tried there did not seem to be an obvious way to remove
TurnWeighting. Maybe you can provide some background what is important for #1776 ?karussell commentedon Dec 11, 2019
in createWeighting we know the GraphHopperStorage and use it e.g. for BlockAreaWeighting. So this dependency should probably be ok.
But changing this is not required if I understand it properly as one CHProfile has only one "TurnCostProvider".
Sounds good.
Hmmh, having QueryGraph before the Weighting will make problems with the BlockAreaWeighting use case ... see my update notice in the first comment of #729. In short: the LocationIndex is required for BlockAreaWeighting.
Maybe we should start the refactoring from the other end and my conclusion to get rid of TurnWeighting was too fast. I basically tried to replace any EdgeFilter with a Weighting (like #729) and stumbled over a few TurnWeighting places where I didn't now how to proceed. Probably I will have to do it again to refresh my memory and to identify the exact issues.
karussell commentedon Dec 11, 2019
Sorry I meant: the Weighting will be required for LocationIndex.findClosest to create the QueryGraph.
easbar commentedon Dec 11, 2019
Yes this is also true the turn cost provider must not change anyway after the CH preparation.
easbar commentedon Dec 11, 2019
To me this sounds like we should first use a Weighting+BaseGraph for LocationIndex lookup and such and then use a thin wrapper QueryWeighting+QueryGraph for the routing. Maybe there should be a concept of a 'weighted' graph (weighting+graph): Instead of doing
weighting.calcWeight(edge), we would doedge.getWeight(), which internally passes the edgeState to the weighting (weighting.calcWeight(internalEdge)), just like here:graphhopper/core/src/main/java/com/graphhopper/routing/ch/PrepareCHEdgeIterator.java
Lines 70 to 76 in 78793cf
easbar commentedon Dec 11, 2019
Another problematic dependency is that
CHProfileis required to createGraphHopperStorage. So we cannot create a weighting or CHProfile referencing the turn cost storage (which is created byGraphHopperStorage). However, this dependency seems rather unnecessary to me. Do you remember why it exists ? I do not see a bigger problem in creating aGraphHopperStoragefirst and then adding CH graphs to it afterwards ? And would this not even be nice to have ? This way one could for example first create a 'normal' graph, read OSM etc. and later add CH preparations. Of course its important to make sure the properties file is always up to date and adding CH graphs should only be possible when we are using the same version as we used when we created the base graph etc. Once we are able to add CH graphs after creating GraphHopperStorage we should be able to create the weightings like this:Another way to include turn costs within the weightings we use for CH would be something like the following:
karussell commentedon Dec 12, 2019
Likely due to historic reasons. CH was strongly coupled to everything.
I still fail to see a real use case for this. But yes, I think this was even requested from users.
Looks good :)
The disadvantage I see here is that we have two things (weightingFactory.createWeighting and GraphHopper.createWeighting) that convert parameters into a Weighting. But maybe this can be avoided.
easbar commentedon Dec 12, 2019
Yeah maybe this should just be (more or less) the same thing.
Do you have an idea yet how configurable weightings should be usable with CH (in the long run) ? Maybe we will be able to put the same weighting definition we can use per request with #1776 in config.yml to define the weighting used for CH preparation ?
Hmm maybe when you do a planet import + preparation for car and then you realize you need bike as well this will save you from doing the import + preparation for car again (?).
easbar commentedon Dec 13, 2019
I did this (or the first part of this) the easy way for now:
CHGraphs are now added toGraphHopperStorageafter the constructor is called, but beforecreate(), so we have access to theTurnCostStoragewhen callingaddCHGraph(), but cannot addCHGraphsafter the GH storage has been initialized /createorloadExistingwas called: 402028feasbar commentedon Dec 13, 2019
Any idea what to do with
FlagEncoder#supports(TurnWeighting.class)? Maybe just addFlagEncoder#supportsTurnCosts()? Whats the idea behindFlagEncoder#supports(Class<?> feature)? Hmm the changelog for 0.4 says:encoder.supportTurnCost is replaced by encoder.supports(TurnWeighting.class)...karussell commentedon Dec 14, 2019
👍
Yes, the idea is exactly this: instead of providing the weighting config in the request body we put this section in a file and refer to it in the
config.ymlor embed it into config.yml. At least I implemented this in one of the flexible branches this way and it worked well, except that I had to add a yaml parser to the core (because when calling gh.load it needs to know the CH weighting), but we can probably avoid this with some interfacing.We used it in the past to see if certain FlagEncoders have support for e.g. turn cost or PriorityWeighting. We need to get rid of it, likely encodingManager, but as turn cost can be vehicle dependent it needs to be something like
encodingManager.supportsTurnCostFor("car")?karussell commentedon Jan 10, 2020
Seems that #1842 autoclosed this due to "fix #1842" :) ... reopening ...