Issue setting up with racingbike profile

I’m trying to set up a Graphhopper instance as provided in the examples.
But I would like to use the “racingbike” profile:

  public static void routing(GraphHopper hopper) {

        GraphHopper hopper = createGraphHopperInstance(relDir + "core/files/berlin.osm.pbf");

 

    }
     static GraphHopper createGraphHopperInstance(String ghLoc) {

        GraphHopper hopper = new GraphHopper();

        hopper.setOSMFile(ghLoc);

        // specify where to store graphhopper files

        hopper.setGraphHopperLocation("target/routing-graph-cache");

        // add all encoded values that are used in the custom model, these are also available as path details or for client-side custom models

        hopper.setEncodedValuesString("racingbike_priority, racingbike_access, bike_network, roundabout, racingbike_average_speed, bike_road_access, average_slope, mtb_rating, hike_rating, sac_scale, country, road_class, ferry_speed");

        // see docs/core/profiles.md to learn more about profiles

        hopper.setProfiles(new Profile("racingbike").setCustomModel(GHUtility.loadCustomModelFromJar("racingbike.json")));

        // this enables speed mode for the profile we called car

        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("racingbike"));

        // now this can take minutes if it imports or a few seconds for loading of course this is dependent on the area you import

        hopper.importOrLoad();

        return hopper;

    }

I’m getting errors when using the supplied “racingbike.json”:

Exception in thread “main” java.lang.IllegalArgumentException: Could not create weighting for profile: ‘racingbike’.

Profile: name=racingbike|turn_costs={null}|weighting=custom|hints={custom_model=distanceInfluence=null|headingPenalty=null|speedStatements=[{"if": "road_environment == FERRY", "limit_to": "ferry_speed"}, {"else": "", "limit_to": "racingbike_average_speed"}, {"if": "!racingbike_access && backward_racingbike_access", "limit_to": "5"}]|priorityStatements=[{"if": "true", "multiply_by": "racingbike_priority"}, {"if": "bike_network == INTERNATIONAL || bike_network == NATIONAL", "multiply_by": "1.4"}, {"else_if": "bike_network == REGIONAL || bike_network == LOCAL", "multiply_by": "1.2"}, {"if": "road_environment == FERRY", "multiply_by": "0.5"}, {"if": "mtb_rating > 2", "multiply_by": "0"}, {"else_if": "mtb_rating == 2", "multiply_by": "0.5"}, {"if": "hike_rating > 1", "multiply_by": "0"}, {"if": "bike_road_access == NO", "multiply_by": "0"}, {"if": "!racingbike_access && (!backward_racingbike_access || roundabout)", "multiply_by": "0"}, {"else_if": "!racingbike_access && backward_racingbike_access", "multiply_by": "0.2"}]|turnPenaltyStatements=[]|areas=[]}

Error: Cannot compile expression: 'racingbike_priority' not available

If I comment out the first line of racingbike.json

{ "if": "true",  "multiply_by": "racingbike_priority" },

which causes this error I get:

Exception in thread “main” java.lang.IllegalArgumentException: Could not create weighting for profile: ‘racingbike’.

Profile: name=racingbike|turn_costs={null}|weighting=custom|hints={custom_model=distanceInfluence=null|headingPenalty=null|speedStatements=[{“if”: “road_environment == FERRY”, “limit_to”: “ferry_speed”}, {“else”: “”, “limit_to”: “racingbike_average_speed”}, {“if”: “!racingbike_access && backward_racingbike_access”, “limit_to”: “5”}]|priorityStatements=[{“if”: “bike_network == INTERNATIONAL || bike_network == NATIONAL”, “multiply_by”: “1.4”}, {“else_if”: “bike_network == REGIONAL || bike_network == LOCAL”, “multiply_by”: “1.2”}, {“if”: “road_environment == FERRY”, “multiply_by”: “0.5”}, {“if”: “mtb_rating > 2”, “multiply_by”: “0”}, {“else_if”: “mtb_rating == 2”, “multiply_by”: “0.5”}, {“if”: “hike_rating > 1”, “multiply_by”: “0”}, {“if”: “bike_road_access == NO”, “multiply_by”: “0”}, {“if”: “!racingbike_access && (!backward_racingbike_access || roundabout)”, “multiply_by”: “0”}, {“else_if”: “!racingbike_access && backward_racingbike_access”, “multiply_by”: “0.2”}]|turnPenaltyStatements=[]|areas=[]}

Error: Cannot compile expression: priority entry invalid condition “bike_network == INTERNATIONAL || bike_network == NATIONAL”: ‘bike_network’ not available

at com.graphhopper.GraphHopper.checkProfilesConsistency(GraphHopper.java:1208)

Am I doing something wrong or is racingbike,json outdated?

Many thanks for your support

Robert

Did you add the racingbike encoded values documented in the racingbike.json?

Currently:

 graph.encoded_values: racingbike_priority, racingbike_access, bike_network, roundabout, racingbike_average_speed, bike_road_access, average_slope, mtb_rating, hike_rating, sac_scale, country, road_class, ferry_speed

>Did you add the racingbike encoded values documented in the racingbike.json?

Yes, as you can see above :

// add all encoded values that are used in the custom model, these are also available as path details or for client-side custom models

    `hopper.setEncodedValuesString("racingbike_priority, racingbike_access, bike_network, roundabout, racingbike_average_speed, bike_road_access, average_slope, mtb_rating, hike_rating, sac_scale, country, road_class, ferry_speed");`

If the config of the graph does not exactly match the configuration then it will also throw this error (confusing, yes, we need to fix it :slight_smile: ). And to get the configuration match that one of the graph the best is probably to use the GraphHopper.init method as discussed here.

Ok, I changed my setup this way :

config.yml

datareader.file: core/files/berlin.osm.pbf
graph.location: graphs/berlin-regular/graph
graph.elevation.provider: srtm   # enables elevation
graph.encoded_values: road_environment, racingbike_priority, racingbike_access, bike_network, roundabout, racingbike_average_speed, bike_road_access, average_slope, mtb_rating, hike_rating, sac_scale, country, road_class, ferry_speed
profiles:
    - name: racingbike
      custom_model_files: [racingbike.json, bike_elevation.json]

import.osm.ignored_highways: motorway,trunk # use if you only have non-motorized vehicle profiles
index.max_region_search: 100
index:
  pups: 200

used by

    static GraphHopper createGraphHopperInstanceRacingBike() throws Exception {
        GraphHopper hopper = new GraphHopper();

        File file = null;
        URL resource = MapMatchingTest.class.getResource("/config.yml");
        if (resource == null) {
            throw new IllegalArgumentException("file not found!");
        } else {
            file = new File(resource.toURI());
        }

        YAMLMapper yamlMapper = new YAMLMapper();
        GraphHopperConfig config = yamlMapper.readValue(file, GraphHopperConfig.class);
        hopper.init(config);

        hopper.importOrLoad();
        return hopper;
    }

Now I get the following exception:

java.lang.IllegalArgumentException: Unknown encoded value: sac_scale
at com.graphhopper.GraphHopper.prepareImport(GraphHopper.java:899)
at com.graphhopper.GraphHopper.process(GraphHopper.java:817)
at com.graphhopper.GraphHopper.importOrLoad(GraphHopper.java:792)

Yes, there is no sac_scale encoded value. Probably you want hike_rating?

Thank you, I took graph.encoded_values from racingbike.json and did not see sac_scale in it.

Working now :+1: