How to set priorities, define the first and last point beyond the warehouse

I have a route optimization problem where, 1st requirement: I need to determine which is the first city/point that my route should start from. Some loads carry heavy products that should be unloaded first. 2nd requirement: I also need to determine which is the last city my route should have. Note: my vehicle has a defined depot and “return_to_depot”: true.

I’m trying to make the point that I set high priority to be the first on the route, is this possible? If not, what is the correct way to define the first city where my route starts, in addition to the warehouse coordinates?

Base code

{
  "objectives": [
    {
      "type": "min",
      "value": "completion_time"
    }
  ],
  "vehicles": [
    {
      "vehicle_id": "v1",
      "type_id": "custom_vehicle_type",
      "start_address": {
        "location_id": "v1",
        "lat":-27.676941,
        "lon": -52.288830
      },
      "earliest_start": 1508839200,
      "return_to_depot": true
    }
  ],
  "vehicle_types": [
    {
      "type_id": "custom_vehicle_type",
      "profile": "car"
    }
  ],
  "services":[
    {
        "id": "s-1",
        "address": {
            "location_id": "Liberato Salzano",
            "lon": -53.0748607372178,
            "lat": -27.5964701638556
        },
        "priority": 10
    },
    {
        "id": "s-2",
        "address": {
            "location_id": "Jaboticaba",
            "lon": -53.2843894020471,
            "lat": -27.631222386294
        },
        "priority": 10
    },
    {
        "id": "s-3",
        "address": {
            "location_id": "Erval Seco",
            "lon": -53.5095730836612,
            "lat": -27.5494171265095
        },
        "priority": 1
    }
]
}

In the example above, it doesn’t make any difference if I change the priority because the sequence of points remains the same

Priorities do not help here. You can use relations to determine sequences before. Here is your example with “s-3” as first stop.

{
  "objectives": [
    {
      "type": "min",
      "value": "completion_time"
    }
  ],
  "vehicles": [
    {
      "vehicle_id": "v1",
      "type_id": "custom_vehicle_type",
      "start_address": {
        "location_id": "v1",
        "lat": -27.676941,
        "lon": -52.28883
      },
      "earliest_start": 1508839200,
      "return_to_depot": true
    }
  ],
  "vehicle_types": [
    {
      "type_id": "custom_vehicle_type",
      "profile": "car"
    }
  ],
  "services": [
    {
      "id": "s-1",
      "address": {
        "location_id": "Liberato Salzano",
        "lon": -53.0748607372178,
        "lat": -27.5964701638556
      },
      "priority": 10
    },
    {
      "id": "s-2",
      "address": {
        "location_id": "Jaboticaba",
        "lon": -53.2843894020471,
        "lat": -27.631222386294
      },
      "priority": 10
    },
    {
      "id": "s-3",
      "address": {
        "location_id": "Erval Seco",
        "lon": -53.5095730836612,
        "lat": -27.5494171265095
      },
      "priority": 1
    }
  ],
  "relations": [
    {
      "type": "in_direct_sequence",
      "ids": [
        "start",
        "s-3"
      ]
    }
  ]
}

Just copy and paste it here: https://explorer.graphhopper.com/ to see the impact of relations.

1 Like

Thanks for your help !! :smiley:
I managed to define the penultimate and last point in the same way.

"relations": [
    {
      "type": "in_direct_sequence",
      "ids": [
        "start",
        "s-5"
      ]
    },
        {
      "type": "in_direct_sequence",
      "ids": [
        "s-1",
        "end"
      ]
    }
  ]
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.