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 "jobs": "[...]"
3}

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 "vehicles": "[...]"
3}

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}

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>' --header 'Content-Type: application/json' --data '{...}'

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:

1curl --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 }

Following is a visual representation of the initial locations of tasks, vehicles and the routes suggested after optimization as per the given constraints.

docs-image

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!