Routing for emergency vehicle

I’m trying to use graphhopper to plan routes for our emergency service response cars that use motorway access gates and service routes. I’m very new to Java - I’m just trying to see if I can do a proof of concept to take to my bosses so we can engage with a programmer.

I’ve successfully installed a local java installation from source and can use it to create standard car routes. I’ve tried editing the restricted values section of CarTagParser.java to:

    restrictedValues.add("agricultural");
    restrictedValues.add("forestry");
    restrictedValues.add("delivery");
    restrictedValues.add("military");

    restrictedValues.remove("emergency");
restrictedValues.remove("private");
restrictedValues.remove("no");
restrictedValues.remove("restricted");

I’ve also removed the recent update which restricts access for cars to service roads with emergency access.

I’ve deleted the files in graph-cache and then re-started the application without any success.

Here are two different examples of the access routes, one that includes the tag emergency: designated and one that just appears as a service highway.

When I select the local MVT layer, no overlay or information is displayed for these roads - could it be that they’re not being recognised by the OSM reader?

Instead of changing the CarFlagEncoder I recommend to use the new RoadsFlagEncoder instead and then restrict access as you need it. E.g. using a custom_model like:

{
 "speed": [
  {
   "if": "true",
   "limit_to": 130
  },{
   "if": "road_class == RESIDENTIAL || road_class == SERVICE",
   "limit_to": 30
  },{
   "if": "road_class == UNCLASSIFIED",
   "limit_to": 40
  },{
   "if": "road_class == TERTIARY",
   "limit_to": 70
  },{
   "if": "road_class == SECONDARY",
   "limit_to": 90
  },{
   "if": "road_class == PRIMARY",
   "limit_to": 100
  }
 ],
 "priority": [
    {
   "if": "car$access == false",
   "multiply_by": 0.2
  },
  {
   "if": "road_class == CYCLEWAY || road_class == FOOTWAY || road_class == PEDESTRIAN || road_class == PATH",
   "multiply_by": 0
  },{
   "if": "road_class != TRUNK || road_class != MOTORWAY",
   "multiply_by": 0.8
  },{
   "if": "road_class == TERTIARY",
   "multiply_by": 0.7
  }]
}

Please note the condition with car$access, this allows the vehicle to drive oneway roads in reverse order but still gives a big penalty for these cases so that this only happens when necessary. Please note that this model can only act as a start and you should introduce a conditional for motorways so that the reverse direction is never used and probably many more.

Also with the branch text_value_rhs it is even easier:

{
 "speed": [
  {
   "if": "true",
   "limit_to": "car$average_speed"
  }
 ],
 "priority": [
    ... same as before ...
 ]
}

Thanks for replying.

Unfortunately, that doesn’t create routes using the private segments of road. I’ve tried adding
{
“if”: “access == PRIVATE”,
“multiply_by”: 1
}
to the custom model and adding a limit_to entry. I’ve also tried changing the graph.flag_encoders entry to car|block_private=false.

When I use the local MVT layer, the roads that are listen as private access in OSM do not have an overlay with any data - see picture for example. When I edit the map in JOSM and change the road segment to public access then re-build the application, the segment has an MVT entry. Is it possible that the private access roads are not passing/visible to the routing engine?

Did you use the roads encoder instead of car? Remove the line with graph.flag_encoders and do:

  ...
  profiles:
    - name: roads # or name it `car` or `emergency` or something
      vehicle: roads
      weighting: custom
      custom_model_file: empty # or directly use the custom_model above

Sorry I misunderstood.

The top custom model worked as I hoped when I changed “car$access” to “car_access”. Using “car$access” produced the following error message in NetBeans:
“Error: Cannot compile expression: in ‘priority’ entry, invalid expression “car$access == false”: ‘car$access’ not available”

Likewise, the second model produced the following error message:
“Operations limit_to expects a number but was “car$average_speed” (through reference chain: com.graphhopper.util.CustomModel[“speed”]->java.util.ArrayList[0])”

In order to use this new feature (“value expressions”) you need to compile graphhopper on the mentioned branch as it is not yet in a stable release:

Powered by Discourse