How to Preprocess Multiple Route Restrictions Efficiently in Speed Mode (CH)?

GraphHopper Version:

Using GraphHopper [version 10.2] with Contraction Hierarchies (CH) enabled.

Problem:

I need to restrict routes based on different combinations of toll, ferry, and motorway. In OSRM, we achieved this using Lua:

Set {‘toll’}, Set {‘motorway’}, Set {‘ferry’}, Set {‘ferry’, ‘toll’}, Set {‘ferry’, ‘motorway’}, Set {‘toll’, ‘motorway’}, Set {‘ferry’, ‘toll’, ‘motorway’}

In GraphHopper, we are using custom_model like this:

profiles:
- name: car
  turn_costs:
    vehicle_types: [motorcar, motor_vehicle]
  custom_model_files: [ car.json]

- name: car_no_ferry
  turn_costs: 
    vehicle_types: [motorcar, motor_vehicle]
  custom_model:
    speed:
      - if: 'true'
        limit_to: "car_average_speed"
    priority:
      - if: "road_environment == FERRY"
        multiply_by: 0.0
      - if: "!car_access"
        multiply_by: 0.0
      - if: "road_access == DESTINATION || road_access == PRIVATE"
        multiply_by: 0.1

- name: car_no_toll
  weighting: custom  # Use 'custom' weighting for CustomModel
  turn_costs: 
    vehicle_types: [motorcar, motor_vehicle]
  custom_model:
    speed:
      - if: 'true'
        limit_to: "car_average_speed"
    priority:
      - if: "toll != NO"  # Corrected condition: Avoid toll roads
        multiply_by: '0.0'
      - if: "!car_access"
        multiply_by: '0.0'
      - if: "road_access == DESTINATION || road_access == PRIVATE"
        multiply_by: '0.1'

- name: car_no_motorway
  weighting: custom
  turn_costs: 
    vehicle_types: [motorcar, motor_vehicle]
  custom_model:
    speed:
      - if: 'true'
        limit_to: "car_average_speed"
    priority:
      - if: "road_class == MOTORWAY"
        multiply_by: 0.0
      - if: "!car_access"
        multiply_by: '0.0'
      - if: "road_access == DESTINATION || road_access == PRIVATE"
        multiply_by: '0.1'

Issue:

  1. This increases preprocessing time significantly because CH requires separate graphs for each profile.
  2. In OSRM, preprocessing was faster due to Lua-based filtering. In GraphHopper, CH preprocessing is expensive.
  3. I do NOT want to apply restrictions at runtime but precompute them.

Questions:

  1. How can I reduce preprocessing time while keeping CH enabled?
  2. Is there a better way to precompute restrictions without creating too many profiles?

Any insights would be appreciated!

There is no specific way to improve speed for CH preprocessing. (However, if you can live without the turn costs config, then this will make the preprocessing a lot faster.)

Or do you mean that the processing of the normal car with CH is faster than e.g. the processing of the car that avoids ferry?

because CH requires separate graphs for each profile

Not really full graphs, but additional data, yes. But if you are using OSRM then you would need to duplicate the entire installation for each profile (according to my potential outdated information)

I do NOT want to apply restrictions at runtime but precompute them.

Then you can use CH as you did or LM (where the preprocessing is faster when using turn costs but the requests are slower)

You can increase the number of threads used for the preparation using the prepare.ch.threads parameter in your config file. For seven profiles setting prepare.ch.threads: 7 should result in an import time that is roughly the same as for a single profile, provided that you have enough RAM to process seven CH profiles at once, of course.

I’m not sure what you mean by Lua-based filtering. Can you be more specific or point to some OSRM documentation that explains this? I don’t see how the Lua configuration could possibly speed up the CH preparation for multiple profiles (other than running them in parallel like GraphHopper also can do as I explained above).

My bad, yes you are right, I was talking about the exclude flags

I have to prepare for all profiles, I will try with an increased thread count.

Does OSRM then support these exclude parameters per request or will the resulting profile exclude tolls, motorways and ferries?