Class CustomWeighting
- All Implemented Interfaces:
Weighting
The formula for the edge weights is as follows:
weight = distance/speed + distance_costs + stress_costs
The first term simply corresponds to the time it takes to travel along the edge. The second term adds a fixed per-distance cost that is proportional to the distance but *independent* of the edge properties, i.e. it reads
distance_costs = distance * distance_influence
The third term is also proportional to the distance but compared to the second it describes additional costs that *do* depend on the edge properties. It can represent any kind of costs that depend on the edge (like inconvenience or dangers encountered on 'high-stress' roads for bikes, toll roads (because they cost money), stairs (because they are awkward when going by bike) etc.). This 'stress' term reads
stress_costs = distance * stress_per_meter
and just like the distance term it describes costs measured in seconds. When modelling it, one always has to 'convert' the costs into some time equivalent (e.g. for toll roads one has to think about how much money can be spent to save a certain amount of time). Note that the distance_costs described by the second term in general cannot be properly described by the stress costs, because the distance term allows increasing the per-distance costs per-se (regardless of the type of the road). Also note that both the second and third term are different to the first in that they can increase the edge costs but do *not* modify the travel *time*.
Instead of letting you set the speed directly, `CustomWeighting` allows changing the speed relative to the speed we get from the base flag encoder. The stress costs can be specified by using a factor between 0 and 1 that is called 'priority'.
Therefore the full edge weight formula reads:
weight = distance / (base_speed * speed_factor * priority) + distance * distance_influence
The open parameters that we can adjust are therefore: speed_factor, priority and distance_influence and they are
specified via the `CustomModel
`. The speed can also be restricted to a maximum value, in which case the value
calculated via the speed_factor is simply overwritten. Edges that are not accessible according to the access flags of
the base vehicle always get assigned an infinite weight and this cannot be changed (yet) using this weighting.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
static interface
static class
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCustomWeighting
(TurnCostProvider turnCostProvider, CustomWeighting.Parameters parameters) -
Method Summary
Modifier and TypeMethodDescriptionlong
calcEdgeMillis
(EdgeIteratorState edgeState, boolean reverse) This method calculates the time taken (in milliseconds) to travel along the specified edgeState.double
calcEdgeWeight
(EdgeIteratorState edgeState, boolean reverse) This method calculates the weight of a givenEdgeIteratorState
.double
Used only for the heuristic estimation in A*long
calcTurnMillis
(int inEdge, int viaNode, int outEdge) double
calcTurnWeight
(int inEdge, int viaNode, int outEdge) getName()
boolean
This method can be used to check whether or not this weighting returns turn costs (or if they are all zero).
-
Field Details
-
NAME
- See Also:
-
-
Constructor Details
-
CustomWeighting
-
-
Method Details
-
calcMinWeightPerDistance
public double calcMinWeightPerDistance()Description copied from interface:Weighting
Used only for the heuristic estimation in A*- Specified by:
calcMinWeightPerDistance
in interfaceWeighting
- Returns:
- minimal weight per meter. E.g. if you calculate the fastest way the return value is '1/max_velocity' or a shortest weighting would return 1.
-
calcEdgeWeight
Description copied from interface:Weighting
This method calculates the weight of a givenEdgeIteratorState
. E.g. a high value indicates that the edge should be avoided during shortest path search. Make sure that this method is very fast and optimized as this is called potentially millions of times for one route or a lot more for nearly any preprocessing phase.- Specified by:
calcEdgeWeight
in interfaceWeighting
- Parameters:
edgeState
- the edge for which the weight should be calculatedreverse
- if the specified edge is specified in reverse direction e.g. from the reverse case of a bidirectional search.- Returns:
- the calculated weight with the specified velocity has to be in the range of 0 and +Infinity. Make sure your method does not return NaN which can e.g. occur for 0/0.
-
calcEdgeMillis
Description copied from interface:Weighting
This method calculates the time taken (in milliseconds) to travel along the specified edgeState. It is typically used for post-processing and on only a few thousand edges.- Specified by:
calcEdgeMillis
in interfaceWeighting
-
calcTurnWeight
public double calcTurnWeight(int inEdge, int viaNode, int outEdge) - Specified by:
calcTurnWeight
in interfaceWeighting
-
calcTurnMillis
public long calcTurnMillis(int inEdge, int viaNode, int outEdge) - Specified by:
calcTurnMillis
in interfaceWeighting
-
hasTurnCosts
public boolean hasTurnCosts()Description copied from interface:Weighting
This method can be used to check whether or not this weighting returns turn costs (or if they are all zero). This is sometimes needed to do safety checks as not all graph algorithms can be run edge-based and might yield wrong results when turn costs are applied while running node-based.- Specified by:
hasTurnCosts
in interfaceWeighting
-
getName
-