Group nearby orders

Product Used: Route Optimization Flexible 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.

Order grouping feature creates clusters of tasks which are located within a given radius of each other and treats them as one stop. Delivery drivers can park the vans at a suitable place and complete the all grouped deliveries quickly. This saves the time that, otherwise, would have been spent on driving up to each nearby location and finding a parking spot for each of them.

In this example, we will set up a Route Optimization request to fulfill 5 delivery jobs while employing the order grouping feature to group nearby tasks, if they match a given criteria. The optimization service will then take into account all the variables specified in the input request and return optimal routes and task assignments to meet the configured objective. Let’s set up the problem statement in the following sections.

Configure optimization request

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
{
2
"locations": {
3
"id": 1,
4
"location": [
5
"39.95685024,-75.17623367",
6
"39.94849475,-75.17744821",
7
"39.94854692,-75.17772914",
8
"39.94823786,-75.17781810",
9
"39.94692819,-75.17641397",
10
"39.94688552,-75.17629895"
11
]
12
}
13
}

Jobs & Shipments

We define a bunch of delivery jobs 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
  • “delivery” amounts for all tasks
  • The actual time taken to complete the delivery 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
}

Vehicles

In this step we will configure the delviery van that will fulfilling the above delivery jobs. To configure the van and its properties, we add: A unique ID for the van “capacity” of the load that the van can take A “start_index” for the location from which the van starts

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

1
"vehicles": [
2
{
3
"id": 1,
4
"start_index":0,
5
"capacity":[10]
6
}
7
]

Options

Lastly we set the grouping criteria for the nearby tasks in the above optimization problem. We set the following constraints:

  • Configure the “grouping_diameter” to group tasks together if they are within the given straight line distance.”.

Following is the “options” JSON:

1
"options": {
2
"grouping": {
3
"order_grouping": {
4
"grouping_diameter": 100
5
}
6
}
7
}
8

Route Optimization POST request

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

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

Route Optimization POST request

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

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

Route Optimization GET response

You would see the solution with all the suggested routes and the tasks that were assigned to each of the vans.

1
{
2
"description": "Group Nearby Orders",
3
"result": '{...}'}

We can see that the 5 jobs are grouped in 2 groups. The location of the common stop for each group is returned in the “projected_location” field.

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

© 2024 NextBillion.ai all rights reserved.