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:
- This increases preprocessing time significantly because CH requires separate graphs for each profile.
- In OSRM, preprocessing was faster due to Lua-based filtering. In GraphHopper, CH preprocessing is expensive.
- I do NOT want to apply restrictions at runtime but precompute them.
Questions:
- How can I reduce preprocessing time while keeping CH enabled?
- Is there a better way to precompute restrictions without creating too many profiles?
Any insights would be appreciated!