Having trouble loading custom vehicle profile json

Hi, I’m running Graphhopper locally on my android. I’m attempting to load vehicle profiles from json using the following code.

ObjectMapper jsonOM = Jackson.newObjectMapper();
return jsonOM.readValue(new File(customModelLocation), CustomModel.class);

However, even when I use the official examples from here Examples For Customizable Routing - GraphHopper Directions API
I get the following error message

Cannot deserialize instance of java.util.LinkedHashMap<java.lang.Object,java.lang.Object> out of START_ARRAY token

Digging into the indices, it appears to be objecting to the open square bracket after after “priority”

For example in this file, (from the above link)
{
“priority”: [{
“if”: “road_class == PRIMARY”,
“multiply_by”: 0.1
}]
}

I get the following detail
[Source: (File); line: 2, column: 14]

Any advice would be welcome, thanks!

I’ve learned a little more by trial and error. It looks like if I use a file of the following format
{
“priority”: {
“max_length”: {
" < 10.7": 0
},
“max_weight”: {
" < 25.0": 0
}
}}

It at least loads properly. However I’m still completely stuck on how to represent area-based priorities.

Any help would be welcome

I recommend to use the latest stable version 5.0 (or at least >=3.0) where the syntax is easier to read and more powerful.

Thanks

So, I’ve upgraded to 5 and I’m a little further. However when I call importOrLoad() right after initting my Graphhopper, I get the following error. Any thoughts?

04-18 15:18:07.117 7479 7479 E AndroidRuntime: Error: Cannot compile expression, in source: File ‘source’, Line 1, Column 50: A class “com.graphhopper.routing.weighting.custom.CustomWeightingHelper” could not be found

The (probably helpful) info line right before it is:

04-18 15:18:07.117 7479 7479 E AndroidRuntime: Profile: name=theirs_new_polygon|vehicle=car|weighting=custom|turnCosts=false|hints={custom_model=distanceInfluence=null|headingPenalty=300.0|speedStatements=[]|priorityStatements=[{“if”: “max_length < 10.7”, “multiply_by”: 0.0}, {“if”: “max_weight < 25.0”, “multiply_by”: 0.0}, {“if”: “in_runways”, “multiply_by”: 0.0}]|areas={runways=id:null}, custom_model_file=empty}

I’m using one of the examples from the example link I mentioned in my original post.

TIA

You seem to use GraphHopper on Android. We do only support the OpenJDK and there is no support for VMs like ART or Dalvik (for Android OS) that state to support Java but in reality never really supported it (library-wise). Which makes many things really ugly. See Future of 'Offline' Routing · Issue #1940 · graphhopper/graphhopper · GitHub

And although the expression engine we use (janino) supports JREs 7+ it only emits JVM bytecode: compiler · Issue #66 · janino-compiler/janino · GitHub

1 Like
Powered by Discourse