Route Optimization Flexible API

Introduction

Nextbillion.ai's Route Optimization Flexible API is a powerful tool that helps businesses optimize their delivery routes to maximize efficiency, save time, and reduce costs. It is designed to solve both Single and/or Multi Vehicle Routing Problem (VRP), which is a classic optimization problem in operations research that involves finding the optimal set of routes for a fleet of vehicles to visit a set of locations while satisfying various constraints such as time windows, capacity, and vehicle availability.

The Route Optimization Flexible API consists of two main components - the input data and the optimization engine. The input data includes information about the jobs (stops/places to visit), vehicles (delivery trucks, vans, etc.), and shipments (pickup and delivery tasks), while the optimization engine uses this data to find the most efficient set of routes for the vehicles to follow.

With the ability to handle complex constraints and variables such as capacity, time windows, and vehicle availability, our API can be customized to meet specific needs of your business.

There are two components to API

  1. Optimization Post - Use this method to submit input for your VRP.
  2. Optimization GET - Retrieve the status of a submitted VRP using a unique reference ID.

Optimization POST Method

POST

https://api.nextbillion.io/optimization/v2?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.

Define the objective of your optimization, soft-constraints and routing preferences in the options object. You can also use advanced features like re-optimization and order sequencing using the solutions and relations object respectively.

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 Parameter

Loading..

Request Body

Loading..

Response Schema

Loading..

Example

Let us build a basic flexible route optimization request using a sample scenario which has:

  • 2 vehicles with properties like capacity, time_window, start_index, end_index and skills set.

  • 6 jobs and 1 shipments with their id, locations, pickup/delivery amounts, time_windows and service time set.

Request

1
curl --location 'https://api.nextbillion.io/optimization/v2?key=<your_api_key>' --request POST \
2
--header 'Content-Type: application/json' \
3
--data-raw '{
4
"description": "Los Angeles Sample Optimization",
5
"locations": {
6
"id": 2,
7
"location": ["34.06675919,-118.30620984", "34.04268850,-118.28191077", "34.03434239,-118.28358834", "34.04238041,-118.23817754", "34.08431954,-118.25597762", "34.06892275,-118.29156827", "34.01103011,-118.19238067", "34.08659806,-118.17526366", "34.06624918,-118.11066669", "34.05221370,-118.28427087"]
8
},
9
"jobs": [
10
{
11
"id": 8,
12
"location_index": 0,
13
"service": 300,
14
"pickup": [
15
1
16
],
17
"time_windows": [
18
[
19
1688112000,
20
1688119200
21
]
22
]
23
},
24
{
25
"id": 9,
26
"location_index": 1,
27
"service": 300,
28
"pickup": [
29
1
30
],
31
"time_windows": [
32
[
33
1688112000,
34
1688119200
35
]
36
]
37
},
38
{
39
"id": 100,
40
"location_index": 3,
41
"service": 300,
42
"pickup": [
43
1
44
],
45
"time_windows": [
46
[
47
1688119200,
48
1688122800
49
]
50
]
51
},
52
{
53
"id": 18,
54
"location_index": 6,
55
"service": 300,
56
"delivery": [
57
1
58
],
59
"time_windows": [
60
[
61
1688126400,
62
1688130000
63
]
64
]
65
},
66
{
67
"id": 28,
68
"location_index": 7,
69
"service": 300,
70
"delivery": [
71
1
72
],
73
"time_windows": [
74
[
75
1688126400,
76
1688137200
77
]
78
]
79
},
80
{
81
"id": 38,
82
"location_index": 4,
83
"service": 300,
84
"delivery": [
85
1
86
],
87
"time_windows": [
88
[
89
1688126400,
90
1688137200
91
]
92
]
93
}
94
],
95
"vehicles": [
96
{
97
"id": 1,
98
"start_index": 8,
99
"end_index": 8,
100
"capacity": [
101
46
102
],
103
"time_window": [
104
1688110200,
105
1688140800
106
],
107
"skills": [2, 3]
108
}, {
109
"id": 2,
110
"start_index": 9,
111
"end_index": 9,
112
"capacity": [
113
46
114
],
115
"time_window": [
116
1688110200,
117
1688146200
118
]
119
}
120
],
121
"shipments": [
122
{
123
"pickup": {
124
"id": 1,
125
"service": 300,
126
"location_index": 2,
127
"time_windows": [[1688122800, 1688126400]]
128
},
129
"delivery": {
130
"id": 1,
131
"service": 300,
132
"location_index": 5,
133
"time_windows": [[1688126400, 1688130000]]
134
},
135
"amount": [5],
136
"skills": [2],
137
"priority": 100
138
}
139
]
140
}'

