Vehicle costs
In this example, we learn about the vehicle cost attributes. NextBillion.ai’s Route Optimization V2 currently provides two types of vehicle costs - fixed
and per_hour
costs.
Fixed costs are the cost of using the vehicle irrespective of how long the vehicle remains in use. Driver fee, license fee, taxes etc can be thought of as fixed costs. If only the fixed cost of the vehicle is provided then it will be added to the travel_cost
of the route.
per_hour
on the other hand, is a way to factor the hourly cost of operating a vehicle in the optimization calculations. If the vehicle per_hour
cost is provided, the optimizer will only consider the vehicle cost (either only per_hour
or a sum of fixed
& per_hour
if fixed
cost is also provided) as the total cost of the route. The route with lower costs is preferred over other routes, in general, given other constraints like - time_windows, skills, location of the tasks, vehicles etc.
Get Started
Readers would need a valid NextBillion API key to try this example out. If you don’t have one, please contact us to get your API key now!
Setup
Once you have a valid API Key, you can start setting up the components to be used in this example. Let’s take a look at them below.
Jobs & Shipments
We start by defining 3 jobs and 2 shipments. For these tasks we add:
-
A unique identifier for each task
-
Location indexes for each task
-
Specify the schedule of tasks. This is done by adding time windows within which a task must be completed. We have added a 15 min time window for all tasks for the sake of simplicity, but Route Optimization V2 is absolutely capable of handling tight task schedules equally well.
-
Skills needed to perform each task
The actual time taken to complete the tasks once the driver/vehicle is at the task’s location i.e. the service time for each task.
Let’s take a look at the jobs
JSON after the above properties are configured:
1{
2 "jobs": [
3 {
4 "id": 1,
5 "location_index": 0,
6 "service": 300,
7 "skills": [
8 1
9 ],
10 "pickup": [
11 0
12 ],
13 "time_windows": [
14 [
15 1693398600,
16 1693399500
17 ]
18 ]
19 },
20 {
21 "id": 2,
22 "location_index": 1,
23 "service": 180,
24 "skills": [
25 1
26 ],
27 "pickup": [
28 0
29 ],
30 "time_windows": [
31 [
32 1693401300,
33 1693402200
34 ]
35 ]
36 },
37 {
38 "id": 3,
39 "location_index": 2,
40 "service": 300,
41 "pickup": [
42 0
43 ],
44 "skills": [
45 2
46 ],
47 "time_windows": [
48 [
49 1693408500,
50 1693409400
51 ]
52 ]
53 }
54 ],
55 "shipments": [
56 {
57 "pickup": {
58 "description": "Shipment Pickup 1",
59 "id": 1,
60 "location_index": 3,
61 "service": 120,
62 "time_windows": [
63 [
64 1693404000,
65 1693404900
66 ]
67 ]
68 },
69 "delivery": {
70 "description": "Shipment Delivery 1",
71 "id": 1,
72 "location_index": 4,
73 "service": 120,
74 "time_windows": [
75 [
76 1693405800,
77 1693406700
78 ]
79 ]
80 },
81 "skills": [
82 2
83 ],
84 "amount": [
85 2
86 ]
87 },
88 {
89 "pickup": {
90 "description": "Shipment Pickup 2",
91 "id": 2,
92 "location_index": 5,
93 "service": 120,
94 "time_windows": [
95 [
96 1693407600,
97 1693408500
98 ]
99 ]
100 },
101 "delivery": {
102 "description": "Shipment Delivery 2",
103 "id": 2,
104 "location_index": 6,
105 "service": 120,
106 "time_windows": [
107 [
108 1693409400,
109 1693410300
110 ]
111 ]
112 },
113 "skills": [
114 3
115 ],
116 "amount": [
117 2
118 ]
119 }
120 ]
121}
Vehicles
Next, we add 4 vehicles that are going to fulfill the tasks within the defined constraints. To describe the vehicles and their properties we add:
-
A unique ID for each vehicle
-
Vehicle shift time or the time window
-
Capacity to denote the amount of load that the vehicle can take
-
Start_index to denote the point from where the vehicle would start.
-
Skills of the driver or the vehicle
-
In order to demonstrate all combinations of vehicle costs, let’s add only
fixed
cost for vehicle 2, onlyper_hour
cost for vehicle 3, both types of costs for vehicle 1, and a high fixed cost for vehicle 4.
Once the vehicle and their properties are defined, the resulting vehicles
JSON is:
1{
2 "vehicles": [
3 {
4 "id": 1,
5 "start_index": 7,
6 "skills": [
7 1
8 ],
9 "capacity": [
10 10
11 ],
12 "costs": {
13 "fixed": 1000,
14 "per_hour": 1000
15 },
16 "time_window": [
17 1693396800,
18 1693404000
19 ]
20 },
21 {
22 "id": 2,
23 "start_index": 8,
24 "skills": [
25 2
26 ],
27 "capacity": [
28 10
29 ],
30 "costs": {
31 "fixed": 1000
32 },
33 "time_window": [
34 1693402200,
35 1693411200
36 ]
37 },
38 {
39 "id": 3,
40 "start_index": 9,
41 "skills": [
42 3
43 ],
44 "capacity": [
45 10
46 ],
47 "costs": {
48 "per_hour": 1000
49 },
50 "time_window": [
51 1693405800,
52 1693411200
53 ]
54 },
55 {
56 "id": 4,
57 "start_index": 10,
58 "skills": [
59 2
60 ],
61 "capacity": [
62 10
63 ],
64 "costs": {
65 "fixed": 5000
66 },
67 "time_window": [
68 1693402200,
69 1693413000
70 ]
71 }
72 ]
73}
Locations
And now, lastly we would define the locations
object and add all the locations used in the problem along with a valid id
. The locations
object with all the points used in this example:
1{
2 "locations": {
3 "id": 1,
4 "location": [
5 "34.083950,-118.318640",
6 "34.076350,-118.338519",
7 "34.000895,-118.204929",
8 "34.018780,-118.317919",
9 "33.996658,-118.261708",
10 "33.916595,-118.240132",
11 "33.946275,-118.385486",
12 "34.057106,-118.361326",
13 "34.016137,-118.253523",
14 "33.940407,-118.265196",
15 "33.98951774,-118.28330959"
16 ]
17 }
18}
Optimization POST Request
Bringing all these components together to create the final POST request that we will submit to the optimizer.
1curl --location 'https://api.nextbillion.io/optimization/v2?key=<your_api_key>' \
2--header 'Content-Type: application/json' \
3--data '{
4 "description": "Vehicle Cost Example",
5 "jobs": [
6 {
7 "id": 1,
8 "location_index":0,
9 "service": 300,
10 "skills": [1],
11 "pickup":[0],
12 "time_windows": [
13 [
14 1693398600,
15 1693399500
16 ]
17 ]
18 },
19 {
20 "id": 2,
21 "location_index": 1,
22 "service": 180,
23 "skills": [1],
24 "pickup":[0],
25 "time_windows": [
26 [
27 1693401300,
28 1693402200
29 ]
30 ]
31 },
32 {
33 "id": 3,
34 "location_index": 2,
35 "service": 300,
36 "pickup":[0],
37 "skills": [2],
38 "time_windows": [
39 [
40 1693408500,
41 1693409400
42 ]
43 ]
44 }
45 ],
46 "shipments": [
47 {
48 "pickup":{
49 "description": "Shipment Pickup 1",
50 "id":1,
51 "location_index":3,
52 "service":120,
53 "time_windows":[[1693404000,1693404900]]
54 },
55 "delivery":{
56 "description": "Shipment Delivery 1",
57 "id":1,
58 "location_index":4,
59 "service":120,
60 "time_windows":[[1693405800,1693406700]]
61 },
62 "skills":[2],
63 "amount":[2]
64 },
65 {
66 "pickup":{
67 "description": "Shipment Pickup 2",
68 "id":2,
69 "location_index":5,
70 "service":120,
71 "time_windows":[[1693407600,1693408500]]
72 },
73 "delivery":{
74 "description": "Shipment Delivery 2",
75 "id":2,
76 "location_index":6,
77 "service":120,
78 "time_windows":[[1693409400,1693410300]]
79 },
80 "skills":[3],
81 "amount":[2]
82 }
83 ],
84 "vehicles": [
85 {
86 "id": 1,
87 "start_index": 7,
88 "skills":[1],
89 "capacity":[10],
90 "costs":{
91 "fixed":1000,
92 "per_hour":1000
93 },
94 "time_window": [
95 1693396800,
96 1693404000
97 ]
98
99 },
100 {
101 "id": 2,
102 "start_index": 8,
103 "skills": [2],
104 "capacity":[10],
105 "costs":{
106 "fixed":1000
107 },
108 "time_window": [
109 1693402200,
110 1693411200
111 ]
112 },
113 {
114 "id": 3,
115 "start_index": 9,
116 "skills": [3],
117 "capacity":[10],
118 "costs":{
119 "per_hour":1000
120 },
121 "time_window": [
122 1693405800,
123 1693411200
124 ]
125 },
126 {
127 "id": 4,
128 "start_index": 10,
129 "skills": [2],
130 "capacity":[10],
131 "costs":{
132 "fixed":5000
133 },
134 "time_window": [
135 1693402200,
136 1693413000
137 ]
138 }
139 ],
140 "locations":
141 {
142 "id": 1,
143 "location": ["34.083950,-118.318640","34.076350,-118.338519","34.000895,-118.204929","34.018780,-118.317919","33.996658,-118.261708","33.916595,-118.240132","33.946275,-118.385486","34.057106,-118.361326","34.016137,-118.253523","33.940407,-118.265196","33.98951774,-118.28330959"]
144 }
145}
146'
Optimization POST Response
Once the request is made, we get a unique ID in the API response:
1{
2"id": "e4bbf6a9b4f95edcc8c95447460f6356",
3"message": "Optimization job created",
4"status": "Ok"
5}
Optimization GET Request
We take the ID and use the Optimization GET request to retrieve the result. Here is the GET request:
curl --location 'https://api.nextbillion.io/optimization/v2/result?id=e4bbf6a9b4f95edcc8c95447460f6356&key=<your_api_key>'
Optimization GET Response
Following is the optimized route plan:
1{
2 "description": "Vehicle Cost Example",
3 "result": {
4 "code": 0,
5 "summary": {
6 "cost": 5067,
7 "routes": 3,
8 "unassigned": 0,
9 "setup": 0,
10 "service": 1260,
11 "duration": 4934,
12 "waiting_time": 2945,
13 "priority": 0,
14 "delivery": [
15 4
16 ],
17 "pickup": [
18 4
19 ],
20 "distance": 61393.600000000006
21 },
22 "routes": [
23 {
24 "vehicle": 3,
25 "cost": 418,
26 "steps": [
27 {
28 "type": "start",
29 "arrival": 1693407772,
30 "duration": 0,
31 "setup": 0,
32 "service": 0,
33 "waiting_time": 0,
34 "location": [
35 33.940407,
36 -118.265196
37 ],
38 "location_index": 9,
39 "load": [
40 0
41 ]
42 },
43 {
44 "type": "pickup",
45 "arrival": 1693408235,
46 "duration": 463,
47 "setup": 0,
48 "service": 120,
49 "waiting_time": 0,
50 "location": [
51 33.916595,
52 -118.240132
53 ],
54 "location_index": 5,
55 "id": 2,
56 "load": [
57 2
58 ],
59 "description": "Shipment Pickup 2"
60 },
61 {
62 "type": "delivery",
63 "arrival": 1693409400,
64 "duration": 1508,
65 "setup": 0,
66 "service": 120,
67 "waiting_time": 0,
68 "location": [
69 33.946275,
70 -118.385486
71 ],
72 "location_index": 6,
73 "id": 2,
74 "load": [
75 0
76 ],
77 "description": "Shipment Delivery 2"
78 },
79 {
80 "type": "end",
81 "arrival": 1693409520,
82 "duration": 1508,
83 "setup": 0,
84 "service": 0,
85 "waiting_time": 0,
86 "location": [
87 33.946275,
88 -118.385486
89 ],
90 "location_index": 6,
91 "load": [
92 0
93 ]
94 }
95 ],
96 "setup": 0,
97 "service": 240,
98 "duration": 1508,
99 "waiting_time": 0,
100 "priority": 0,
101 "delivery": [
102 2
103 ],
104 "pickup": [
105 2
106 ],
107 "distance": 22189.5,
108 "geometry": "q~cnEftypUr@?hD@xA?h@?X?PAJ?N?h@?^?dB?X?lA?rA?|C?x@?nB?jA?X?jA@`A@B?zBAbB?`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\?zA?rB?r@?^?jB?fD?P?|B?F?X?T?r@?L@fB?v@c@AgAA?aAz@?BA@A?E@uCc@?Y?C?ABA@@hB??"
109 },
110 {
111 "vehicle": 1,
112 "cost": 1298,
113 "steps": [
114 {
115 "type": "start",
116 "arrival": 1693398736,
117 "duration": 0,
118 "setup": 0,
119 "service": 0,
120 "waiting_time": 0,
121 "location": [
122 34.057106,
123 -118.361326
124 ],
125 "location_index": 7,
126 "load": [
127 0
128 ]
129 },
130 {
131 "type": "job",
132 "arrival": 1693399500,
133 "duration": 764,
134 "setup": 0,
135 "service": 300,
136 "waiting_time": 0,
137 "location": [
138 34.08395,
139 -118.31864
140 ],
141 "location_index": 0,
142 "id": 1,
143 "load": [
144 0
145 ]
146 },
147 {
148 "type": "job",
149 "arrival": 1693400112,
150 "duration": 1076,
151 "setup": 0,
152 "service": 180,
153 "waiting_time": 1188,
154 "location": [
155 34.07635,
156 -118.338519
157 ],
158 "location_index": 1,
159 "id": 2,
160 "load": [
161 0
162 ]
163 },
164 {
165 "type": "end",
166 "arrival": 1693401480,
167 "duration": 1076,
168 "setup": 0,
169 "service": 0,
170 "waiting_time": 0,
171 "location": [
172 34.07635,
173 -118.338519
174 ],
175 "location_index": 1,
176 "load": [
177 0
178 ]
179 }
180 ],
181 "setup": 0,
182 "service": 480,
183 "duration": 1076,
184 "waiting_time": 1188,
185 "priority": 0,
186 "delivery": [
187 0
188 ],
189 "pickup": [
190 0
191 ],
192 "distance": 9876.7,
193 "geometry": "ywznEjmlqUBG@G@GAEEEMIw@[q@WLoA@KB[JmAB_@?U@[?a@?iABiD?u@@c@@aB@iB@g@?S@_ABsF@aB?s@?k@@o@?m@@g@?UBgBB{EDcF@s@@qD@aB@[@gA?y@?]BuB?}@?W@m@?Q?W@{@?]?K@M?kA?Q?U?I@_@BuE@qA@W?c@DcB?u@?y@?M@}BWGwF_B{@WiI}BcCo@WI_@KYIa@MUGOEMCMGIAIAG??S?S?M@U?W@mA@}A@e@?_@?g@@aA@qB@yB@cB@s@?[?M?c@@o@@wA?w@@}@@cA@_B?U?Q?w@BuB@cB?m@?_@@g@?]?cA@a@?sA@iA@kA?Q?U@oA?e@?U?k@QAkA@c@?gA?}@@c@AC?YAWASCSAWEa@EKCi@GyBYWC[CU?W?yH@aC?oB?Y?O?q@@]@c@@E@[?K?i@?o@@cB?mA?}@?u@?g@?[@{G?gD?eC?iB@s@?YAA?I?I?OCKCWEIAa@Iq@KA?OCG?E?Y?M?K?[@c@DE?o@He@Dg@@e@?C?E?u@?S?aC?s@?WAUCmAKq@EwB@c@?yA?gA?O?WAUCOAEAQGOGUKQMUMKGECMEMEOEOCSEUAE?OAOAWA?o@?i@?Y?o@?Q?y@?iBA{A@]?c@?[?u@?m@?W?m@?g@?e@?K?c@?g@?k@?cA?q@?e@?oB?a@?Y?i@AoB?Q?oA?oA?k@?e@?wA?s@_B@A`@@B?@?@?@DDBB@@@B?P?R?N?b@?d@?J?K?e@?c@?O?S?QACAACCEE?A?A?AAC@a@~AA?r@nJCxO?`B?|B?xEAhB??`@?f@?l@?t@?l@?b@?d@?l@@tB?n@?l@?l@@hB?n@?l@?vB?j@A^?T?R?d@?pA?R?bBAf@@T?v@?~@?b@AbC?n@?T?F?F?H@L?DDb@D\\DRDN?BHXJVHVFRJ\\@FH^D`@?B?B@T@L?TENAX?V?LAPCVCVWnC[dDEf@CXCZARAp@?tC@nA?JAN?LA\\DNA~@?nA?^?^AXANANAN?JAJ?N@r@@hA?d@?d@?x@?tC?d@?x@@nA?Z?h@?r@?p@a@???"
194 },
195 {
196 "vehicle": 2,
197 "cost": 3350,
198 "steps": [
199 {
200 "type": "start",
201 "arrival": 1693404153,
202 "duration": 0,
203 "setup": 0,
204 "service": 0,
205 "waiting_time": 0,
206 "location": [
207 34.016137,
208 -118.253523
209 ],
210 "location_index": 8,
211 "load": [
212 0
213 ]
214 },
215 {
216 "type": "pickup",
217 "arrival": 1693404900,
218 "duration": 747,
219 "setup": 0,
220 "service": 120,
221 "waiting_time": 0,
222 "location": [
223 34.01878,
224 -118.317919
225 ],
226 "location_index": 3,
227 "id": 1,
228 "load": [
229 2
230 ],
231 "description": "Shipment Pickup 1"
232 },
233 {
234 "type": "delivery",
235 "arrival": 1693405843,
236 "duration": 1570,
237 "setup": 0,
238 "service": 120,
239 "waiting_time": 0,
240 "location": [
241 33.996658,
242 -118.261708
243 ],
244 "location_index": 4,
245 "id": 1,
246 "load": [
247 0
248 ],
249 "description": "Shipment Delivery 1"
250 },
251 {
252 "type": "job",
253 "arrival": 1693406743,
254 "duration": 2350,
255 "setup": 0,
256 "service": 300,
257 "waiting_time": 1757,
258 "location": [
259 34.000895,
260 -118.204929
261 ],
262 "location_index": 2,
263 "id": 3,
264 "load": [
265 0
266 ]
267 },
268 {
269 "type": "end",
270 "arrival": 1693408800,
271 "duration": 2350,
272 "setup": 0,
273 "service": 0,
274 "waiting_time": 0,
275 "location": [
276 34.000895,
277 -118.204929
278 ],
279 "location_index": 2,
280 "load": [
281 0
282 ]
283 }
284 ],
285 "setup": 0,
286 "service": 540,
287 "duration": 2350,
288 "waiting_time": 1757,
289 "priority": 0,
290 "delivery": [
291 2
292 ],
293 "pickup": [
294 2
295 ],
296 "distance": 29327.4,
297 "geometry": "uwrnEbkwpUSKkBcAoAq@aB_AeAk@a@SsA{@{A{@g@a@a@_@mAeAmAkAmAgAmAiAoAgAsAgAk@hAYl@qCdGiAdCo@i@k@g@WUMMUSSSc@_@a@_@OO_@YiAaASSUQWWm@k@GGIGWU[UQOCCSQKIe@c@_@bAEv@CNKf@Sz@GTMb@Y~@Wx@?@GRO`@O`@Ul@I^]p@Yn@Sb@GVADk@nAq@nBc@tBgBzD_AtBSb@Q`@OZO^KRaAdCUl@e@pAUp@GROd@Md@M`@K^GTGVOj@CJKd@Sx@I`@SdAQv@Ot@S|@Ml@Oj@Kb@K`@St@KXGRITIVMZKXEJIRMZKTGNGNy@dBYn@S`@Ud@MVYn@o@tAO^MV]v@a@|@[v@Q\\g@hACFIPs@zAg@`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?I?qF?e@?OAkA@{@?[?UAQ?cB?S?K?iA?K?S?e@?W?k@?[?e@?q@?M?K?]?g@?u@?[?eA?G?GHW?wB?s@?m@@cA@aA@u@@WG[@GD]Hc@FYDOLc@FSFMHSR_@NW@CZe@RWPQXUBCNKNMTMJILENIJGBATILCBALCNEJCLCHA`@CD?NAL?TAb@?N?J?L@ZAN?n@A^?~@??k@?[?a@A]?g@?eB?e@AgA?Y?oC?SAiH?oB?_@@k@?cAAcA?WAc@?I?]A{@?[AY?M?w@AS?K?k@?SAiA?[A{@?iA?[AoA?c@?EA]?O?g@?w@AS?mA?[AU?i@?_@Ak@?cAAu@?i@?Y?eAA_A?k@CgC?I?SCeE@WAs@?eCAgAAoA?]Ai@?e@?q@mBB[?A?e@ACA?AEaDCuA?K?kCBGHGPAVK??"
298 }
299 ]
300 },
301 "status": "Ok",
302 "message": ""
303}
Following is a visual representation of the initial locations of tasks, vehicles and the routes suggested after optimization as per the given constraints.

