Custom Objective Equal Task Distribution

Custom Objective is a valuable feature that empowers users to pursue unique objectives which are significantly different from the typical approach of minimizing travel costs. This feature allows users to tune the optimization algorithm to achieve following objectives:

  • Minimize the number of vehicles used in the solution

  • Minimize the time taken to complete all the tasks

  • Distribute tasks equally among all the routes

  • Distribute travel_cost equally among all the routes

The above objectives can be used in conjunction with other constraints of vehicle costs, task time window constraints, re-optimization and other features that are offered by Route Optimization Flexible API.

In this example, we are going to cover the equal task distribution objective. The Custom Objective feature proves highly effective in addressing optimization challenges, especially in business scenarios having a critical need to ensure equal distribution of workload - either in terms of the number of tasks or the travel cost - among all routes. This feature helps in addressing challenges like optimizing resource utilization, better workforce management, better vehicle availability among other benefits.

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 16 jobs. For these jobs we:

Add a unique identifier for each task Provide location indexes for each task Specify the schedule of tasks. This is done by adding time windows within which a task must be completed. Here we have considered the same time window for all tasks for the sake of simplicity, but Route Optimization Flexible API can handle tighter time windows easily. Configure 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 "shipments": "[...]"
4}

Vehicles

Next, we add 2 vehicles that are going to fulfill the tasks. To describe the vehicles and their properties we add: A unique ID for each vehicle

  • Vehicle shift time or the time window

  • Start_index to denote the point from where the vehicle would start.

  • Costs for all vehicles.

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

1{
2 "vehicles": "[...]"
3}

Locations

And lastly, we define the locations object by adding 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}

Now that we have built the fundamental attributes of a request, readers are encouraged to submit a request containing the above components and analyze the solution returned under default settings. Most likely there will be 2 routes returned with 1 route having decidedly more tasks than the other.

Options

Moving forward we incorporate our objective of equal task distribution, into the request by using the objective attribute. We set:

  • type as min-max to indicate that we want to invoke the equal distribution algorithm.

  • value as tasks to indicate that we want to apply the algorithm on the number of tasks metric.

The resulting objective attribute JSON is:

1{
2 "options": {
3 "objective": {
4 "custom": {
5 "type": "min-max",
6 "value": "tasks"
7 }
8 }
9 }
10}

Optimization POST Request

Now let’s put all these components together and 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 successfully submitted, we get a unique ID in the API response:

1{
2"id": "682b0756abb75427be030457db66ee5e",
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=682b0756abb75427be030457db66ee5e
2&key=<your_api_key>'

Optimization GET Response

Following is the optimized route plan:

1{
2 "description": "Custom Objective (task distribution) 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.

Analyzing the Solution

Looking at the result we can see that all the tasks are accommodated on the 2 routes with each vehicle taking care of 8 jobs. We can see that the optimizer has favored equal distribution of the task over the cost considerations of the route as is evident from the locations of some of the jobs which were located closer to vehicle 1 than to vehicle 2. NextBillion.ai’s Route Optimization Flexible API offers a unique feature to tackle the challenges of uniform cost distribution across multiple resources as per the rules defined by the user and prepare the best solution. Readers are encouraged to try the other metric available for equal distribution, travel cost, as well.

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