Problem using custom weighting - "weighting null not supported"

I’ve implemented a custom weighting that extends FastestWeighting, but I cannot get it to work. In line with this project, I’ve tried to allow use of this weighting by adding the following code to GraphHopper.java:

else if (“custom”.equalsIgnoreCase(weightingStr)) {
weighting = new CustomWeighting(encoder, hintsMap);
}

In the CustomWeighting class, I have overridden the getName() method:
@Override
public String getName() {
return “custom”;
}

However, if I start the server and change the weighting in the URL to ‘custom’, I get the error ‘weighting null not supported’. The same happens if I set prepare.ch.weightings=custom in the config.properties file.

Please help - my project depends on it.

It looks like the weighting string is not properly forwarded from the URL to the GraphHopper class.

I think you have to overwrite the toString-Method.

public String toString() {
return “custom”;
}

Another approach: Try to call the GH-instance by code and set your string by the encoding-manager.

No, getName is the correct method. toString prints e.g. ‘fastest|car’

Okay.
But in some cases to have to implement this method. I think for custom flag encoder.

@acrossthesound: Does the problem still exist?

1 Like

If you extend from AbstractWeighting you should be on the safe side

@Olli_Zi I’ve managed to sort the original error, apparently having ch.disable=true causes this failure.

I’m now getting the following error:
Cannot find CH RoutingAlgorithmFactory for weighting map{…}, - This comes from the getDecoratedAlgorithmFactory() method in CHAlgoFactoryDecorator.java.

Bizarrely, I can’t seem to debug this - if I make any changes to the code, remove the old jars and rebuild with ‘./graphhopper.sh web greater-london-latest.osm.pbf’ - none of the changes seem to be reflected. I can literally comment out everything in the getDecoratedAlgorithmFactory() method, rebuild the project and restart the webapp, and the same error appears.

Try following: Go to the directory with the pbf-file and delete the created directory “greater-london-latest-gh” (or something similar). Now execute your script again. The directory will created again.

Maybe this helps. If not, append the log file or the error message from the log.

Please give me feedback:)

1 Like

@Olli_Zi Thanks, I tried this (and also deleted the downloaded elevation data files), however I’m still getting the error as follows:

2017-08-05 17:47:12,695 [qtp1525409936-29] ERROR com.graphhopper.http.GHBaseServlet - point=51.493034%2C-0.210285&point=51.489186%2C-0.199471&type=json&locale=en-US&vehicle=foot&weighting=custom&elevation=true&key= 0:0:0:0:0:0:0:1 en_US Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 [51.493034,-0.210285, 51.489186,-0.199471], took:0.0303713, , custom, foot, errors:[java.lang.IllegalArgumentException: Cannot find CH RoutingAlgorithmFactory for weighting map {elevation=true, instructions=true, way_point_max_distance=1.0, calc_points=true, type=json, locale=en-US, weighting=custom, key=, vehicle=foot} in entries fastest|foot, ]

It is the same error, if you use “weighting=fastest”?

Take also a look at the error message: The both weighting parameter do not match, “custom” vs. “fastest”.

Use an IDE for customization and gradle for dependency management. Using the shell-script is not good practice in my eyes to inject custom weightings.

1 Like

Thanks, I think you’ve spotted something I’d missed. I didn’t get the error with “weighting=fastest”, however I did get the error with “weighting=shortest”, which was new. Previously I could change the weighting at runtime - and it returned different routes.

It turns out I had commented out the config setting ‘routing.ch.disabling_allowed=true’. With this uncommented and ch.disable=true in the URL, I can select any provided weighting. However, I’m back to getting a weighting null not supported with my custom weighting:

2017-08-06 11:59:12,945 [qtp1525409936-35] ERROR com.graphhopper.http.GHBaseServlet - point=51.554874%2C-0.296631&point=51.482238%2C-0.181274&type=json&locale=en-US&vehicle=foot&weighting=custom&elevation=true&key=&ch.disable=true 0:0:0:0:0:0:0:1 en_US Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36 [51.554874,-0.296631, 51.482238,-0.181274], took:0.002968037, , custom, foot, errors:[java.lang.IllegalArgumentException: weighting null not supported]

@Olli_Zi I’ve fixed it! It looks like there wasn’t anything wrong with my code, just some sort of glitch.

I tried cloning other projects extending GraphHopper to see if I could use their custom weightings. This didn’t work, but on restoring my project folder I found the webapp wouldn’t load properly. I recloned my own project from source control, and lo and behold, when I started up the server again, setting the weighting as ‘custom’ was working.

Thank you so much for all your help :slight_smile:

OK:) Congratulations.

1 Like