How to Optimize Routes with Vehicle Capacity Limits
- API or service
- Route Planner API
- Task
- Vehicle capacities and task amounts → feasible load-aware routes
- Examples
- Difficulty
- Intermediate
- Time
- 10 min
Optimize routes with vehicle capacity limits
You have vehicles with different load limits and deliveries, collections, or shipments with different amounts. The route plan must assign and order the work without asking an agent to carry more than its configured capacity.
Use agent capacities together with task amounts. Route Planner includes those load constraints when deciding which agent receives each task.
Task flow: vehicle capacities and task amounts → Route Planner API → feasible assignments and load-aware routes.
Model vehicle loads
Choose one capacity model and use the same business unit for every related value:
| Work being modeled | Agent field | Task field | Load behavior |
|---|---|---|---|
| Goods loaded before the route and delivered to jobs | delivery_capacity |
Job delivery_amount |
Agent starts loaded; each job removes an amount |
| Goods collected from jobs | pickup_capacity |
Job pickup_amount |
Agent starts empty; each job adds an amount |
| Goods picked up and delivered during the route | Compatible agent capacity | Shipment amount |
Amount is carried between the shipment's pickup and delivery |
Amounts are unitless numbers. Your application defines whether 1 means one parcel, kilogram, liter, pallet position, or another measure. Never compare or combine amounts expressed in different units.
A job may specify pickup_amount or delivery_amount, but not both. The current Route Planner request contract also treats pickup_capacity and delivery_capacity as mutually exclusive on one agent. Use shipments when the same goods must be collected and delivered as a linked operation.
Capacity is one-dimensional. If weight and volume must both be constrained independently, decide which limit is operationally dominant or validate the second dimension in your application.
Set capacities and task amounts
This example assigns three deliveries containing 16 total units to a six-unit van and a twelve-unit van.
POST https://api.geoapify.com/v1/routeplanner?apiKey=YOUR_API_KEY
Content-Type: application/json
{
"mode": "drive",
"agents": [
{
"id": "van-small",
"start_location": [13.4132, 52.5219],
"end_location": [13.4132, 52.5219],
"delivery_capacity": 6
},
{
"id": "van-large",
"start_location": [13.4132, 52.5219],
"end_location": [13.4132, 52.5219],
"delivery_capacity": 12
}
],
"jobs": [
{
"id": "delivery-5",
"location": [13.3777, 52.5163],
"delivery_amount": 5
},
{
"id": "delivery-7",
"location": [13.3904, 52.5076],
"delivery_amount": 7
},
{
"id": "delivery-4",
"location": [13.4397, 52.505],
"delivery_amount": 4
}
]
}
The small van can carry either the five-unit or four-unit delivery, but not both. The large van can carry the seven-unit delivery together with the remaining compatible task.
Verify the load assignment
The optimizer assigns four units to the small van and twelve units to the large van. The response is reduced to agent IDs and assigned jobs.
Reduced response:
{
"features": [
{
"properties": {
"agent_id": "van-small",
"distance": 6935,
"actions": [
{"type": "job", "job_id": "delivery-4", "start_time": 243, "waypoint_index": 1}
]
}
},
{
"properties": {
"agent_id": "van-large",
"distance": 7459,
"actions": [
{"type": "job", "job_id": "delivery-7", "start_time": 266, "waypoint_index": 1},
{"type": "job", "job_id": "delivery-5", "start_time": 448, "waypoint_index": 2}
]
}
}
]
}
Check the result rather than assuming every task was assigned. If total demand, task sizes, time windows, or other constraints make the plan infeasible, the API may return job or shipment indexes under properties.issues.
For delivery jobs, sum the delivery_amount assigned to each agent and compare it with delivery_capacity. Here, 4 ≤ 6 and 7 + 5 = 12 ≤ 12.