Force higher priority services over lower priority

Hi there. I’m facing an issue regarding service priorities. When I establish a higher priority on a specific service, It doesn’t get placed before another with a lower priority. I’m testing really simple routes with only 2 stops and it’s not working.

Example request JSON Body:

{
  "vehicles": [
    {
      "vehicle_id": "vehicle_1",
      "type_id": "veh_type",
      "start_address": {
        "location_id": "40.6025767_-3.7024083",
        "lon": -3.7024083,
        "lat": 40.6025767
      },
      "earliest_start": 1640608200,
      "return_to_depot": true
    }
  ],
  "vehicle_types": [
    {
      "type_id": "veh_type",
      "profile": "car"
    }
  ],
  "services": [
    {
      "id": "0",
      "name": "Service 0",
      "address": {
        "location_id": "40.4507261_-3.7742854",
        "lon": -3.7742854,
        "lat": 40.4507261
      },
      "priority": 10
      
    },
    {
      "id": "1",
      "name": "Service 1",
      "address": {
        "location_id": "40.4332156_-3.647966199999999",
        "lon": -3.647966199999999,
        "lat": 40.4332156
      },
      "priority": 1
    }
  ]
}

As far as I understand, service with id = 1 should be placed in first place (higher priority), but the response always returns id = 0 in first place no matter it has a lower priority.

In general, the solution I’m looking for is getting the best route with the defined objectives, but with the restriction of forcing all higher priority services to be done before any of the lower priority services.

Is there any possibility to achieve this?

Thank you in advance!

Hi Ethan,

The priority is to with the allocation of eligible services into the schedule rather than the order of the services. See docs here: Documentation - GraphHopper Directions API

Priority: Specifies the priority. Can be 1 = high priority to 10 = low priority. Often there are more services/shipments than the available vehicle fleet can handle. Then you can set priorities to differentiate high priority tasks from those that could be left unassigned. i.e. the lower the priority the earlier these tasks are omitted in the solution.

The solution is trying to provide you the best route for all your services and all your services in the problem fit. If you want some services to be visited first I believe you will need to use timeWindows (see: Documentation - GraphHopper Directions API) and a high priority.

Regards

1 Like

:+1:

You can also use the relations feature for applying some ordering:

See also the more recent neighbor relation: