Features

Time windows

A how-to guide for using time windows 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.

The format for timestamps should be RFC3339, e.g.: "2023-01-01T00:00:00Z".

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

Field nameRequiredData typeSI UnitDefined onExampleConfigurable via defaults
start_time_windowNoarray of timestamp or array of array of timestampNAstop{"start_time_window": [["2023-01-01T12:00:00Z", "2023-01-01T12:05:00Z"], ["2023-01-01T12:30:00Z", "2023-01-01T13:35:00Z"]]}

In vehicle routing problems stops often have to be serviced within specific time windows. E.g., in a bike sharing problem the stations have to be filled up with bikes while they are empty or bikes have to be picked up while they are full.

The start_time_window feature allows you to define a time window (or multiple time windows) for when a stop must start to be serviced. The time window is an array of two timestamps (or array of array of two timestamps), defined by the earliest and latest times at which a stop can start service.

A vehicle may arrive before the start_time_window opens, in which case it will have to wait to start servicing the stop. The waiting time can be limited by using the max_wait feature.

Here is an example that defines time windows on stops. A sample output obtained after solving the problem is also shown.

{
  "defaults": {
    "vehicles": {
      "speed": 20,
      "start_time": "2023-01-01T12:00:00Z"
    },
    "stops": {
      "duration": 300
    }
  },
  "stops": [
    {
      "id": "Fushimi Inari Taisha",
      "location": { "lon": 135.772695, "lat": 34.967146 },
      "start_time_window": ["2023-01-01T12:00:00Z", "2023-01-01T12:05:00Z"]
    },
    {
      "id": "Kiyomizu-dera",
      "location": { "lon": 135.78506, "lat": 34.994857 },
      "start_time_window": ["2023-01-01T12:05:00Z", "2023-01-01T12:10:00Z"]
    },
    {
      "id": "Nijō Castle",
      "location": { "lon": 135.748134, "lat": 35.014239 },
      "start_time_window": ["2023-01-01T12:10:00Z", "2023-01-01T12:15:00Z"]
    },
    {
      "id": "Kyoto Imperial Palace",
      "location": { "lon": 135.762057, "lat": 35.025431 },
      "start_time_window": ["2023-01-01T12:15:00Z", "2023-01-01T12:20:00Z"]
    },
    {
      "id": "Gionmachi",
      "location": { "lon": 135.775682, "lat": 35.002457 },
      "start_time_window": ["2023-01-01T12:20:00Z", "2023-01-01T12:25:00Z"]
    },
    {
      "id": "Kinkaku-ji",
      "location": { "lon": 135.728898, "lat": 35.039705 },
      "start_time_window": ["2023-01-01T12:25:00Z", "2023-01-01T12:30:00Z"]
    },
    {
      "id": "Arashiyama Bamboo Forest",
      "location": { "lon": 135.672009, "lat": 35.017209 },
      "start_time_window": ["2023-01-01T12:30:00Z", "2023-01-01T12:35:00Z"]
    }
  ],
  "vehicles": [
    {
      "id": "v1"
    },
    {
      "id": "v2"
    }
  ]
}
Copy

Here is an example using multiple time windows on stops.

{
  "defaults": {
    "vehicles": {
      "speed": 15,
      "start_time": "2023-01-01T12:00:00Z"
    },
    "stops": {
      "unplanned_penalty": 20000,
      "duration": 600,
      "start_time_window": [
        ["2023-01-01T12:00:00Z", "2023-01-01T12:05:00Z"],
        ["2023-01-01T12:30:00Z", "2023-01-01T13:35:00Z"]
      ]
    }
  },
  "stops": [
    {
      "id": "Kyoto Imperial Palace",
      "location": { "lon": 135.77159, "lat": 34.96714 }
    },
    {
      "id": "Gionmachi",
      "location": { "lon": 135.77159, "lat": 34.96714 }
    },
    {
      "id": "Kinkaku-ji",
      "location": { "lon": 135.77159, "lat": 34.96714 },
      "start_time_window": ["2023-01-01T12:20:00Z", "2023-01-01T12:25:00Z"]
    }
  ],
  "vehicles": [
    {
      "id": "v1"
    }
  ]
}
Copy

Page last updated