Repository navigation
Remove TurnWeighting and handle turn weights within Weighting instead - #1863
Conversation
# Conflicts: # core/src/test/java/com/graphhopper/routing/weighting/RandomizedRoutingTest.java
# Conflicts: # core/src/main/java/com/graphhopper/storage/GraphBuilder.java # core/src/test/java/com/graphhopper/routing/CHQueryWithTurnCostsTest.java # core/src/test/java/com/graphhopper/routing/RandomCHRoutingTest.java # core/src/test/java/com/graphhopper/routing/ch/EdgeBasedNodeContractorTest.java # core/src/test/java/com/graphhopper/routing/ch/EdgeBasedWitnessPathSearcherTest.java # core/src/test/java/com/graphhopper/storage/ShortcutUnpackerTest.java
# Conflicts: # core/src/main/java/com/graphhopper/storage/GraphBuilder.java # core/src/test/java/com/graphhopper/routing/CHQueryWithTurnCostsTest.java # core/src/test/java/com/graphhopper/routing/RandomCHRoutingTest.java # core/src/test/java/com/graphhopper/routing/ch/EdgeBasedNodeContractorTest.java # core/src/test/java/com/graphhopper/routing/ch/EdgeBasedWitnessPathSearcherTest.java # core/src/test/java/com/graphhopper/storage/ShortcutUnpackerTest.java
karussell
left a comment
There was a problem hiding this comment.
Thanks a lot! This LGTM!
The only bigger problem I have is with the static AbstractWeighting.calc* methods - it just looks ugly :) ... should we make them non-static and include them in the Weighting interface? If you prefer to keep this interface lean then should we move the static methods to the interface? IMO it is applicable to all Weighting implementations not only the ones that extend AbstractWeighting (?)
Is it still a WIP? ... looks very polished already :)
|
Thanks a lot for taking a look!
Yes this is not ideal, but having them non-static isn't better IMO. The reason I did not include it in
Its certainly misleading that the static method is in
I don't think there is much missing, should be possible to merge soon. |
Indeed that would break Java 7 compatibility, as seems needing Java 8. |
Ah, this is ugly. Thought this was only regarding the default methods. |
# Conflicts: # core/src/main/java/com/graphhopper/GraphHopper.java # core/src/main/java/com/graphhopper/storage/CHProfile.java
Fixes #1820
This is (more or less) what happens here:
Weightinghas two new methodscalcTurnWeight/Millis(inEdge, viaNode, outEdge)so besides edge-weights it now also calculates turn weightsThe turn weight is calculated by implementations of a new interface
TurnCostProvider, there isNoTurnCostProviderin case the turn costs should be zero.DefaultTurnCostProviderhandles u-turn costs as we did so far and applies turn restrictions (same asTurnWeightingdid before)AbstractWeightinghas aTurnCostProvider, which is passed via the constructor -> It must be known at the time theWeightingis created (in contrast to the oldTurnWeightingwhich wrapped an existingWeightingafter it was created).Since
AbstractWeightingprovides default implementations forcalcTurnWeight/Millis, the sub-classes usually do not need to be concerned with turn weightings. They only need to overridecalc*Edge*Weight/Millis. If you want to change the turn weights in a subclass you can just pass anotherTurnCostProvider to theAbstractWeighting` constructor.Some
Weightings do not inherit fromAbstractWeighting, but rather wrap another weighting (e.g. avoid edges and block area). For this reason its ugly to haveWeighting#calcWeight(edgeState, reverse, prevNext)which is now just a combination of edge and turn weights anyway. For example theAvoidEdgesWeightingadjusts the edge weights, but is unaware of the turn cost implementation of the wrapped weighting, so its not clear how to implementcalcWeightbased on the wrapped weighting. Therefore I removedWeighting#calcWeight. For the (quite common) case where we combine edge- with turn-weights there is a static helper method (currently inAbstractWeighting).There is one more (bigger) complication: Turn costs at virtual nodes and edges. So far we had to use the (special)
TurnCostStoragefromQueryGraphand pass it intoTurnWeighting. But now thatTurnWeightingis gone we have to wrap theWeightingintoQueryGraphWeightingwhen we use it withQueryGraphinstead (at least to calculate turn costs). This is a bit ugly to do, so I addedGraph#wrapWeighting(which is only really implemented byQueryGraphfor now).