GH 3.2 - Custom Model - model.addToPriority causing empty routes (resolved)


The below has been fixed by not using CH.
The ‘custom_model’ parameter is currently not supported for speed mode, you need to disable speed mode with ch.disable=true.

Working on moving to GH 3.2 and receiving empty routes when applying my custom profile parameters.

public static CustomModel getModel(){
        CustomModel model = new CustomModel();
        model.addToPriority(If("road_class == FOOTWAY", MULTIPLY, 0.0));
        model.addToPriority(If("road_class == PEDESTRIAN", MULTIPLY, 0.0));
        model.addToPriority(If("road_class == STEPS", MULTIPLY, 0.0));
        model.addToPriority(If("road_class == SERVICE", MULTIPLY, 1.0));
        model.addToPriority(If("road_class == PATH", MULTIPLY, 0.0));
        model.addToPriority(If("road_class == TRACK", MULTIPLY, 0.0));
        model.addToPriority(If("road_access == PRIVATE", MULTIPLY, 1.0));
        return model;

Apply the model before the response is made;

GHRequest request = new GHRequest().setProfile("custom_veh");

Is this correct implementation or am I confusing something?

My Graphhopper setup;

graphHopper = new GraphHopper()

                .setElevationProvider(new CGIARProvider(System.getProperty("user.home")+File.separator+"srtm"+File.separator))

                    new Profile("foot").setVehicle("foot").setWeighting("fastest"),
                    new Profile("car").setVehicle("car").setWeighting("fastest"),
                    new Profile("rural").setVehicle("motorcycle").setWeighting("fastest").setTurnCosts(true).putHint("u_turn_costs", 3),
                    new CustomProfile("custom_veh").setCustomModel(new CustomModel()).setVehicle("foot"))


Will update if I resolve.

The custom_model parameter cannot be used for a CH query, yes. But you can still define your custom model in the config.yml (i.e. on the server side) and use this for CH preparation.

I.e. you play around with your custom model until it fits your needs and then you can make it very fast via putting it into a CH preparation. (If you want to make the custom model only faster and still keep most of its flexibility you can use an LM preparation instead.)


Thanks Karussell, I will still require to use CH in some instances but using LM for basic routing doesn’t have a huge processing time increase and using the new custom model setup is nice and easy.

I am having issues with the CH setup though, are there any examples?
Historically I have used the following as I am not using a config.yml;

CustomModel model = new CustomModel();
HashMap map = new HashMap();
map.put("footway", 0);
map.put("pedestrian", 0);
map.put("steps", 0);
map.put("service", 1.0);
map.put("path", 0);
map.put("track", 0);
model.getPriority().put("road_class", map);

and then in my graphhopper setup;
new CustomProfile("custom_veh").setCustomModel(model).setVehicle("foot").setWeighting("custom")

For Java it is even easier as we have many tests :slight_smile:
and (see e.g. profile car_no_unclassified)

E.g. if you want to add a CH preparation for your car profile and the custom_veh profile in your code above you just append:

.setCHProfiles(Arrays.asList(new CHProfile("car"), new CHProfile("custom_veh")));
1 Like

Awesome, thanks karussell.

So CH custom profiles are customized at graph creation and LM custom profiles are customized at request creation allowing greater flexibility.

This is really helpful as I can have really fast specific profiles setup but also have a couple of customizable profiles within my project that users can adjust without rebuilding the graph.

Also, just to tie it all off;
Forcing curbside and uturn costs using CH;
Creating the Graph using van profile
new CustomProfile("van").setCustomModel(new CustomModel(getModel())).setVehicle("car").setTurnCosts(true).putHint("u_turn_costs", 3)

Then on each request;
List<String> CURBSIDES = new ArrayList<>(Arrays.asList("left", "left"));
new GHRequest().setProfile("van").setCurbsides(CURBSIDES).putHint(Parameters.Routing.FORCE_CURBSIDE, false);

The custom profiles are used directly “as they are” for CH and LM preparation. But the difference then is for the query: the LM algorithm allows further customization and CH does not allow further customization per request.

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