On this page, you’ll find various examples demonstrating how to use the API for various scenarios. The API primarily supports two main use cases:
- Planning and Scheduling: Generates an optimized schedule for a fleet’s tours, considering constraints related to jobs and vehicles.
- Re-optimization: Modifies an existing or ongoing schedule to reflect changes such as new jobs or cancellations as well as broken vehicles.
Explore the examples provided to see how these use cases are implemented:
Example 1: Planning a simple pickup and delivery (drop-off) scenario
Example 2: A simple re-optimization scenario for adding new jobs to an existing schedule
Example 3: Re-optimization with cancelled jobs
Example 4: Re-optimization with broken vehicles
Example 1: Planning a simple pickup and delivery scenario
In this example, our fleet consists of 2 vehicles, and we have 3 pickup and delivery jobs that must be served by the two vehicles. Here are the details for each vehicle:
Vehicle 1:
Shift Details: The shift starts on 2024-10-01 at 8:00 AM from location (52.46642, 13.28124) and ends at 6:00 PM at the same location.
Breaks: The vehicle has two breaks, each lasting 15 minutes:
- First break: Between 12:00 PM and 1:00 PM at location (51.23210, 13.12346).
- Second break: Between 2:00 PM and 3:00 PM at location (51.53171, 12.65421).
Capacity: 15 seats and 5 baggage.
Skills: Equipped with a lift and air conditioning.
Vehicle 2:
Shift Details: The shift starts on 2024-10-01 at 8:00 AM from location (50.10643, 14.2234) and ends at 6:00 PM at location (51.21643, 14.5432).
Breaks: The vehicle has one 15-minute break:
- Break: Between 12:00 PM and 1:00 PM at location (51.23210, 13.12346).
Capacity: 10 seats and 8 baggage.
Skills: Equipped with a lift only.
We also have three pickup and delivery jobs. Here are the details of each job:
Job 1:
Pickup: Location (51.12345, 12.23412)
- Service Window: 9:00 AM to 9:30 AM
- Duration: 10 minutes
- Requirements: 1 seat, 2 baggage, vehicle equipped with a lift
Delivery: Location (53.26128, 13.43278)
- Service Window: 10:30 AM to 10:45 AM
- Duration: 5 minutes
Job 2:
Pickup: Location (50.73547, 14.65216)
- Service Window: 11:30 AM to 11:45 AM
- Duration: 5 minutes
- Requirements: 1 seat, vehicle equipped with both a lift and air conditioning
Delivery: Location (52.14443, 12.17741)
- Service Window: 12:45 PM to 1:30 PM
- Duration: 5 minutes
Job 3:
Pickup: Location (52.30021, 13.80103)
- Service Window: 2:00 PM to 2:30 PM
- Duration: 10 minutes
- Requirements: 1 seat, 3 baggage, no specific equipment is required
Delivery: Location (53.02359, 12.34525)
- Service Window: 3:30 PM to 3:45 PM
- Duration: 5 minutes
Our goal is to assign these jobs to the defined vehicles so that the total travel time is minimized. In other words, our optimization objective will be equal to 1. Now, let’s create our input problem as follows:
{
"problem":
{
"fleet":
[
{
"id" : "1",
"shifts": [
{
"start": {
"time": "2024-10-01T08:00:00Z",
"location": {"lat": 52.46642, "lng": 13.28124}
},
"end": {
"time": "2024-10-01T18:00:00Z",
"location": {"lat": 52.46642, "lng": 13.28124}
},
"breaks": [
{
"serviceWindow": ["2024-10-01T12:00:00Z","2024-10-01T13:00:00Z"],
"duration": 15,
"location": {"lat": 51.23210, "lng": 13.12346}
},
{
"serviceWindow": ["2024-10-01T14:00:00Z","2024-10-01T15:00:00Z"],
"duration": 15,
"location": {"lat": 51.53171, "lng": 12.65421}
}]
}],
"capacities":[
{
"name": "seat",
"units": 15
},
{
"name": "baggage",
"units": 5
}
],
"skills": ["lift","air_conditioner"]
},
{
"id" : "2",
"shifts": [
{
"start": {
"time": "2024-10-01T08:00:00Z",
"location": {"lat": 50.10643, "lng": 14.2234}
},
"end": {
"time": "2024-10-01T18:00:00Z",
"location": {"lat": 51.21643, "lng": 14.5432}
},
"breaks": [
{
"serviceWindow": ["2024-10-01T12:00:00Z","2024-10-01T13:00:00Z"],
"duration": 15,
"location": {"lat": 52.73190, "lng": 11.14325}
}
]
}],
"capacities":[
{
"name": "seat",
"units": 10
},
{
"name": "baggage",
"units": 8
}
],
"skills": ["lift"]
}
],
"jobs": [
{
"id": "1",
"pickups": [
{
"id": "1",
"location": [51.12345, 12.23412],
"serviceWindows": [["2024-10-01T09:00:00Z","2024-10-01T09:30:00Z"]],
"duration": 10,
"demand":[
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 2
}
],
"skills": ["lift"]
}
],
"deliveries": [
{
"id": "1",
"location": [53.26128, 13.43278],
"serviceWindows": [["2024-10-01T10:30:00Z","2024-10-01T10:45:00Z"]],
"duration": 5,
"demand":[
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 2
}
],
"skills": ["lift"]
}
]
},
{
"id": "2",
"pickups": [
{
"id": "1",
"location": [50.73547, 14.65216],
"serviceWindows": [["2024-10-01T11:30:00Z","2024-10-01T11:45:00Z"]],
"duration": 5,
"demand":[
{
"name": "seat",
"units": 1
}
],
"skills": ["lift","air_conditioner"]
}
],
"deliveries": [
{
"id": "1",
"location": [52.14443, 12.17741],
"serviceWindows": [["2024-10-01T12:45:00Z","2024-10-01T13:30:00Z"]],
"duration": 5,
"demand":[
{
"name": "seat",
"units": 1
}
],
"skills": ["lift","air_conditioner"]
}
]
},
{
"id": "3",
"pickups": [
{
"id": "1",
"location": [52.30021, 13.80103],
"serviceWindows": [["2024-10-01T14:00:00Z","2024-10-01T14:30:00Z"]],
"duration": 10,
"demand":[
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 3
}
]
}
],
"deliveries": [
{
"id": "1",
"location": [53.02359, 12.34525],
"serviceWindows": [["2024-10-01T15:30:00Z","2024-10-01T15:45:00Z"]],
"duration": 5,
"demand":[
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 3
}
]
}
]
}
],
"objective": 1,
"configuration":
{
"input":
{
"siteId": 1,
}
"output":
{
"polyLineType": "plain",
"unassignedJobs": False,
"statistics": True,
}
}
"version": 1.0
}
}
Example 2: A simple re-optimization scenario for adding new jobs to an existing schedule
Now consider the previous example. Assume that you have started performing the produced schedule since the morning, and now it is 11:36:34, and you get a new job order as follows:
- Job 4: (a new job)
- Pickup: Location (52.99211, 12.99127)
- Service Window: 15:45 to 16:15
- Duration: 15 minutes
- Requirements: 1 seat, 1 baggage
- Delivery: Location (54.13452, 14.21008)
- Service Window: 17:00 to 17:15
- Duration: 10 minutes
BTW, you have already performed Job 1 but Job 2 and Job 3 are still in progress with the following details:
- Job 1: (performed)
- Job 2: (in progress)
- Pickup:
- Current Vehicle ID: 2
- ETA: 11:40
- Delivery:
- Current Vehicle ID: 2
- ETA:15:00
- Job 3: (in progress)
- Pickup:
- Current Vehicle ID: 1
- ETA: 14:10
- Delivery:
- Current Vehicle ID: 1
- ETA: 15:34
Note that since Job 2 and Job 3 are in progress, they have an associate vehicle ID and ETA. To re-optimize your schedule to include the new job (i.e. Job 4), you’ll need to provide an updated view of your current schedule through the API. This should include details about your jobs follows:
Job 1: for this job, since it is already performed, you can set the status of the pickup and delivery tasks for this job to “status”:”performed” . Note that you don’t need to provide the current vehicle ID and ETA for these tasks as they are already performed, and you cannot change them anymore.
Job 2: this job is still in progress, and it is assigned to vehicle 2 with pickup ETA=11:40 and delivery ETA=13:15. So, you need to include the following object for its pickup task:
"lastKnownLocation":{
"location":[53.12345,13.24221],
"time":"2024-10-01T-11:36:34"
}
Also, you need to include the following object for its delivery task:
"status": "in_progress",
"vehicleID": 2,
"eta": "2024-10-01T13:15:00Z"
Job 3: this job is still in progress, and it is assigned to vehicle 1 with pickup ETA=14:10 and delivery ETA=15:34. So, you need to include the following object for its pickup task:
"status": "in_progress",
"vehicleID": 1,
"eta": "2024-10-01T14:10:00Z"
Also, you need to include the following object for its delivery task:
"status": "in_progress",
"vehicleID": 1,
"eta": "2024-10-01T15:34:00Z"
Job 4: since this is a new job and not scheduled yet, you simply set its status to “status”:”pending”. You don’t need to specify a vehicle ID or ETA for this job because it is not scheduled yet, and you don’t have this information. After performing the re-optimization, you will get a vehicle ID and an ETA for each task of this job.
Moreover, you need to provide the last known location of your vehicles so that the API can have an updated picture of your current schedule to do the optimization task efficiently. Suppose that the last known location of your vehicles at time 11:36:34 (i.e. the time that we want to do re-optimization) is as follows:
- Vehicle 1: (53.12345,13.24221)
- Vehicle 2: (53.79912,13.35789)
For this purpose, you need to include the following object for vehicle 1:
"lastKnownLocation":{
"location":[53.12345,13.24221],
"time":"2024-10-01T-11:36:34"
}
Similarly, you need to include the following object for vehicle 2:
"lastKnownLocation":{
"location":[53.79912,13.35789],
"time":"2024-10-01T-11:36:34"
}
To do re-optimization, you can now submit your new optimization problem as follows:
{
"problem": {
"fleet": [
{
"id": "1",
"shifts": [
{
"start": {
"time": "2024-10-01T08:00:00Z",
"location": {
"lat": 52.46642,
"lng": 13.28124
}
},
"end": {
"time": "2024-10-01T18:00:00Z",
"location": [
52.46642,
13.28124
]
},
"breaks": [
{
"serviceWindow": [
"2024-10-01T12:00:00Z",
"2024-10-01T13:00:00Z"
],
"duration": 15,
"location": {
"lat": 51.23210,
"lng": 13.12346
}
},
{
"serviceWindow": [
"2024-10-01T14:00:00Z",
"2024-10-01T15:00:00Z"
],
"duration": 15,
"location": {
"lat": 51.53171,
"lng": 12.65421
}
}
]
}
],
"capacities": [
{
"name": "seat",
"units": 15
},
{
"name": "baggage",
"units": 5
}
],
"skills": [
"lift",
"air_conditioner"
],
"lastKnownLocation": {
"location": [
53.12345,
13.24221
],
"time": "2024-10-01T-11:36:34"
}
},
{
"id": "2",
"shifts": [
{
"start": {
"time": "2024-10-01T08:00:00Z",
"location": {
"lat": 50.10643,
"lng": 14.2234
}
},
"end": {
"time": "2024-10-01T18:00:00Z",
"location": {
"lat": 50.10643,
"lng": 14.2234
}
},
"breaks": [
{
"serviceWindow": [
"2024-10-01T12:00:00Z",
"2024-10-01T13:00:00Z"
],
"duration": 15,
"location": {
"lat": 52.73190,
"lng": 11.14325
}
}
]
}
],
"capacities": [
{
"name": "seat",
"units": 10
},
{
"name": "baggage",
"units": 8
}
],
"skills": [
"lift"
],
"lastKnownLocation": {
"location": [
53.79912,
13.35789
],
"time": "2024-10-01T-11:36:34"
}
}
],
"jobs": [
{
"id": "1",
"pickups": [
{
"id": "1",
"location": [
51.12345,
12.23412
],
"serviceWindows": [
[
"2024-10-01T09:00:00Z",
"2024-10-01T09:30:00Z"
]
],
"duration": 10,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 2
}
],
"skills": [
"lift"
],
"status": "performed"
}
],
"deliveries": [
{
"id": "1",
"location": [
53.26128,
13.43278
],
"serviceWindows": [
[
"2024-10-01T10:30:00Z",
"2024-10-01T10:45:00Z"
]
],
"duration": 5,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 2
}
],
"skills": [
"lift"
],
"status": "performed"
}
]
},
{
"id": "2",
"pickups": [
{
"id": "1",
"location": [
50.73547,
14.65216
],
"serviceWindows": [
[
"2024-10-01T11:30:00Z",
"2024-10-01T11:45:00Z"
]
],
"duration": 5,
"demand": [
{
"name": "seat",
"units": 1
}
],
"skills": [
"lift",
"air_conditioner"
],
"status": "in_progress",
"vehicleID": 2,
"eta": "2024-10-01T11:40:00Z"
}
],
"deliveries": [
{
"id": "1",
"location": [
52.14443,
12.17741
],
"serviceWindows": [
[
"2024-10-01T12:45:00Z",
"2024-10-01T13:30:00Z"
]
],
"duration": 5,
"demand": [
{
"name": "seat",
"units": 1
}
],
"skills": [
"lift",
"air_conditioner"
],
"status": "in_progress",
"vehicleID": 2,
"eta": "2024-10-01T13:15:00Z"
}
]
},
{
"id": "3",
"pickups": [
{
"id": "1",
"location": [
52.30021,
13.80103
],
"serviceWindows": [
[
"2024-10-01T14:00:00Z",
"2024-10-01T14:30:00Z"
]
],
"duration": 10,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 3
}
],
"status": "in_progress",
"vehicleID": 1,
"eta": "2024-10-01T14:10:00Z"
}
],
"deliveries": [
{
"id": "1",
"location": [
53.02359,
12.34525
],
"serviceWindows": [
[
"2024-10-01T15:30:00Z",
"2024-10-01T15:45:00Z"
]
],
"duration": 5,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 3
}
],
"status": "in_progress",
"vehicleID": 1,
"eta": "2024-10-01T15:34:00Z"
}
]
},
{
"id": "4",
"pickups": [
{
"id": "1",
"location": [
52.99211,
12.99127
],
"serviceWindows": [
[
"2024-10-01T15:45:00Z",
"2024-10-01T16:15:00Z"
]
],
"duration": 15,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 1
}
],
"status": "pending"
}
],
"deliveries": [
{
"id": "1",
"location": [
54.13452,
14.21008
],
"serviceWindows": [
[
"2024-10-01T17:00:00Z",
"2024-10-01T17:15:00Z"
]
],
"duration": 10,
"demand": [
{
"name": "seat",
"units": 1
},
{
"name": "baggage",
"units": 1
}
],
"status": "pending"
}
]
}
],
"objective": 1,
"version": 1.0
}
}
Example 3: Re-optimization with Cancelled Jobs
If you’ve submitted an optimization problem for a set of jobs and already have a schedule in place, but some jobs have been cancelled, you can re-optimize your schedule by removing the cancelled jobs from the problem. To do this, you’ll need to:
- Provide an updated picture of your remaining jobs and the last known locations of your vehicles similar to Example 2.
- Create and submit a revised problem reflecting these changes.
Once submitted, you will receive a new schedule that accounts for the updated jobs and fleet status.
Example 4: Re-optimization with broken vehicles
Suppose it’s 8:00 AM and you use the API to generate an optimized schedule for your jobs with 10 vehicles. You begin executing the schedule, but at 9:14 AM, you learn that one of your vehicles has broken down and can no longer perform its assigned jobs.
To re-optimize the schedule, follow these steps:
- Update Fleet Information: Remove the broken vehicle from your fleet object.
- Provide Vehicle Locations: Submit the last known locations of the remaining vehicles, similar to Example 2.
- Update Task Status:
- Provide the status of all tasks. You need to specify which tasks are already performed, which ones are in progress, and which one are new or pending (not scheduled yet).
- For tasks in progress, include the associated vehicle ID and the estimated time of arrival (ETA).
- Handle Tasks for the Broken Vehicle:
- Change the status of all tasks previously assigned to the broken vehicle to “pending”. This allows the API to reassign them to other available vehicles and recalculate their ETAs.
- Submit for Re-optimization: Submit the updated problem to the API for a new schedule optimization.
See Next: API Errors