Features

Precedence

A how-to guide for using precedence with vehicle routing.

This feature is configurable via .json input, without the need for code customization and is available for both the Marketplace app and Platform. You can find a list of all available features here.

This how-to guide assumes you already completed the get started with vehicle routing tutorial.

Field nameRequiredData typeSI UnitDefined onExampleConfigurable via defaults
precedesNoarray of string or stringNAstop{"precedes": ["foo", "bar"]}
succeedsNoarray of string or stringNAstop{"succeeds": ["foo", "bar"]}

The precedence constraint is used to indicate that a specific stop must be visited (pickup) before a different one (dropoff). You can use the precedes and succeeds fields on the stops of the input to work with precedence constraints as follows.

  • precedes: ensures that the pickup is visited before the dropoff. It is applied to the individual stop that must be visited before the stop id defined in the precedes field.
  • succeeds: can be used to model the precedence relation the other way around. Using the same example as above, the opposite would be specified: on the dropoff stop we define that it needs to succeed its pickup counterpart.

Both precedes and succeeds may be specified as:

  • a string value that specifies a relationship with a single stop given by its id.
  • an array of string values that specifies a relationship with multiple stops given by their ids. This array is unordered meaning that the order of the stops in the array will not be enforced in the assigned route.

Here is an example defining both types of precedence relationships and their types. A sample output obtained after solving the problem is also shown.

{
  "stops": [
    {
      "id": "Fushimi Inari Taisha",
      "location": { "lon": 135.772695, "lat": 34.967146 },
      "precedes": "Kiyomizu-dera"
    },
    {
      "id": "Kiyomizu-dera",
      "location": { "lon": 135.78506, "lat": 34.994857 }
    },
    {
      "id": "Nijō Castle",
      "location": { "lon": 135.748134, "lat": 35.014239 },
      "succeeds": "Kiyomizu-dera"
    },
    {
      "id": "Kyoto Imperial Palace",
      "location": { "lon": 135.762057, "lat": 35.025431 },
      "precedes": ["Gionmachi", "Kinkaku-ji"]
    },
    {
      "id": "Gionmachi",
      "location": { "lon": 135.775682, "lat": 35.002457 }
    },
    {
      "id": "Kinkaku-ji",
      "location": { "lon": 135.728898, "lat": 35.039705 }
    },
    {
      "id": "Arashiyama Bamboo Forest",
      "location": { "lon": 135.672009, "lat": 35.017209 },
      "succeeds": ["Gionmachi", "Kinkaku-ji"]
    }
  ],
  "vehicles": [
    {
      "id": "v1",
      "speed": 20
    }
  ]
}
Copy

Note that all stops that have a precedence relationship that groups them together will be assigned to the same vehicle in the final solution.

Both, precedes and succeeds, can be used in combination to model more complex precedence relationships.

Page last updated