Accommodate last minute tasks

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. One such powerful feature is the re-optimization feature which allows the users to tweak an existing solution in face of some last minute changes without changing the existing solution which was already under execution.

In this example, we will generate an original solution for an optimization problem with 2 operators and 5 tasks. Once we get the original solution we will emulate a situation where 2 new high priority orders are received at the very last minute. We, then, will use the re-optimization properties to share the original solution along with the 2 new tasks’ information to be accommodated into the existing route plan.

Configure original optimization request

To configure the original 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

We configure the locations attribute and add all the locations used in the problem along with a valid id. We add locations for 5 tasks and the starting point of the agent. 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"]
4
}

Jobs

We define 5 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.

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.

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

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

Original Route Optimization POST request

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

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

Route Optimization POST response

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

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

Retrieve original 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=4b1946289eb46b5c6b97f52178f7c762&key=<your_api_key>'

We get the original response using the above request. Keep the original route plan suggested in this solution handy as it will be used in the next step.

Re-optimize the original solution

Once the original response is available the operations team starts executing the plan by assigning tasks and sharing route plans with the agents. However, while the plan is in motion, another set of high priority orders are received. In this case, we use the re-optimization features available with NextBillion.ai’s Route Optimization and tweak the original plan to accommodate new orders.

Add new tasks

We add the newly received tasks to the original “jobs” attribute. Following are the new tasks that we use for this job

1
{
2
"id": "Job 6",
3
"location_index": 6,
4
"service": 300
5
},
6
{
7
"id": "Job 7",
8
"location_index": 7,
9
"service": 300
10
}

Configure input with previous solution

Next we prepare the solution attribute with details of original route plan from the previously generated GET response. This attribute will be added to the input request to generate a re-optimized plan.

1
"solution": "[...]"

Next, we add the solution and the new task details to the second request that we prepare to re-optimize. Following is the input request with re-optimization configured:

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

Re-optimized solution

Upon submitting the above request we get a new ID to retrieve the re-optimized solution using the GET request. Once we retrieve the response below, we can see the new tasks are also accommodated in the new route plan.

1
{
2
"description": "Re-optimization",
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.