Error creating a new custom profile

Hello guys,

I’ve been trying to create a new custom profile for big trucks, but when I activate the profile and put the graphhopper to run, I got the following error log.

java.lang.IllegalArgumentException: Could not create weighting for profile: 'big_truck'.
Profile: name=big_truck|turn_costs={null}|weighting=custom|hints={custom_model_files=[big_truck.json], custom_model=distanceInfluence=null|headingPenalty=null|speedStatements=[{"if": "max_height < 4.5", "multiply_by": 0.5}, {"if": "max_weight < 40", "multiply_by": 0.5}, {"else": "null", "multiply_by": 1.0}]|priorityStatements=[{"if": "road_class == MOTORWAY", "multiply_by": 1.5}, {"if": "road_class == TRUNK", "multiply_by": 1.3}, {"if": "road_class == PRIMARY", "multiply_by": 1.2}, {"if": "max_width < 3 || max_height < 4", "multiply_by": 0.01}, {"if": "max_weight < 18", "multiply_by": 0.01}, {"else": "null", "multiply_by": 1.0}]|areas=[]}
Error: Cannot compile expression: The first block needs to contain a single unconditional 'if' statement (or end with an 'else').

Here’s my big_truck.json custom model:

    {
      "priority": [
          {
              "if": "road_class == MOTORWAY",
              "multiply_by": "1.5"
          },
          {
              "if": "road_class == TRUNK",
              "multiply_by": "1.3"
          },
          {
              "if": "road_class == PRIMARY",
              "multiply_by": "1.2"
          },
          {
              "if": "max_width < 3 || max_height < 4",
              "multiply_by": "0.01"
          },
          {
              "if": "max_weight < 18",
              "multiply_by": "0.01"
          },
          { 
              "else": "",
              "multiply_by": "1.0"
          }
      ],
      "speed": [
          {
              "if": "max_height < 4.5",
              "multiply_by": "0.5"
          },
          {
              "if": "max_weight < 40",
              "multiply_by": "0.5"
          },
          { 
              "else": "",
              "multiply_by": "1.0"
          }
      ]
    }

any ideia about whats been happening?

You need to limit the speed unconditionally. For example your first speed statement could be if: true, limit_to: 100, which would set the speed to 100 everywhere. You could also use the default car speeds like if: true: limit_to: car_average_speed, or a fraction of that like if: true, limit_to: car_average_speed * 0.9. But in any case you need to have one speed rule that applies everywhere.

1 Like

Hi @easbar ,

Thanks for your help. I updated the custom model file, and It worked as below

{
      "priority": [
          { 
              "if": "true",
              "limit_to": "car_average_speed * 0.9"
          },
          {
              "if": "road_class == MOTORWAY",
              "multiply_by": "1.5"
          },
          {
              "if": "road_class == TRUNK",
              "multiply_by": "1.3"
          },
          {
              "if": "road_class == PRIMARY",
              "multiply_by": "1.2"
          },
          {
              "if": "max_width < 3 || max_height < 4",
              "multiply_by": "0.01"
          },
          {
              "if": "max_weight < 18",
              "multiply_by": "0.01"
          },
          { 
              "else": "",
              "multiply_by": "1.0"
          }
      ],
      "speed": [
          { 
              "if": "true",
              "limit_to": "car_average_speed * 0.9"
          },
          {
              "if": "max_height < 4.5",
              "multiply_by": "0.5"
          },
          {
              "if": "max_weight < 40",
              "multiply_by": "0.5"
          },
          { 
              "else": "",
              "multiply_by": "1.0"
          }
      ]
    }

Do you have any consideration about this custom model?

The unconditional rule is only required for the “speed” section. For “priority” the default value is simply 1.

Unconditionally, you mean the else statement?

Another question, I was able to active the profile I need with LM profile. But when I try to request via browser using http://localhost:8080/maps/?point=-22.223605%2C-54.812498&point=-22.7865%2C-43.32339&profile=big_truck&layer=OpenStreetMap&ch.disable=true, I receive the following error:

Cannot find CH preparation for the requested profile: 'big_truck' You can try disabling CH using ch.disable=true available CH profiles: [car, truck]

I understood the LM is activated by default if I ‘disable’ ch (It was not actived BTW). Is that correct?

Any idea about it?

No I meant the if: true, limit_to: car_average_speed * 0.9. This is only required for speed, but not priority.

This is because the ch.disable=true option is not picked up from the url. You would have to modify the web UI code to add request options like this.