• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

Route Optimization Fast API

Introduction

Nextbillion.ai’s Route Optimization Fast API solves for the optimization of a Multi(or single) vehicle routing problem. There are two components to API

  1. Optimization POST - Use this method to submit the input for your VRP.

  2. Optimization GET - Retrieve the status of a submitted VRP using a unique reference ID.

Route Optimization Fast API
Tutorials
To see all tutorials related to the Route Optimization Fast API, click this banner

General Notes:

  • A "task" is either a job, a pickup or a delivery

  • The expected order for all location arrays is [latitude, longitude]

  • All the timestamps are UNIX in seconds and other time-related parameters’ units are in seconds.

  • All the distance-related parameter units are in meters.

  • A time_window object is a pair of UNIX epoch timestamps in the form [start, end].

  • Cost values in output are the ones used in the optimization objective.

Optimization POST

POST

https://api.nextbillion.io/optimise-mvrp?key={your_api_key}


Use this method to configure the constraints and properties of the optimization problem that you need to solve. Use the fundamental objects - vehicles, jobs, locations and shipments to emulate the scenario that your business needs to optimize. You can choose to use either one of jobs and shipments or use both of them.

The objective to be achieved during optimization can be defined in the optionspart. Once an Optimization POST request is successfully submitted, the API will return a unique task ID in the acknowledgement response. Use this unique ID to retrieve the actual solution using the Optimization GET Method.

Request Parameters

Loading..

Request Body

Loading..

Response Schema

Loading..

Sample Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
curl --location 'https://api.nextbillion.io/optimise-mvrp?key=<your_api_key>' 
--header 'Content-Type: application/json' 
--data '
{
  "locations": {
    "id": 2,
    "location": "1.29360227,103.80828989|1.29360227,103.8273062|1.30227739,103.84595327|1.31482858,103.84503015|1.31925839,103.86312334|1.3248957169,103.8285176106|1.2996042263,103.8112802999|1.2830643677,103.8343527086|1.2856021297,103.8384649827"
  },
  "description": "Test shipments",
  "jobs": [
    {
      "id": 8,
      "location_index": 0,
      "service": 300,
      "delivery": [1],
      "setup": 200,
      "pickup": [1],
      "time_windows": [[1656327600, 1656342000]]
    },
    {
      "id": 9,
      "location_index": 1,
      "service": 300,
      "delivery": [1],
      "pickup": [1],
      "time_windows": [[1656327600, 1656332000]]
    },
    {
      "id": 100,
      "location_index": 3,
      "service": 300,
      "delivery": [1],
      "pickup": [1],
      "time_windows": [[1656327600, 1656362000]]
    }
  ],
  "vehicles": [
    {
      "id": 1,
      "start_index": 3,
      "end_index": 3,
      "capacity": [46],
      "time_window": [1656327600, 1656372000],
      "skills": [2, 3]
    },
    {
      "id": 2,
      "start_index": 1,
      "end_index": 1,
      "capacity": [46],
      "time_window": [1656327600, 1656352000]
    }
  ],
  "shipments": [
    {
      "pickup": {
        "id": 1,
        "service": 300,
        "location_index": 6,
        "time_windows": [[1656329600, 1656342000]]
      },
      "delivery": {
        "id": 1,
        "service": 300,
        "location_index": 3,
        "time_windows": [[1656339600, 1656352000]]
      },
      "amount": [5],
      "skills": [2],
      "priority": 100
    }
  ]
}'

Sample Response

1
2
3
4
5
6
7
8
9
10
{
"id": "e1467c725225edefa973b5b544f88b70",
"message": "Optimization job created",
"status": "Ok",
"warning": [
"location_index[2] and 4 others are unused",
"location_index[0] and 2 others are used for both pickup and dropoff",
"location_index[3] and 1 others are used for both pickups/deliveries as well as vehicle start/end"
]
}

Optimization GET Request

GET

https://api.nextbillion.io/optimise-mvrp/result?{id}&key={your_api_key}


Use this method to retrieve the optimized solution for the optimization tasks created using the Optimization POST Method.

