Problems with custom profiles

Hi! I’m new to Graphhopper, I managed to get the graphhopper-web-10.2.jar routing engine work with build-in car and foot profiles, but creating a working custom profile seems to be impossible. I’d like to use GH for emergency vehicle routing, and i created a simple ambulance.json file containing following:

{
“speed”: [
{
“if”: “true”,
“multiply_by”: “1.2”
}
]
}

Basically I just wanted to multiply speeds with 1.2.

In config.yml I added to profiles section:

  • name: ambulance
    custom_model_files: [ambulance.json]

When importing the config, I get
2025-06-20 10:57:33.261 [main] INFO com.graphhopper.GraphHopper - version 10.2|2025-01-20T08:40:08Z (9,23,7,5,2,9)
java.lang.IllegalArgumentException: Could not create weighting for profile: ‘ambulance’.
Profile: name=ambulance|turn_costs={null}|weighting=custom|hints={custom_model_files=[ambulance.json], custom_model=distanceInfluence=null|headingPenalty=null|speedStatements=[{“if”: “true”, "multiply_by: “1.2”}]|priorityStatements=|areas=}
Error: Cannot compile expression: The first group needs to contain a single unconditional ‘if’ statement (or end with an ‘else’).

I just don’t understand what I’m doing wrong. Any ideas?

The same problem was answered recently here: Error creating a new custom profile - #2 by easbar

Maybe we could add something like “otherwise the speed might be undefined for some roads” to clarify? @Zombinol would this have been helpful for you to understand what you’re doing wrong?

I think I understood, but just don’t know how to get it to work…

{
“speed”: [
{
“if”: “true”,
“limit_to”: “50”
}
]
}

This works, but I don’t understand why doesn’t the following work as well? Ain’t the “if”: “true” condition always true?

{
“speed”: [
{
“if”: “true”,
“multiply_by”: “1.2”
}
]
}

Yes, it’s always true. But before you set the speed for every edge there is nothing it can be ‘multiply(ied)_by’, so you need to set the speed first with limit_to. There is no default value for the speed otherwise.

And yes, this cannot be seen from the error message.

My brain is twitching, but now it seems to work! Thank you!