I’ve been trying to implement a custom routing profile that will choose primary roads over secondary. So far I have the following code:
GraphHopper graphHopper() {
final var graphHopperConfiguration = new GraphHopperConfig();
graphHopperConfiguration.putObject("datareader.file", "my-path-to-file");
graphHopperConfiguration.putObject("graph.location", "my-path-to-graph-cache");
graphHopperConfiguration.putObject("graph.flag_encoders", "car|turn_costs=true");
graphHopperConfiguration.setProfiles(List.of(getProfile()));
return new GraphHopper().init(graphHopperConfiguration).importOrLoad();
}
private Profile getProfile() {
final var customModel = new CustomModel();
customModel.addToPriority(If("road_class == SECONDARY", MULTIPLY, 0.3));
customModel.setDistanceInfluence(150);
return new CustomProfile("car_profile")
.setCustomModel(customModel)
.setVehicle("car")
.setTurnCosts(true);
}
However, when I run my code the following exception is thrown:
Error: Cannot compile expression: Enclosing scope is already set for statement "protected EnumEncodedValue road_class_enc" at File 'source', Line 8, Column 11
After hours of debugging and investigations, I can confirm that the issue lies in CustomModelParser.injectStatements.copyFieldDeclaration().
It seems like the DeepCopier tries to reassign road_class_enc variable that was already declared in the classTemplate string (line 129).
Did anyone encounter this issue? Any help would be very much appreciated
Thank you