Routing Profiles

Managing a fleet with a variety of vehicle types—such as cars, trucks, and minivans—often requires separate route planning requests for each vehicle type, leading to unnecessary complexity and inefficiency. NextBillion.ai Route Optimization allows users to define multiple Routing Profiles to plan routes for mixed vehicle fleets in a single request.

This tutorial will guide you through how to set up and configure routing profiles, where you can define unique routing constraints and preferences for each vehicle type, including travel mode, departure time and more. Each vehicle can be tagged to a profile, enabling seamless, optimized route planning for an entire fleet with varied vehicle types, saving time and improving operational efficiency in the process.

Setup

We have a total of 10 delivery jobs to be fulfilled by a fleet of mixed vehicle types. The fleet has 2 types of vehicles in it - minivans and cars. For each of the vehicle profiles, we will define its routing characteristics and then use them when defining actual vehicles. Let’s start with configuring the locations, delivery jobs with their revenues, and the vehicles 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": {
2
"id": 1,
3
"location": [
4
"34.02410429,-118.25503086",
5
"34.04118314,-118.24377960",
6
"34.05248264,-118.25345384",
7
"34.04890945,-118.25881547",
8
"34.04456349,-118.26277841",
9
"34.03674018,-118.25811613",
10
"34.03374589,-118.25333728",
11
"34.02947273,-118.24628531",
12
"34.04736425,-118.23375569",
13
"34.04077071,-118.26444905",
14
"34.04523018,-118.24971985"
15
16
]
17
}

Jobs

Next, we define the 10 delivery jobs in our problem statement. For each of these tasks, we add:

  • A unique identifier
  • Location index
  • Delivery quantities
  • A service time

Following is the JSON we use in this example:

1
"jobs": "[..]"

Routing Profiles

Next we set up the routing profiles for all types of vehicles in the fleet. As per our problem statement, we have to define 2 types of profiles - “car” and “minivan”.

The “car” type profile has a travel mode of car and needs to avoid highways. Whereas, the “minivan” type profile is of truck type and has specific weight and size dimensions. The “minivan” also needs to avoid tolls and should not make any left turns.

Following is the JSON script to configure these routing profiles:

1
"options": {
2
"routing": {
3
"mode":"car",
4
"traffic_timestamp":1724679300,
5
"profiles": {
6
"car": {
7
"mode": "car",
8
"avoid": [
9
"highway"
10
]
11
},
12
"minivan": {
13
"mode": "truck",
14
"truck_weight": 10000,
15
"truck_size": "200,210,400",
16
"avoid": [
17
"toll",
18
"left_turn"
19
]
20
}
21
}
22
}
23
}

Do observe that we have defined routing.mode = car and routing.traffic_timestamp = 1724679300 outside profiles attribute. These routing properties apply to vehicles with default profiles i.e. vehicles which do not belong to any defined route profiles. Check the next section, to know how we define vehicles with default profiles.

Vehicles

Now we configure each of the vehicles in the fleet and tag them to a routing profile defined earlier. To configure the van properties, we specify:

  • A unique ID
  • start_index & end_index to indicate the starting and ending locations of the route
  • capacity indicating the storage capacity of the vehicle
  • profile to tag the vehicle to the routing profile defined in the previous step

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

1
"vehicles": "[..]"

Notice that for “Vehicle_4_default”, we haven’t specified any profiles. This vehicle is automatically assigned to the “default” profile and is subject to default routing properties. The default routing properties are defined as part of options.routing attribute and not as part of any profiles.

Optimization POST Request

When all the above components are put together we get the final POST request that we will submit to the optimizer.

1
curl --location 'https://api.nextbillion.io/optimization/v2?key=<your_api_key>'
2
--header 'Content-Type: application/json'
3
--data '{...}'

Optimization POST Response

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

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

Optimization GET Request

We use the request ID and retrieve the result through the Optimization GET request. Following is the GET request:

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

Optimization GET Response

Following is the optimized route plan:

1
{
2
"description": "Multiple Routing Profiles",
3
"result": '{...}'
4
}

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

Sample route plan for multiple vehicle profiles

Caption: Route Plan for different routing profiles

Analyzing the Solution

Looking at the result we can observe that:

  • All 3 vehicles were used to fulfill all the tasks.
  • One “car” type and a “default” type vehicle was used for 2 deliveries each, while the “minivan” type vehicle was used for remaining 6 deliveries.
  • We can see the “minivan” takes a route (blue route in the image representation) which always avoids left turns as defined by its routing profile.
  • The solution also returns the details of all the profiles - namely “car”, “minivan” and “default” - used while generating the solution.

The above example exhibits how NextBillion.ai’s Route Optimization API allows making use of multiple routing profiles to generate most efficient routes for a fleet with a variety of vehicle types. We encourage you to go ahead and try out different configurations of profiles, number of tasks / vehicles and explore how the solution changes under different scenarios presented to Route Optimization 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.