Allocate tasks based on skills

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 make use of the skills property to ensure that the correct tasks are assigned to agents based on the skills configured for them.

In this example, we will configure 6 tasks and 2 agents to fulfill those tasks. When configuring them we will also add the respective skills needed to fulfill each task. The optimization service will then ensure that only the right agent is assigned to each task and if an agent with the right skillset is not available then some tasks remain unassigned.

Configure optimization request

To configure a 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.

Locations

First we define the locations object and add all the locations used in the problem along with a valid id. Following is the locations object with all the coordinates to be used in this example:

1
"locations": {
2
"id": 1,
3
"location": ["34.06675919,-118.30620984", "34.04268850,-118.28191077", "34.03434239,-118.28358834", "34.04238041,-118.23817754", "34.08431954,-118.25597762", "34.06892275,-118.29156827", "34.01103011,-118.19238067"]
4
}

Jobs

We define 6 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
  • skills needed to complete the task
  • Time taken to complete the task once the agent is at the task’s location i.e. the “service” time for each task.

Let’s take a look at the “jobs” after the above properties are configured:

1
"jobs": [...]

Vehicles

Next, we add details about the 2 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.
  • “skills” of the agent to ensure that only the correct tasks are assigned to them.

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

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

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 response

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

1
{
2
"id": "9a9bfaa251fa221a272c4c4c3f027181",
3
"message": "Optimization job created",
4
"status": "Ok",
5
"warning": [
6
"skill 4 is not found in any vehicle"
7
]
8
}

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=9a9bfaa251fa221a272c4c4c3f027181&key=<your_api_key>'

Route Optimization GET response

In the response, we see that the service has correctly assigned the right agent for each task based on the skills that are required to fulfill them. We can also see that some tasks that required skills not possessed by any of the available agents, remain unassigned.

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

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

© 2024 NextBillion.ai all rights reserved.