Error: Weighting 'fast_easy' not supported

Hi all,

I am trying to create a modified fastest weighting called fast_easy weighting. I only difference is that I am adding my routing_priority encoded value for each edge to fastest weighting:

public class FastEasyWeighting 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;
protected double routingPriority;
private final EnumEncodedValue 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 FastEasyWeighting(FlagEncoder encoder) {
    this(encoder, new PMap(0));
}

public FastEasyWeighting(FlagEncoder encoder, TurnCostProvider turnCostProvider) {
    this(encoder, new PMap(0), turnCostProvider);
}

public FastEasyWeighting(FlagEncoder encoder, PMap map) {
    this(encoder, map, NO_TURN_COST_PROVIDER);
}

public FastEasyWeighting(FlagEncoder encoder, PMap map, TurnCostProvider turnCostProvider) {
    super(encoder, turnCostProvider);
    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 getMinWeight(double distance) {
    return distance / (maxSpeed * routingPriority);  
}

@Override
public double calcEdgeWeight(EdgeIteratorState edgeState, boolean reverse) {
    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;
}

@Override
public long calcEdgeMillis(EdgeIteratorState edgeState, boolean reverse) {
    // TODO move this to AbstractWeighting? see #485
    long time = 0;
    boolean unfavoredEdge = edgeState.get(EdgeIteratorState.UNFAVORED_EDGE);
    if (unfavoredEdge)
        time += headingPenaltyMillis;

    return time + super.calcEdgeMillis(edgeState, reverse);
}

static double checkBounds(String key, double val, double from, double to) {
    if (val < from || val > to)
        throw new IllegalArgumentException(key + " has invalid range should be within [" + from + ", " + to + "]");

    return val;
}

@Override
public String getName() {
    return "fast_easy";
}

}

I get this error when executing GraphHopper:

java.lang.IllegalArgumentException: Could not create weighting for profile: ‘car’.
Profile: name=car|vehicle=car|weighting=fast_easy|turnCosts=false|hints={distance_factor=0}
Error: Weighting ‘fast_easy’ not supported
at com.graphhopper.GraphHopper.checkProfilesConsistency(GraphHopper.java:845)
at com.graphhopper.GraphHopper.load(GraphHopper.java:787)
at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:633)
at com.graphhopper.http.GraphHopperManaged.start(GraphHopperManaged.java:103)
at io.dropwizard.lifecycle.JettyManaged.doStart(JettyManaged.java:27)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
at org.eclipse.jetty.server.Server.start(Server.java:423)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:97)
at org.eclipse.jetty.server.Server.doStart(Server.java:387)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:53)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:60)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:98)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:94)
at com.graphhopper.http.GraphHopperApplication.main(GraphHopperApplication.java:35)
java.lang.IllegalArgumentException: Could not create weighting for profile: ‘car’.
Profile: name=car|vehicle=car|weighting=fast_easy|turnCosts=false|hints={distance_factor=0}
Error: Weighting ‘fast_easy’ not supported
at com.graphhopper.GraphHopper.checkProfilesConsistency(GraphHopper.java:845)
at com.graphhopper.GraphHopper.load(GraphHopper.java:787)
at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:633)
at com.graphhopper.http.GraphHopperManaged.start(GraphHopperManaged.java:103)
at io.dropwizard.lifecycle.JettyManaged.doStart(JettyManaged.java:27)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:169)
at org.eclipse.jetty.server.Server.start(Server.java:423)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:117)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:97)
at org.eclipse.jetty.server.Server.doStart(Server.java:387)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:73)
at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:53)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:60)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:98)
at io.dropwizard.cli.Cli.run(Cli.java:78)
at io.dropwizard.Application.run(Application.java:94)
at com.graphhopper.http.GraphHopperApplication.main(GraphHopperApplication.java:35)

Does anyone know why I am getting this error?

Problem solved. I needed to add my custom weighting to DefaultWeightingFactory.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.