I am testing how create a custom Encoded Value similar to CurvatureEnc in CurvatureWeighting and call it, but I get the following error:
Error: Cannot find EncodedValue car$leighton in collection: null
Here are code snippets:
public class FastestWeighting extends AbstractWeighting {
/**
* Converting to seconds is not necessary but makes adding other penalties easier (e.g. turn
* costs or traffic light costs etc)
*/
protected final static double SPEED_CONV = 3.6;
private final double headingPenalty;
private final long headingPenaltyMillis;
private final double maxSpeed;
**private final DecimalEncodedValue leightonEnc;** //Leighton test
private final EnumEncodedValue<RoadAccess> roadAccessEnc;
// this factor puts a penalty on roads with a "destination"-only or private access, see #733 and #1936
private final double destinationPenalty, privatePenalty;
public FastestWeighting(FlagEncoder encoder) {
this(encoder, new PMap(0));
}
public FastestWeighting(FlagEncoder encoder, TurnCostProvider turnCostProvider) {
this(encoder, new PMap(0), turnCostProvider);
}
public FastestWeighting(FlagEncoder encoder, PMap map) {
this(encoder, map, NO_TURN_COST_PROVIDER);
}
public FastestWeighting(FlagEncoder encoder, PMap map, TurnCostProvider turnCostProvider) {
super(encoder, turnCostProvider);
**leightonEnc = flagEncoder.getDecimalEncodedValue(EncodingManager.getKey(flagEncoder, "leighton"));**
headingPenalty = map.getDouble(Routing.HEADING_PENALTY, Routing.DEFAULT_HEADING_PENALTY);
headingPenaltyMillis = Math.round(headingPenalty * 1000);
maxSpeed = encoder.getMaxSpeed() / SPEED_CONV;
if (!encoder.hasEncodedValue(RoadAccess.KEY))
throw new IllegalArgumentException("road_access is not available but expected for FastestWeighting");
// ensure that we do not need to change getMinWeight, i.e. road_access_factor >= 1
double defaultDestinationFactor = encoder.getTransportationMode().isMotorVehicle()? 10 : 1;
destinationPenalty = checkBounds("road_access_destination_factor", map.getDouble("road_access_destination_factor", defaultDestinationFactor), 1, 10);
double defaultPrivateFactor = encoder.getTransportationMode().isMotorVehicle()? 10 : 1.2;
privatePenalty = checkBounds("road_access_private_factor", map.getDouble("road_access_private_factor", defaultPrivateFactor), 1, 10);
roadAccessEnc = destinationPenalty > 1 || privatePenalty > 1 ? encoder.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class) : null;
}
@Override
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
**double leighton_test = leightonEnc.getDecimal(false, edgeState.getFlags()); //Leighton test**
** System.out.println("leighton_test:" + "" + leighton_test);**
double speed = reverse ? edgeState.getReverse(avSpeedEnc) : edgeState.get(avSpeedEnc);
if (speed == 0)
return Double.POSITIVE_INFINITY;
double time = edgeState.getDistance() / speed * SPEED_CONV;
if (roadAccessEnc != null) {
RoadAccess access = edgeState.get(roadAccessEnc);
if (access == RoadAccess.DESTINATION)
time *= destinationPenalty;
else if (access == RoadAccess.PRIVATE)
time *= privatePenalty;
}
// add direction penalties at start/stop/via points
boolean unfavoredEdge = edgeState.get(EdgeIteratorState.UNFAVORED_EDGE);
if (unfavoredEdge)
time += headingPenalty;
return time;
}
This is the CarFlagEncoder:
public class T4ACarFlagEncoder extends AbstractFlagEncoder {
protected final Map<String, Integer> trackTypeSpeedMap = new HashMap<>();
protected final Set<String> badSurfaceSpeedMap = new HashSet<>();
private boolean speedTwoDirections;
// This value determines the maximal possible on roads with bad surfaces
protected int badSurfaceSpeed;
**private DecimalEncodedValue leightonEncoder;**
.
.
.
@Override //Kyk na dit Leighton test
public void createEncodedValues(List<EncodedValue> registerNewEncodedValue, String prefix, int index) {
// first two bits are reserved for route handling in superclass
super.createEncodedValues(registerNewEncodedValue, prefix, index);
**registerNewEncodedValue.add(leightonEncoder = new UnsignedDecimalEncodedValue(getKey(pref**ix, "leighton"), 4, 0.1, false)); //Leighton test
}