Request Parameters

Loading..

Response Schema

Loading..

Sample Request

1
2
curl --location 
  'https://api.nextbillion.io/optimise-mvrp/result?key=<your_api_key>&id=e1467c725225edefa973b5b544f88b70'

Sample Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{
   "result":{
      "code":0,
      "summary":{
         "cost":4359,
         "routes":1,
         "unassigned":1,
         "setup":0,
         "service":0,
         "duration":4359,
         "waiting_time":0,
         "priority":0,
         "delivery":[
            3
         ],
         "pickup":[
            3
         ]
      },
      "unassigned":[
         {
            "id":1,
            "location":[
               1.35369921,
               103.9554801
            ]
         }
      ],
      "routes":[
         {
            "vehicle":1,
            "cost":4359,
            "steps":[
               {
                  "arrival":1655693482,
                  "duration":0,
                  "setup":0,
                  "service":0,
                  "waiting_time":0,
                  "location":[
                     1.42495049,
                     103.79807462
                  ],
                  "load":[
                     3
                  ]
               },
               {
                  "arrival":1655694739,
                  "duration":1257,
                  "setup":0,
                  "service":0,
                  "waiting_time":0,
                  "location":[
                     1.35369921,
                     103.9554801
                  ],
                  "id":5,
                  "load":[
                     0
                  ]
               },
               {
                  "arrival":1655696519,
                  "duration":3037,
                  "setup":0,
                  "service":0,
                  "waiting_time":0,
                  "location":[
                     1.31943721,
                     103.74590942
                  ],
                  "id":2,
                  "load":[
                     3
                  ]
               },
               {
                  "arrival":1655697841,
                  "duration":4359,
                  "setup":0,
                  "service":0,
                  "waiting_time":0,
                  "location":[
                     1.42495049,
                     103.79807462
                  ],
                  "load":[
                     3
                  ]
               }
            ],
            "setup":0,
            "service":0,
            "duration":4359,
            "waiting_time":0,
            "priority":0,
            "delivery":[
               3
            ],
            "pickup":[
               3
            ]
         }
      ]
   },
   "status":"Ok",
   "message":""
}

Object Overview

Location Object

  • The location object contains a list of coordinates in [lat, lon] format. Other properties in the request will refer to coordinates specified in the location object via their index parameter. An example of a location object can be understood via the following table

  • "Location" : "51.388997,-0.119022 | 51.391915,-0.103666 | 51.369777,-0.10438 | 51.365014,-0.105654 | 51.351818,-0.014773"

    IndexLocation
    051.388997,-0.119022
    151.391915,-0.103666
    251.369777,-0.10438
    351.365014,-0.105654
    451.351818,-0.014773
  • So for example, if in the "vehicles" property, the start_index parameter is set to 2, then the starting coordinate for that vehicle is 51.369777,-0.10438 as per the above table.

Vehicles Object

vehicles object describes the characteristics and constraints of a vehicle that will be used in a multi-vehicle routing problem. Some points to consider about vehicles object:

  • The users can set a start or an end location of their choice as long as it is present in the locations object. The vehicle’s start and end locations can be different from job locations.

  • If the optional start_index parameter is not used, the route will start from the location of the depot to which the vehicle is assigned. Otherwise, the route will start at the first visited task whose choice is determined by the optimization process.

  • If optional end_index parameter is not used, the route will end at the location of the depot to which the vehicle is assigned. Otherwise, the route will end at the last visited task whose choice is determined by the optimization process.

  • In order to request a round trip, you can specify both start_index and end_index with the same location index. Alternatively, the users can assign a depot to the vehicle and leave start_index and end_index unspecified to make the vehicle start and finish at the depot’s location.

  • breaks parameter can be used to plan the breaks that the driver needs to take.

  • costs of the vehicles can be used to prefer lower cost vehicles over higher cost vehicles.