The above problem statement would look like the following when visualized on a map. We can see the locations of the 2 vehicles, 6 jobs and a shipment task. We will cover the solution and how it looks on a map in the next section.

documentation image

Response

1
{
2
"id": "3b14afd6c576690eb1df5c6871090383",
3
"message": "Optimization job created",
4
"status": "Ok"
5
}

Optimization GET Method

GET

https://api.nextbillion.io/optimization/v2/result?{id}&key={your_api_key}


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

A point worth highlighting here is that the optimizer uses traffic conditions at the time of making the request to prepare a solution. Slight changes in traffic conditions can cause the optimizer to prefer different routes and possibly different sequences in which to fulfill the jobs or shipments. Therefore, different optimization requests made with similar task or constraint configuration are expected to return different optimized solutions.

Request Parameters

Loading..

Response Schema

Loading..

Example

Let’s retrieve the same job that was created in the example above in the Optimization POST Method section.

Request

1
curl --location --request GET 'https://api.nextbillion.io/optimization/v2/result?id=3b14afd6c576690eb1df5c6871090383&key=<your_api_key>'

Response

1
{
2
"description": "Los Angeles Sample Optimization",
3
"result": {
4
"code": 0,
5
"summary": {
6
"cost": 6774,
7
"routes": 2,
8
"unassigned": 0,
9
"setup": 0,
10
"service": 2400,
11
"duration": 6774,
12
"waiting_time": 1696,
13
"priority": 200,
14
"delivery": [8],
15
"pickup": [8],
16
"distance": 88544
17
},
18
"routes": [
19
{
20
"vehicle": 1,
21
"cost": 5391,
22
"steps": [
23
{
24
"type": "start",
25
"arrival": 1688121973,
26
"duration": 0,
27
"service": 0,
28
"waiting_time": 0,
29
"location": [34.06624918, -118.11066669],
30
"location_index": 8,
31
"load": [3],
32
"distance": 0
33
},
34
{
35
"type": "job",
36
"arrival": 1688122800,
37
"duration": 827,
38
"service": 300,
39
"waiting_time": 0,
40
"location": [34.04238041, -118.23817754],
41
"location_index": 3,
42
"id": 100,
43
"load": [4],
44
"distance": 15357
45
},
46
{
47
"type": "pickup",
48
"arrival": 1688123729,
49
"duration": 1456,
50
"service": 300,
51
"waiting_time": 0,
52
"location": [34.03434239, -118.28358834],
53
"location_index": 2,
54
"id": 1,
55
"load": [9],
56
"distance": 23975
57
},
58
{
59
"type": "job",
60
"arrival": 1688124704,
61
"duration": 2131,
62
"service": 300,
63
"waiting_time": 1696,
64
"location": [34.08431954, -118.25597762],
65
"location_index": 4,
66
"id": 38,
67
"load": [8],
68
"distance": 32327
69
},
70
{
71
"type": "delivery",
72
"arrival": 1688127297,
73
"duration": 2728,
74
"service": 300,
75
"waiting_time": 0,
76
"location": [34.06892275, -118.29156827],
77
"location_index": 5,
78
"id": 1,
79
"load": [3],
80
"distance": 38067
81
},
82
{
83
"type": "job",
84
"arrival": 1688128555,
85
"duration": 3686,
86
"service": 300,
87
"waiting_time": 0,
88
"location": [34.01103011, -118.19238067],
89
"location_index": 6,
90
"id": 18,
91
"load": [2],
92
"distance": 52640
93
},
94
{
95
"type": "job",
96
"arrival": 1688129778,
97
"duration": 4609,
98
"service": 300,
99
"waiting_time": 0,
100
"location": [34.08659806, -118.17526366],
101
"location_index": 7,
102
"id": 28,
103
"load": [1],
104
"distance": 67654
105
},
106
{
107
"type": "end",
108
"arrival": 1688130860,
109
"duration": 5391,
110
"service": 0,
111
"waiting_time": 0,
112
"location": [34.06624918, -118.11066669],
113
"location_index": 8,
114
"load": [1],
115
"distance": 78857
116
}
117
],
118
"service": 1800,
119
"duration": 5391,
120
"waiting_time": 1696,
121
"priority": 200,
122
"delivery": [8],
123
"pickup": [6],
124
"distance": 78857,
125
"geometry": "aq|nEnn{oUF??aB?uC?s@AeA?w@?OA{@m@@Y?K?W?kA?a@@I?Y?a@?M?w@?I?A?K?I?_@?Y?a@@O@M@YBK?QMkAA_@?M?c@A]?S?M?K?O?U?iB?eA?e@@M?M?U?MAK@S?O?K?kCBm@KICIIEICIAK?IBIBIDEFCFCJEl@?j@?ZAL@HDHDDFBHDLBf@BH?H?J?J?F@f@@`@Bj@@D?DR~B@nCFlNBzMDlJ?~@BlHBxE?bB?f@@tC@|A?n@?J@fA?pA?V?Z@x@@dA?l@?`@@bA@`E?`@BnL@V@pB?~@@t@?F?t@?tA?lA@rA?rB@fD?jABnD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CQASAUA[Cc@A}@?kAAiDCiC?eCCaF?{@AyAAcD?W?I@]AmAAoEAuAAk@AcB?y@?i@?iAAw@?W?s@AsDAcA?e@?OAy@AwIA}CCcE?]CwH?gACsI?e@CaB?_A?sAA}B?I?MAuBAm@?wA?yB?SCaC?i@?i@CcH?{@AkA?qA?]Aa@?e@AsBAmB?sA?_AA{AAsA?kBAiA?u@AcB?cAC{H?_@?U?UHu@H_A@_A@E?KD[BKDGFGHEJCP?b@?`AARAFAJEHGHKL[HMFIJEPGJ@N?L?z@@t@?h@?PIJ?XCLANA`@AX?^?H?J?@?H?v@?L?`@?X?H?`@AjA?V?J?X?l@A@z@?N?v@@dA?r@?tC?`BG?"
126
},
127
{
128
"vehicle": 2,
129
"cost": 1383,
130
"steps": [
131
{
132
"type": "start",
133
"arrival": 1688111823,
134
"duration": 0,
135
"service": 0,
136
"waiting_time": 0,
137
"location": [34.0522137, -118.28427087],
138
"location_index": 9,
139
"load": [0],
140
"distance": 0
141
},
142
{
143
"type": "job",
144
"arrival": 1688112000,
145
"duration": 177,
146
"service": 300,
147
"waiting_time": 0,
148
"location": [34.0426885, -118.28191077],
149
"location_index": 1,
150
"id": 9,
151
"load": [1],
152
"distance": 1177
153
},
154
{
155
"type": "job",
156
"arrival": 1688112986,
157
"duration": 863,
158
"service": 300,
159
"waiting_time": 0,
160
"location": [34.06675919, -118.30620984],
161
"location_index": 0,
162
"id": 8,
163
"load": [2],
164
"distance": 6005
165
},
166
{
167
"type": "end",
168
"arrival": 1688113806,
169
"duration": 1383,
170
"service": 0,
171
"waiting_time": 0,
172
"location": [34.0522137, -118.28427087],
173
"location_index": 9,
174
"load": [2],
175
"distance": 9687
176
}
177
],
178
"service": 600,
179
"duration": 1383,
180
"waiting_time": 0,
181
"priority": 0,
182
"delivery": [0],
183
"pickup": [2],
184
"distance": 9687,
185
"geometry": "kyynEfk}pUD?d@AR?ZAN@\\?V?N?V?pAArCAN?d@AvA?l@?hFCh@@L?h@Bb@D\\@L@XBB?F?R?\\At@?t@?L?nAA|@CVAh@Cd@?f@AR?~AAl@ABONk@HWJ]HU^cAPi@Z{@HWp@iBL@B@@@AACAMAq@hBIV[z@Qh@_@bAITK\\IVOj@CNMx@CRE\\_@bCE^U`BCRAFAJAH?J?LAR?LAL?N?B?V@~F@rA?b@?`@?`A?bA?nD?bB?j@@L?V?p@i@?g@?Y?w@?_@?cA@g@?eB?O?s@?W?M?m@?m@?m@?e@?[@cE?[@]A]?yE?i@?q@?W?m@?q@?gA?g@?Y?K?aA?O?Q?s@AQ@M?I?Q@G?{@?aB?G?MLY?q@@Y?SAUCO?MA]@K?]?[?O?K?W?YIAJCTAV?@?t@?N?xB?bC@dB?N@~B?rA?f@@bF?xE?xEAxE@zE@vE@xE?zEoH?w@?mA?gI?g@?}@?C?y@?}A?O?U?K?cA?I?EAIAICGAIAW?c@?c@?u@?K?Q?_@?}B?kD@}D??vF@`C@tB{G@zGAdD@rAAj@?bAAz@@b@?d@?H?nCEl@?H?R@B@D?D@F?H@j@?dIAlECR?v@?l@?hA@AyF?g@@aEA}D?[?eCAsA?c@?i@?wA?s@Am@?mD?i@?yA?uAAw@?gA?wA?qB?_A?g@?gA?Y?a@?aBAuA?c@?U?_A?k@AqA?kB?{@@yBAq@?C?O@y@@y@?u@@kA?Q?G@[?q@?sA?_@?[AgA?c@?q@?c@?a@?Q?g@?GAe@@[?SA]?e@?U?m@?i@?mAAi@?]?w@?Q?aA?Y@q@?S?_@?O@u@|A?d@?j@BdA?X@x@?T?N@t@Ap@?ZAV?J?P?H?R?Z?lDCdAAfA?V?`@?~@AH?L?V?"
186
}
187
]
188
},
189
"status": "Ok",
190
"message": ""
191
}

