• Optimization
  • Navigation
  • Tracking
  • Maps
  • Places

  • Integrations

Vehicle costs

In this example, we learn about the vehicle cost attributes. NextBillion.ai’s Route Optimization Flexible API 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 Flexible API 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
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
110
111
112
113
114
115
116
117
118
119
120
121
{
  "jobs": [
    {
      "id": 1,
      "location_index": 0,
      "service": 300,
      "skills": [
        1
      ],
      "pickup": [
        0
      ],
      "time_windows": [
        [
          1693398600,
          1693399500
        ]
      ]
    },
    {
      "id": 2,
      "location_index": 1,
      "service": 180,
      "skills": [
        1
      ],
      "pickup": [
        0
      ],
      "time_windows": [
        [
          1693401300,
          1693402200
        ]
      ]
    },
    {
      "id": 3,
      "location_index": 2,
      "service": 300,
      "pickup": [
        0
      ],
      "skills": [
        2
      ],
      "time_windows": [
        [
          1693408500,
          1693409400
        ]
      ]
    }
  ],
  "shipments": [
    {
      "pickup": {
        "description": "Shipment Pickup 1",
        "id": 1,
        "location_index": 3,
        "service": 120,
        "time_windows": [
          [
            1693404000,
            1693404900
          ]
        ]
      },
      "delivery": {
        "description": "Shipment Delivery 1",
        "id": 1,
        "location_index": 4,
        "service": 120,
        "time_windows": [
          [
            1693405800,
            1693406700
          ]
        ]
      },
      "skills": [
        2
      ],
      "amount": [
        2
      ]
    },
    {
      "pickup": {
        "description": "Shipment Pickup 2",
        "id": 2,
        "location_index": 5,
        "service": 120,
        "time_windows": [
          [
            1693407600,
            1693408500
          ]
        ]
      },
      "delivery": {
        "description": "Shipment Delivery 2",
        "id": 2,
        "location_index": 6,
        "service": 120,
        "time_windows": [
          [
            1693409400,
            1693410300
          ]
        ]
      },
      "skills": [
        3
      ],
      "amount": [
        2
      ]
    }
  ]
}

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, only per_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
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
{
  "vehicles": [
    {
      "id": 1,
      "start_index": 7,
      "skills": [
        1
      ],
      "capacity": [
        10
      ],
      "costs": {
        "fixed": 1000,
        "per_hour": 1000
      },
      "time_window": [
        1693396800,
        1693404000
      ]
    },
    {
      "id": 2,
      "start_index": 8,
      "skills": [
        2
      ],
      "capacity": [
        10
      ],
      "costs": {
        "fixed": 1000
      },
      "time_window": [
        1693402200,
        1693411200
      ]
    },
    {
      "id": 3,
      "start_index": 9,
      "skills": [
        3
      ],
      "capacity": [
        10
      ],
      "costs": {
        "per_hour": 1000
      },
      "time_window": [
        1693405800,
        1693411200
      ]
    },
    {
      "id": 4,
      "start_index": 10,
      "skills": [
        2
      ],
      "capacity": [
        10
      ],
      "costs": {
        "fixed": 5000
      },
      "time_window": [
        1693402200,
        1693413000
      ]
    }
  ]
}

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
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  "locations": {
    "id": 1,
    "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"
    ]
  }
}

Optimization POST Request

Bringing all these components together to create the final POST request that we will submit to the optimizer.

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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
curl --location 'https://api.nextbillion.io/optimization/v2?key=<your_api_key>' \
--header 'Content-Type: application/json' \
--data '{
   "description": "Vehicle Cost Example",
   "jobs": [
       {
           "id": 1,
           "location_index":0,
           "service": 300,
           "skills": [1],
           "pickup":[0],
           "time_windows": [
               [
                   1693398600,
                   1693399500
               ]
           ]
       },
       {
           "id": 2,
           "location_index": 1,
           "service": 180,
           "skills": [1],
           "pickup":[0],
           "time_windows": [
               [
                   1693401300,
                   1693402200
               ]
           ]
       },
       {
           "id": 3,
           "location_index": 2,
           "service": 300,
           "pickup":[0],
           "skills": [2],
           "time_windows": [
               [
                   1693408500,
                   1693409400
               ]
           ]
       }
   ],
   "shipments": [
       {
        "pickup":{
           "description": "Shipment Pickup 1",
           "id":1,
           "location_index":3,
           "service":120,
           "time_windows":[[1693404000,1693404900]]
        },
        "delivery":{
           "description": "Shipment Delivery 1",
           "id":1,
           "location_index":4,
           "service":120,
           "time_windows":[[1693405800,1693406700]]
        },
        "skills":[2],
        "amount":[2]
        },
        {
         "pickup":{
           "description": "Shipment Pickup 2",
           "id":2,
           "location_index":5,
           "service":120,
           "time_windows":[[1693407600,1693408500]]
        },
        "delivery":{
           "description": "Shipment Delivery 2",
           "id":2,
           "location_index":6,
           "service":120,
           "time_windows":[[1693409400,1693410300]]
        },
        "skills":[3],
        "amount":[2]
       }
   ],
   "vehicles": [
       {
           "id": 1,
           "start_index": 7,
           "skills":[1],
           "capacity":[10],
           "costs":{
               "fixed":1000,
               "per_hour":1000
            },
           "time_window": [
               1693396800,
                   1693404000
           ]
           
       },
       {
           "id": 2,
           "start_index": 8,
           "skills": [2],
           "capacity":[10],
           "costs":{
               "fixed":1000
            },
           "time_window": [
               1693402200,
            1693411200
           ]
       },
       {
           "id": 3,
           "start_index": 9,
           "skills": [3],
           "capacity":[10],
           "costs":{
               "per_hour":1000
            },
           "time_window": [
               1693405800,
            1693411200
           ]
       },
       {
           "id": 4,
           "start_index": 10,
           "skills": [2],
           "capacity":[10],
           "costs":{
               "fixed":5000
            },
           "time_window": [
               1693402200,
            1693413000
           ]
       }
   ],
    "locations":
        {
            "id": 1,
            "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"]
        }
}
'

Optimization POST Response

