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:
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:
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:
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
asmin-max
to indicate that we want to invoke the equal distribution algorithm. -
value
astasks
to indicate that we want to apply the algorithm on the number of tasks metric.
The resulting objective
attribute JSON is:
Optimization POST Request
Now let’s put all these components together and create the final POST request that we will submit to the optimizer.
Optimization POST Response
Once the request is successfully submitted, we get a unique ID in the API response:
Optimization GET Request
We take the ID and use the Optimization GET request to retrieve the result. Here is the GET request:
Optimization GET Response
Following is the optimized route plan:
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!