Following is a visual representation of the optimized solution on a map. We can see that the solution suggested by optimizer has 2 routes to cover all the jobs and shipments. Vehicle 1 starts from its start points and covers the location of all jobs within the prescribed time windows for each job. It also takes care of the shipment between completing the jobs as the skills required for shipment are possessed by only this vehicle in the given scenario. Whereas, vehicle 2 is assigned to only 2 jobs which are located near its starting point. We also get the summary of the overall solution as well as for each of the routes. We can see the overall waiting time is around 30 mins for vehicle 1 which was caused when it was waiting for the delivery time_window of the shipment to start. We also get the route-wise as well as overall cost of the optimized solution.

documentation image

Object Overview

Location Object

Locations object - locations - is used to describe locations that will be used for route optimization. A maximum of 2k locations can be added to this object.

IndexLocation
051.388997,-0.119022
151.391915,-0.103666
251.369777,-0.10438
351.365014,-0.105654
451.351818,-0.014773

With respect to the example above, if in the "vehicles" property, the start_index parameter is set to 2, then 51.369777,-0.10438 would be considered as the starting coordinates for that vehicle.

Job Object

jobs object describes a particular job or a task that needs to be completed as part of the overall optimization process. It contains various properties of a job such as the job id, the index of the location where the job needs to be performed, the service duration, multidimensional quantities for pickup and delivery, available time windows, mandatory skills required, the priority of the job, and a description of the job.

