Vehicle: Max Distance & Max Travel time

The total distance that a vehicle can drive or the total travel time that a vehicle can operate for, is an important business constraint for many logistics providers as well as fleet owners. NextBillion.ai’s Route Optimization Flexible API offers two independent parameters - max_distance and max_travel_time for each vehicle, to implement similar real-world business limitations easily. These parameters can be leveraged to optimize the usage of vehicles and prevent them against unexpectedly high operating costs, potential breakdowns or just control the fuel consumptions.

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

In this example, we will complete 8 deliveries using 3 vehicles and each of the vehicles will have either one or both distance and travel time limitations. We define the locations, delivery jobs, vehicles and their constraints one by one in the following sections.

Locations

First, we define the locations object and add all the location coordinates used in the problem along with a valid id. The locations object used in this example:

1
"locations":"[...]"

Jobs

Next, we define 8 delivery jobs. For each delivery task we add:

  • A unique identifier
  • Location index
  • Delivery quantity
  • A service time to carry out the delivery Let’s take a look at the jobs JSON after the above properties are configured:
1
"jobs":"[...]"

Vehicles Next, we add 3 vehicles that are going to fulfill the deliveries within the defined constraints of max_travel_time and max_distance. To describe the vehicles and their properties we add:

  • A unique ID for each vehicle
  • capacity indicating the amount of load that the vehicle can take
  • start_index to denote the point from where the vehicle would start.
  • max_distance to limit the total distance that the vehicle can travel
  • max_travel_time to limit the total drive time of the vehicle.

Once the vehicle and their properties are defined, the resulting vehicles JSON is:

1
"vehicles":"[...]"

Optimization POST Request

Now let’s put all these components together and create the final POST request that we will submit to the optimizer.

1
curl --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": "0280ecc2730019b3bb2219ed5dd2ddd8",
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:

1
curl --location 'https://api.nextbillion.io/optimization/v2/result?id=0280ecc2730019b3bb2219ed5dd2ddd8
2
&key=<your_api_key>'

Optimization GET Response

Following is the optimized route plan:

1
{
2
"description": "Vehicle Max Distance & Max Duration Example",
3
"result": "{...}",
4
"status": "Ok",
5
"message": ""
6
}

Following image shows a visual representation of the above route plan.

documentation image

Analyzing the Solution

Looking at the result we can draw following insights:

  • We can see that 6 deliveries were completed and 2 were left unassigned.
  • Only 2 vehicles were used to complete the 6 deliveries.
  • Vehicle 1 covered a total of ~6.8 kms with a total drive time of around 12 minutes. Both these metric are well under 15kms distance and 1 hr of drive time constraints specified.
  • Similarly, Vehicle 3 covered a total distance of ~ 12.5 kms with a total drive time of around 26 minutes, which again is less than the allowed 15 kms of drive distance and 35 mins of drive time.
  • The 2 deliveries which remain unassigned were due to these travel limit constraints as we can see from the “reason” field of unassigned attribute in the response.
  • The locations of these 2 deliveries are too far from the starting point of the unused vehicle 2 and the location of last deliveries that vehicle 1 & 3 make, such that they can not be fulfilled without violating the max_distance constraint.

Above example demonstrates how NextBillion.ai’s Route Optimization Flexible API works within the configured operational constraints of each vehicle and suggests the best solution while honoring those constraints. We encourage you to try out different configurations of vehicle or task locations, number of tasks, and different distance and travel time constraint values to explore how varying solutions are returned under different scenarios presented to Route Optimization Flexible API.

Learn more about the other powerful features and the related use cases that Route Optimization Flexible API can solve for you.

© 2024 NextBillion.ai all rights reserved.