Skip to content

Capacities and demand

~4 min read · Recipes

Capacities stop the engine from overloading a vehicle. Each vehicle declares one or more named capacities; each task declares the demand it consumes. The engine keeps every route within its limits.

Single capacity

Both snippets below are fragments of the Quickstart payload, not complete requests: the first is one entry of problem.fleet, the second is one task inside problem.jobs[].deliveries.

A vehicle in problem.fleet:

{ "id": 1, "capacities": [{ "name": "parcels", "units": 40 }] }

A task inside that job:

{ "id": 1001, "location": [49.26340, -123.13830], "duration": 300,
  "demand": [{ "name": "parcels", "units": 2 }] }

demand is a list of named buckets, exactly like capacities. The engine matches them by name, so the order you list them in doesn't matter.

Multiple capacities

Model several limits at once (e.g. count and weight). Name each bucket on the vehicle, then draw on those same names in every task's demand.

A vehicle in problem.fleet:

{ "id": 1, "capacities": [
  { "name": "parcels", "units": 40 },
  { "name": "weight_kg", "units": 800 }
] }

A task inside that job:

{ "id": 1001, "location": [49.26340, -123.13830], "duration": 300,
  "demand": [
    { "name": "parcels", "units": 2 },
    { "name": "weight_kg", "units": 35 }
  ] }

A task only needs to name the buckets it actually consumes — omit the rest.

  • A task whose demand can't fit any vehicle is placed in unassigned with the reason CAPACITY.
  • For pickup-and-delivery, the load is picked up and later dropped off, so capacity is only consumed between the pickup and its delivery.

The names must match

A demand name that appears on no vehicle can never be loaded, and the task will go unassigned. Watch for typos and for casing differences between the two lists.

Related: Pickups and deliveries (PDPTW) · Skills and matching · The Problem object