Properties of a jobs object provide important information to the optimization algorithm, such as time constraints and resource requirements for each job, which helps generate an optimized route plan. It is important to note here that all delivery-related amounts for jobs are loaded at vehicle start, while all pickup-related amounts for jobs are brought back to the last stop of the vehicle. Therefore, the vehicles should have appropriate capacity to handle job pickup and deliveries accordingly.

Vehicle Object

The Vehicle 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:

  1. The users can also 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.

  2. In order to request a round trip, you can specify both the start_index and end_index with the same location index.

  3. capacity parameter describes the maximum multidimensional quantities a vehicle can carry.

Relations Object

relations object is used to configure relationships between jobs and shipments that should be honored in the optimized solution. With this object users can customize the algorithm to emulate real-world constraints like control the sequence of certain jobs/shipments in the solution or ensure certain jobs/shipments are covered on the same route. It allows you to specify various types of relations and their corresponding constraints for the steps. However when using the relations object, please be mindful of the following considerations:

  • time_windows constraints in jobs and shipments might be violated for the steps mentioned in the relations object.

  • Soft constraints parameters like max_vehicle_overtime and max_visit_lateness will not be available in input requests when the relations object is used.

  • Hard constraint of max_activity_waiting time is effective only with in_same_route type of relation. It is not effective for other relation types.

  • If certain relations require multiple steps (e.g., jobs) to be on the same route, the vehicle assigned to that route must have enough capacity and the required skills to serve all the jobs on the route. The optimization service would return an error, otherwise.

  • If a relations input requires a delivery step to occur before a pickup step for a shipment, an error message is returned, as it violates the shipment's logical order.

  • For shipments, both the pickup and delivery steps should exist within the same relations. An error message is reported if a relations contains only one shipment step.