Capacity Restrictions

  • Use amounts (capacity for vehicles, delivery, and pickup for jobs, amount for shipments) to describe a problem with capacity restrictions. Those arrays can be used to model custom restrictions for several metrics at once, e.g. number of items, weight, volume, etc. The order and number of the dimensions must match the order & number of dimensions in the capacity parameter of the vehicle object. For example

    • If capacity = [quantity, weight, volume], each of the parameters (delivery, pickup, amount) must contain [quantity, weight, volume] information.
  • A vehicle is only allowed to serve a set of tasks if the resulting load at each route step is lower than the matching value in capacity for each metric. When using multiple components for amounts, it is recommended to put the most important/limiting metrics first.

  • It is assumed that all delivery-related amounts for jobs are loaded at vehicle start, while all pickup-related amounts for jobs are brought back at vehicle end.

  • All capacity values are integers. It is recommended that the user should convert any non-integer values rounded up to the nearest integer. For example, if a shipment has a weight of 14.57 kg, it is recommended to use 15 in the capacity property.

Skills Restrictions

Use skills to describe a problem where not all tasks can be served by all vehicles. Job skills are mandatory, i.e. a job can only be served by a vehicle that has all its required skills. In other words: job j is eligible to vehicle v if and only if j.skills is contained in v.skills. This definition implies in particular that:

  • a task without skills can be served by any vehicle;

  • a vehicle without skills can only serve tasks with no particular skills

In order to ease modeling problems with no skills required, not providing a skills key defaults to providing an empty array.

Task Setup & Service times

Setup times serve as a means to describe the time it takes to get started for tasks at a given location. This model has a duration that should not be re-applied for other tasks following at the same place.

Service times on the other hand are the times needed for performing services. If for example, a location has 3 different tasks to be completed, each task might have a different service duration.

So the total "action time" for a task is setup + service upon arriving at a new location or service only if performing a new task at the previous vehicle location.

Depots

Depots are congregation points for vehicles. A Depot can contain multiple vehicles. It has the following key features.

  • A depot is assumed to have infinite inventory.

  • If the depot attribute is set for a vehicle, the start_index of a vehicle will need to be set to the location index set by the depot attribute. As an alternative, you can simply not set the start_index and internally, it will be set to the depot’s location. However, the end location for a vehicle can be different from the depot’s location.

  • If the depot attribute is set for a vehicle, and end_index is not set, the end location for the vehicle will be set to the depot’s location_index.

  • There is no restriction on the number of vehicles a depot can contain but one vehicle can only be assigned to one depot.

API Query Limits

  • Nextbillion.ai allows a maximum rate limit of 300 queries per minute or 5 queries/second for continuous requests.

    Note: We can increase the quota if needed on request. Contact [email protected] for more details.

  • At any point the maximum number of pending requests that the queue can hold is 25, for a given API key. New requests for the same key can be submitted once some of the pending requests are resolved.

  • A maximum of 2000 locations can be added to the locations object

  • A maximum of 2000 tasks can be added in an optimization problem. Number of tasks is calculated as number of jobs + 2 * (number of shipments).

  • Maximum value that can be provided for truck_weight is 100,000 kg.

  • Maximum dimensions for truck_size are 5000 cm for length, 5000 cm for width, 1000 cm for height.

  • When using traffic_timestamp or truck related parameters in the routing property of options attribute, please expect a higher request processing time, especially if the number of locations provided in the request is also high.

API Error Codes

Response CodeDescriptionAdditional Notes
200Normal success case.

Normal success case.

400Input validation failed.

There is a missing or an invalid parameter or a parameter with an invalid value type is added to the request.

401APIKEY not supplied or invalid.

This error occurs when the wrong API key is passed in the request or the key is missing altogether

403APIKEY is valid but does not have access to requested resources.

You might be querying for a geographical region which is not valid for your account or requesting a service which is not enabled for you.

404Requested host/path not found.

This error occurs when a malformed hostname is used.

422Could not process the request.

A feasible solution could not be generated for the given set of locations or parameter configuration.

429Too many requests.

QPM or API request count quota reached

500Internal Service error.

There was an internal issue with NextBillion.ai services. You can reach out to [email protected] for an explanation.