EDIT
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.
GHRequest request = new GHRequest().setProfile("custom_veh");
request.setCustomModel(Graphhopper.getModel());
Is this correct implementation or am I confusing something?
My Graphhopper setup;
graphHopper = new GraphHopper()
.setGraphHopperLocation(locationGrapphopperFiles)
.setOSMFile(locationRoutingFile)
.setElevation(true)
.setAllowWrites(true)
.setElevationProvider(new CGIARProvider(System.getProperty("user.home")+File.separator+"srtm"+File.separator))
.setProfiles(Arrays.asList(
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"))
);
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")
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.