Analyzing the Solution
Looking at the result we can observe some interesting insights:
-
summary
section:-
We get an overview of the overall result with a total distance of 61394 meters covered within a total duration of 4934 seconds to complete all the assigned tasks.
-
There are 3 routes with a total cost of 5067. This cost is in seconds as we did not explicitly specify any
travel_cost
, so the solver went with the default setting ofduration
. We can see that one of the vehicles was not used, probably because of its high cost. More details in the next point. -
Other fields in summary provide details about total service time of all the assigned tasks, total waiting_time for the assigned tasks among other details.
-
-
routes
section:-
We can see that vehicle 1 is taking care of job 1 & 2, vehicle 2 is assigned to shipment 1 and job 3, and lastly vehicle 3 is assigned to fulfill shipment 2. This is because of the skills needed to complete those jobs. Take a look at the skills specified for jobs 1, 2 and 3 and that specified for vehicle 1, 2. As an experiment, you can try a variation by removing the skill constraints and check if the task distribution still remains the same or not.
-
As we know from the Basic Route Optimization example that the
cost
value is returned as per thetravel_cost
set in the input request. In our example, the cost is calculated based on theduration
hence all costs in the solution are in seconds. Let’s take a look at the costs for each vehicle:-
Vehicle 1: This vehicle was configured for both
fixed
andper_hour
type of cost. When used, this vehicle incurs a cost of 1000 seconds along with additional 1000 seconds for every hour of operation. The total duration for which this vehicle operates is 1076 seconds (~18 mins) and hence the per_hour cost for this vehicle comes out to be 298 seconds. The total cost of the route, 1298 seconds, is then calculated by adding this value to the fixed cost of using the vehicle. Please note that whenper_hour
cost is usedtravel_cost
of the route is not taken into account for route cost calculations. -
Vehicle 2: This vehicle was configured for only
fixed
cost considerations. When used, this vehicle would incur a fixed cost of 1000 seconds. Looking at the result we conclude that this vehicle operated for a total of 2350 seconds. The fixed cost of the vehicle was added to this value to arrive at the total cost of the route i.e. 3350 seconds. -
Vehicle 3: This vehicle was configured for only
per_hour
cost considerations. On operating for an hour, this vehicle would incur a cost of 1000 seconds. As we can see, the total duration that this vehicle operates for is 1508 seconds (~25 min) and hence the total cost for this vehicle is 418 seconds. Since,per_hour
cost is the only measure of the cost when used, the total cost of the route also becomes 418 seconds. -
Vehicle 4: This vehicle is similar to vehicle 2 in terms of skills, capacity and even shift timings, but has a high fixed cost. We can see that this vehicle was not used because of this reason, even though some task locations were closer to its start location when compared to start location of vehicle 2.
-
-
The total cost of the solution, 5067 seconds, is arrived by adding up the costs of each individual route.
-
As we saw, NextBillion.ai’s Route Optimization V2 understands the cost considerations you provide and suggests the best solution accordingly. We encourage you to go ahead and try out different configurations of vehicle or task locations, time window constraints, skills, number of tasks and explore how different solutions are generated for different scenarios presented to Route Optimization V2 API.
We hope this example was helpful. Check out some more use cases that Route Optimization V2 can handle for you!