Once the request is made, we get a unique ID in the API response:

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

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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
{
  "description": "Vehicle Cost Example",
  "result": {
    "code": 0,
    "summary": {
      "cost": 5067,
      "routes": 3,
      "unassigned": 0,
      "setup": 0,
      "service": 1260,
      "duration": 4934,
      "waiting_time": 2945,
      "priority": 0,
      "delivery": [
        4
      ],
      "pickup": [
        4
      ],
      "distance": 61393.600000000006
    },
    "routes": [
      {
        "vehicle": 3,
        "cost": 418,
        "steps": [
          {
            "type": "start",
            "arrival": 1693407772,
            "duration": 0,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              33.940407,
              -118.265196
            ],
            "location_index": 9,
            "load": [
              0
            ]
          },
          {
            "type": "pickup",
            "arrival": 1693408235,
            "duration": 463,
            "setup": 0,
            "service": 120,
            "waiting_time": 0,
            "location": [
              33.916595,
              -118.240132
            ],
            "location_index": 5,
            "id": 2,
            "load": [
              2
            ],
            "description": "Shipment Pickup 2"
          },
          {
            "type": "delivery",
            "arrival": 1693409400,
            "duration": 1508,
            "setup": 0,
            "service": 120,
            "waiting_time": 0,
            "location": [
              33.946275,
              -118.385486
            ],
            "location_index": 6,
            "id": 2,
            "load": [
              0
            ],
            "description": "Shipment Delivery 2"
          },
          {
            "type": "end",
            "arrival": 1693409520,
            "duration": 1508,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              33.946275,
              -118.385486
            ],
            "location_index": 6,
            "load": [
              0
            ]
          }
        ],
        "setup": 0,
        "service": 240,
        "duration": 1508,
        "waiting_time": 0,
        "priority": 0,
        "delivery": [
          2
        ],
        "pickup": [
          2
        ],
        "distance": 22189.5,
        "geometry": "q~cnEftypUr@?hD@xA?h@?X?PAJ?N?h@?^?dB?X?lA?rA?|C?x@?nB?jA?X?jA@`A@B?zBAbB?`@?ZAf@?b@?R@d@?^?d@?L?@kB?W?k@?c@?w@?y@@mEAiA@cADeF?m@@yA@yE?G?IBO@OBINk@JSJSf@s@~@qAf@q@b@m@d@s@BGDIBG@GDO@M@GD[?M?G@g@@qD?[?W?M?_A?K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398736,
            "duration": 0,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              34.057106,
              -118.361326
            ],
            "location_index": 7,
            "load": [
              0
            ]
          },
          {
            "type": "job",
            "arrival": 1693399500,
            "duration": 764,
            "setup": 0,
            "service": 300,
            "waiting_time": 0,
            "location": [
              34.08395,
              -118.31864
            ],
            "location_index": 0,
            "id": 1,
            "load": [
              0
            ]
          },
          {
            "type": "job",
            "arrival": 1693400112,
            "duration": 1076,
            "setup": 0,
            "service": 180,
            "waiting_time": 1188,
            "location": [
              34.07635,
              -118.338519
            ],
            "location_index": 1,
            "id": 2,
            "load": [
              0
            ]
          },
          {
            "type": "end",
            "arrival": 1693401480,
            "duration": 1076,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              34.07635,
              -118.338519
            ],
            "location_index": 1,
            "load": [
              0
            ]
          }
        ],
        "setup": 0,
        "service": 480,
        "duration": 1076,
        "waiting_time": 1188,
        "priority": 0,
        "delivery": [
          0
        ],
        "pickup": [
          0
        ],
        "distance": 9876.7,
        "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@???"
      },
      {
        "vehicle": 2,
        "cost": 3350,
        "steps": [
          {
            "type": "start",
            "arrival": 1693404153,
            "duration": 0,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              34.016137,
              -118.253523
            ],
            "location_index": 8,
            "load": [
              0
            ]
          },
          {
            "type": "pickup",
            "arrival": 1693404900,
            "duration": 747,
            "setup": 0,
            "service": 120,
            "waiting_time": 0,
            "location": [
              34.01878,
              -118.317919
            ],
            "location_index": 3,
            "id": 1,
            "load": [
              2
            ],
            "description": "Shipment Pickup 1"
          },
          {
            "type": "delivery",
            "arrival": 1693405843,
            "duration": 1570,
            "setup": 0,
            "service": 120,
            "waiting_time": 0,
            "location": [
              33.996658,
              -118.261708
            ],
            "location_index": 4,
            "id": 1,
            "load": [
              0
            ],
            "description": "Shipment Delivery 1"
          },
          {
            "type": "job",
            "arrival": 1693406743,
            "duration": 2350,
            "setup": 0,
            "service": 300,
            "waiting_time": 1757,
            "location": [
              34.000895,
              -118.204929
            ],
            "location_index": 2,
            "id": 3,
            "load": [
              0
            ]
          },
          {
            "type": "end",
            "arrival": 1693408800,
            "duration": 2350,
            "setup": 0,
            "service": 0,
            "waiting_time": 0,
            "location": [
              34.000895,
              -118.204929
            ],
            "location_index": 2,
            "load": [
              0
            ]
          }
        ],
        "setup": 0,
        "service": 540,
        "duration": 2350,
        "waiting_time": 1757,
        "priority": 0,
        "delivery": [
          2
        ],
        "pickup": [
          2
        ],
        "distance": 29327.4,
        "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@`AMVu@xAILS\\e@t@o@`AINc@r@c@p@]j@[h@MRi@`Aw@tAQ`@Q\\Sb@Qb@Ul@M\\Qd@GRGNK`@Oj@CHCHCLEPKf@CLCNCJAJAJ?DCL?FAJCr@?J?j@@^?bB?NBl@Bl@Br@HxALrFBd@DxAFdBDj@@L@XDp@@JJpAFj@Dd@Hn@@JTdBJv@@HBT@JN~@ZxBZlCJp@Fn@@HBZLjADt@Ft@FtADxABvA?x@?lA?pBAH?|@Aj@?~C?~AAv@AlHArAClF?`CEzE?nA?n@?d@?hAAnA?h@AjC?L?z@AjA?dBApB?VA|B?zB?\\C`EA~D?j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ak@?cAAu@?i@?Y?eAA_A?k@CgC?I?SCeE@WAs@?eCAgAAoA?]Ai@?e@?q@mBB[?A?e@ACA?AEaDCuA?K?kCBGHGPAVK??"
      }
    ]
  },
  "status": "Ok",
  "message": ""
}

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 of duration. 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 the travel_cost set in the input request. In our example, the cost is calculated based on the duration 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 and per_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 when per_hour cost is used travel_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 Flexible API 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 Flexible API.

We hope this example was helpful. Check out some more use cases that Route Optimization Flexible API can handle for you!