Distribute tasks equally

Product Used: Route Optimization API

NextBillion.ai’s Route Optimization API provides users with a high degree of customization by leveraging over 50+ parameters to closely emulate the real-world constraints of route planning. Users can leverage the custom settings for tuning the algorithm to achieve their business objectives. One of the custom settings is to distribute the tasks equally among all the operators as much as possible.

In this example, we have 4 agents who need to fulfill 12 tasks which are randomly distributed across a region. To highlight the impact of the custom algorithm settings we will keep the starting points of all 4 vehicles the same. The optimization service will take into account all the constraints and return the best feasible solution with tasks equally distributed.

To configure this Route Optimization request we will need to set up the locations, vehicles involved and the tasks to be performed. Let’s address them one by one below.

Configure optimization request

To configure a Route Optimization request we will need to set up the locations, tasks, vehicles involved along with the custom objective. Let’s address them one by one below.

Locations

We configure the locations attribute and add all the locations used in the problem along with a valid id. We add locations for all 12 tasks and the starting point of the agents. Following is the locations object with all the coordinates to be used in this example:

1
"locations": {
2
"id": 1,
3
"location": ["34.083950,-118.318640", "34.054927,-118.323726", "34.075525,-118.361588", "34.076350,-118.338519", "34.090425,-118.338933", "34.037925,-118.459842", "34.004364,-118.421170", "34.000215,-118.318803", "33.945884,-118.325628", "34.000895,-118.204929", "34.076646,-118.376969", "34.094986,-118.300885", "34.018780,-118.317919"]
4
}

Jobs

We define 12 tasks that need to be performed in this example. Following are the constraints that we set for these tasks:

  • A unique id for each task
  • location_index for each task
  • Time taken to complete the task once the agent is at the task’s location i.e. the “service” time for each task.

Following is the “jobs” attribute after the above properties are configured:

1
"jobs": "[...]"

Vehicles

Next, we add details about the 4 agents that are responsible for fulfilling the above tasks. For each agent, we add:

  • A unique ID
  • “start_index” to denote the point from where the agent starts.

Following is the vehicles JSON with all the above properties configured:

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

Options

Next, we define our objective of equally distributing the tasks among all available agents. We use the custom objective options to configure it

1
"options": "[...]"

Route Optimization POST request

All the above components are now combined and submitted as a single JSON to the Route Optimization endpoint:

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

Route Optimization POST request

Once the above POST request is successfully submitted, a response similar to the following is received:

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

Retrieve optimization solution

Capture the task “id” from the POST response and use it in a subsequent GET request to retrieve the optimized solution asynchronously:

Route Optimization GET request

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

Route Optimization GET response

In the response, we see that the service has distributed the tasks equally among all the available agents with each of them getting 3 tasks to complete.

1
{
2
"description": "Custom Objective",
3
"result": {
4
"code": 0,
5
"summary": "{...}",
6
"routes": "[....]"
7
}
8
}

Visit Route Optimization Flexible API documentations to know more about the available optimization features.

© 2024 NextBillion.ai all rights reserved.