Sample Relations Object

1
{
2
"relations": [
3
{
4
"type": "in_direct_sequence",
5
"steps": [
6
{
7
"type": "start"
8
},
9
{
10
"type": "pickup",
11
"id": 25
12
},
13
{
14
"type": "job",
15
"id": 3
16
},
17
{
18
"type": "delivery",
19
"id": 25
20
},
21
{
22
"type": "end"
23
}
24
],
25
"vehicle": 1
26
}
27
]
28
}

Custom Cost Matrix

This feature enables the optimization algorithm to consider a user-defined cost of traveling between different locations. Users can set the travel_cost parameter of objective property to customized to ensure that the algorithm considers the custom cost values for each traveling between locations.

To utilize the "cost_matrix" object, you need to provide a 2D array with 'n' rows and 'n' columns where n represents the total number of locations. Each element of the array represents the cost of traveling from one location to another. The optimization algorithm would prefer the routes with lower relative costs over the routes with higher relative costs. Therefore, the custom cost matrix can be used to influence the optimized route that the algorithm returns. For example, if you have three locations (A, B, C), the cost_matrix would be a 3x3 array:

1
`cost_matrix`: [
2
[0, 10, 5],
3
[10, 0, 8],
4
[5, 8, 0]
5
]

In this example, the first row represents the cost of traveling from location A to location A,A to B & A to C, the second row represents the cost of traveling to different locations starting from point B to A and so on. Subsequently, for the given example, the cost of traveling from location A to B is 10, from A to C is 5, from B to A is 10, from B to C is 8, and so on.

Few points to consider regarding the use of cost_matrix :

  • The cost values should always be non-negative integers.
  • The cost values do not have any unit. Users can consider the cost of traveling from one location to another as abstract but relative weights.
  • Please ensure to match the index between locations and cost_matrix objects. This means that the costs associated with coordinates at index i in locations object should be added in a row at index i in the cost_matrix object as well.
  • Using custom costs for a subset of total locations is not allowed. Either it should be used for all locations or not used at all. To ignore a particular location and prevent it from being included in the optimization, you can assign a very large value to the corresponding row and column in the cost_matrix. This ensures that the optimizer avoids that location in the routing solution.
  • When the travel_cost is set to customized, the optimization algorithm takes the customized cost matrix into account when calculating the overall cost of a route.
  • max_travel_cost feature allows you to set a maximum travel cost for a route. When a customized cost matrix is used in the optimization request, the total cost of a route is calculated based on the values provided in the customized cost matrix. The max_travel_cost feature ensures that the calculated cost of a route does not exceed a specified value. By combining the customization of the cost_matrix and the max_travel_cost feature, you can optimize routes based on your desired cost factors while also ensuring that the routes remain within specific cost constraints.

Sample Cost Matrix Object

1
{
2
"cost_matrix": [
3
[
4
0,
5
4,
6
22,
7
9999
8
],
9
[
10
4,
11
0,
12
12,
13
33
14
],
15
[
16
22,
17
12,
18
0,
19
45
20
],
21
[
22
9999,
23
33,
24
45,
25
0
26
]
27
]
28
}

Metadata Attribute

The metadata property, as the name suggests, can be used to provide any additional details about the entity that it is being attached to. Route Optimization API allows users to add metadata to vehicles, jobs and shipments. The contents of the metadata attribute always need to follow the “key : value” format. The contents of this attribute do not affect the optimization in any way and are passed through to the solution as is.

This metadata can be used to display additional information, say on an application or a dashboard, about the entities involved in a route optimization problem. A good example is the NextBillion.ai’s Route Planner. User’s can add custom metadata details to their vehicles, jobs & shipments when generating route plans using the Route Planner and then dispatch the routes to an external telematics provider with rich custom details about the route plan like - driver name, vehicle license number, contact details of the drivers or instructions for completing a particular task. The telematics provider then displays these details along with the route on a dashboard for operations manager or shares them directly to the driver, as needed, ensuring managers or drivers have all the details for executing the suggested route plans.

Following is a sample metadata attribute that can be attached to a delivery task

1
{
2
"metadata": {
3
"name": "John",
4
"address": "1234, Elm Street, Los Angeles, CA 90001",
5
"notes": "Drop the package at the door",
6
}
7
}

Multi-Dimensional Parameters

Capacity

The Capacity parameter in Vehicle Object is used to describe multidimensional quantities of capacity. In this context, multi-dimension refers to the fact that a single vehicle can carry loads defined in different units. For example, a vehicle may have a capacity of 10 cubic meters for volume, 1000 kg for weight, and 6 pallets for a number of items. These are three different dimensions of capacity, and each has its own value. By specifying Capacity as an array of integers, we can provide values for each dimension of capacity that a vehicle possesses. This information is then used by the optimization algorithm to ensure that the total capacity required by all shipments assigned to a vehicle does not exceed its capacity in any of the dimensions.

Example: Let's say a construction company has a fleet of trucks that are used to transport multiple things, such as bricks, cement, and even construction workers. Each truck has a different capacity for weight, volume, and number of persons it can carry.

In this case, the capacity parameter can be used to describe the multidimensional quantities for each truck. For example, a truck may have a capacity of 100 kg weight, 10 cubic meters of volume, and can carry 5 construction workers. The capacity parameter can be defined as [100, 10, 5] to represent these values respectively.

By leveraging the capacity in multiple dimensions, the solver can optimize job/shipment assignment to appropriate vehicles ensuring better customer service and efficient transportation.

Amount

Amount parameter in Shipment Object is used to describe multidimensional quantities of a shipment. The term "multi-dimensional" refers to the fact that a single shipment can have amounts defined in different units. Continuing with our example of the construction company above, let’s say a truck needs to pick up 50 kg of bricks, and 2 cubic meters of cement from a construction material supplier’s location. When defining the shipment we define this input as

1
“amount”: [50,2,0]

0 for the construction worker dimension. Next, if we have another stop to pick up 3 construction worker, then we can define the amount as

1
“amount”: [0,0,3]

If the other parameters, like distance, time_windows, location of other trucks etc. are favorable then these 2 pickups can be assigned to the same vehicle with “capacity”: [100,10,5] like in this example.

Amount parameter is useful for optimizing delivery routes and determining the most efficient way to transport goods based on multiple dimensions of quantity.

Skills

Skills parameter in the Vehicles Object describes the skills that a driver or vehicle possesses in different units. The term "multi-dimension" refers to the fact that a single driver or vehicle may have different skills or abilities, each of which could be measured in different units or quantities.

For example, let's say we have a fleet of delivery vehicles. One of these vehicles may have the following skills:

  • Skill ID ‘101’: Capacity to carry 10 large boxes
  • Skill ID ‘102’: Ability to transport goods at a temperature of -10 degrees Celsius
  • Skill ID ‘103’: Ability to transport hazardous materials in a specific type of container

In this case, the Skills parameter would be set as an array of integers, with each element corresponding to a particular skill or ability. For instance, the skills parameter for the vehicle described above might be set as follows:

1
"skills": [101, 102, 103]

Here, the first element (101) corresponds to the vehicle's capacity to carry 10 large boxes, the second element (102) corresponds to its ability to transport goods at a temperature of -10 degrees Celsius, and the third element (103) corresponds to its ability to transport hazardous materials in a specific type of container.

By including skills attribute in the optimization API, users can optimize their delivery routes based on specific skills and abilities of their drivers and vehicles, helping to ensure that each delivery is made efficiently and safely.

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 for vehicle v if j.skills is included 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 need (i.e. without skills as well).

  • a job with multiple skills will be assigned to vehicles matching all the skills. The job will not be assigned to vehicles with partially matching skills.

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

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 4000 locations can be added to the locations object

  • A maximum of 4000 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
200

Normal success case.

Normal success case.

400

Input validation failed.

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

401

APIKEY not supplied or invalid.

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

403

APIKEY 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.

404

Requested host/path not found.

This error occurs when a malformed hostname is used.

413

Request entity too large

This error is caused when the length of input request URI or the request body is too large. Please modify the request. Reach out to [email protected] if the issue still persists.

422

Could not process the request.

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

429

Too many requests.

QPM reached or API request count quota reached.

500

Internal Service error.

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

© 2024 NextBillion.ai all rights reserved.