Capacity reservation
Some work can’t be planned in advance. Urgent repairs and emergency call-outs come in during the day, and a technician must be free to take them. If every shift is fully booked with routine visits, there is no room left for this work.
A capacity reservation keeps part of a shift free for specific visits only.
For example, you can keep the afternoon of a shift free for visits with priority 3 or higher.
Timefold doesn’t schedule routine visits, or the travel to them, in the reserved period.
It still schedules visits that the reservation permits in the reserved period.
1. Define a capacity reservation
Learn how to configure an API Key to run the examples in this guide:
In the examples, replace |
Add a capacityReservations array to a vehicle shift:
{
"id": "Carl-2027-02-01",
"startLocation": [33.68786, -84.18487],
"minStartTime": "2027-02-01T09:00:00Z",
"maxEndTime": "2027-02-01T17:00:00Z",
"capacityReservations": [
{
"id": "Carl-2027-02-01-afternoon",
"startTime": "2027-02-01T13:00:00Z",
"endTime": "2027-02-01T15:00:00Z",
"rule": {
"type": "PRIORITY",
"lowestAllowedPriority": "3"
}
}
]
}
Each capacity reservation has these fields:
-
id: the unique identifier of the capacity reservation. -
startTime: the time the reserved period starts (inclusive). -
endTime: the time the reserved period ends (exclusive). -
rule: the rule that defines which visits the reserved period permits.
A shift can have more than one capacity reservation. Multiple capacity reservations of a shift must not overlap, and they must be inside the shift’s hours.
1.1. Priority rule
The PRIORITY rule permits a visit if its priority is equal to or higher than lowestAllowedPriority.
In the example above, the reservation permits visits with priority 1, 2, and 3.
It doesn’t permit visits with priority 4 to 10.
The rule compares the weights of the priorities, so a mandatory priority and its optional counterpart have the same result.
For example, lowestAllowedPriority 3 permits optional visits with priority opt-3.
See Priority visits for the built-in priorities.
If you use custom priorities, set lowestAllowedPriority to the name of a custom priority.
The rule then compares the weights of your custom priorities.
If you use custom priorities, lowestAllowedPriority can’t be a built-in priority.
lowestAllowedPriority doesn’t accept the deprecated priorities LOW, NORMAL, HIGH, and CRITICAL.
Use a priority from 1 to 10 instead.
If lowestAllowedPriority names a priority that doesn’t exist or is deprecated, the model rejects the dataset with a validation error.
1.2. Permit mandatory visits only
By default, the PRIORITY rule permits both mandatory and optional visits.
To keep the reserved period for mandatory visits only, set lowestAllowedAssignment to MANDATORY:
{
"id": "Carl-2027-02-01-afternoon",
"startTime": "2027-02-01T13:00:00Z",
"endTime": "2027-02-01T15:00:00Z",
"rule": {
"type": "PRIORITY",
"lowestAllowedPriority": "3",
"lowestAllowedAssignment": "MANDATORY"
}
}
A visit must meet both conditions:
-
Its priority is equal to or higher than
lowestAllowedPriority. -
It is mandatory, if
lowestAllowedAssignmentisMANDATORY.
In this example, the reservation permits a mandatory visit with priority 2.
It doesn’t permit an optional visit with priority opt-1 or opt-3, although these priorities are high enough.
lowestAllowedAssignment accepts these values:
-
OPTIONAL(default): the rule permits mandatory and optional visits. -
MANDATORY: the rule permits only mandatory visits.
The model rejects the input if lowestAllowedAssignment is AUTO.
The rule uses the assignment type that the model resolves for each visit.
With the default AUTO assignment, a visit with a built-in priority 1 to 10 is mandatory only if its time window ends in the planning window.
So the same visit can be permitted when its time window ends in the planning window, and not permitted when its time window continues after the planning window.
See Overriding the default assignment type for built-in priorities and Explicit assignment type for custom priorities.
2. How Timefold plans around a capacity reservation
A capacity reservation affects only the visits that it doesn’t permit. For these visits, Timefold moves the activities of the technician out of the reserved period:
-
Service: if the service of a visit overlaps the reserved period, the service starts when the reserved period ends. The technician waits at the visit location. The service also moves to the next time window of the visit if the end of the reserved period is outside the current time window.
-
Travel to the visit: if the travel to a visit overlaps the reserved period, the technician waits at the previous location and sets off when the reserved period ends. If the technician arrives at the visit before the reserved period starts, the travel is not delayed. The technician can wait at the visit location during the reserved period.
-
Travel to the shift end: no capacity reservation permits the travel to the end location of the shift. If this travel overlaps a reserved period, the technician sets off when the reserved period ends. This can make the shift end later.
Timefold doesn’t delay the start of the shift.
A capacity reservation doesn’t move the actual times that you record for a visit:
-
If a visit has an
actualArrivalTime, anactualStartServiceTime, or anactualDepartureTime, the travel to the visit already happened, so Timefold doesn’t delay it. -
If a visit has an
actualStartServiceTime, Timefold doesn’t delay the service. If the visit has only anactualArrivalTime, Timefold will delay the service if it overlaps until the reserved period ends.
Visits that a capacity reservation permits are not affected. Timefold schedules them, and the travel to them, in the reserved period as usual.
For example, Carl’s shift starts at 09:00 and has a capacity reservation from 13:00 to 15:00 for priority 3 or higher.
Visit A has priority 6 and the travel to it takes 30 minutes.
If Carl is ready to set off to visit A at 12:45, the travel overlaps the reserved period.
Carl waits at the previous location until 15:00, and arrives at visit A at 15:30.
If visit A had priority 2, Carl would set off at 12:45 and arrive at 13:15.
3. Capacity reservations and linked shifts
A linked shift can also have a capacityReservations array.
When Timefold uses the combined linked shift:
-
If the linked shift has capacity reservations, Timefold uses only these capacity reservations.
-
If the linked shift has no capacity reservations, Timefold uses the capacity reservations of all the individual shifts in the linked shift.
The reservedCapacity input metric and the totalReservedCapacity output metric count each reserved period once:
-
They include a linked shift only if it has visits.
-
They don’t include a vehicle shift that a linked shift with visits replaces.
4. The No conflict with capacity reservation constraint
The No conflict with capacity reservation hard constraint penalizes a visit that a capacity reservation doesn’t permit, if the travel to the visit or its service overlaps the reserved period.
The penalty is the number of seconds of the overlap.
The travel is the last leg of the travel to the visit.
Waiting at the visit location during the reserved period is not penalized.
Usually, Timefold moves the travel and the service out of the reserved period, so the constraint is not broken. The constraint can be broken if the delay is not possible, for example, if the visit already has a recorded actual time or the visit is pinned with a fixed start service time.
The constraint belongs to the Capacity reservation constraint group.
The constraint is active only if at least one shift has a capacity reservation.
5. Reserved capacity in the output
The output dataset shows how much of the reserved time the technicians use.
These metrics are in the metrics of each shift and each vehicle in the model output, and in the KPIs of the route plan:
-
totalReservedCapacity: the total time of the capacity reservations. -
usedReservedCapacity: the time of the capacity reservations that the technician uses for the travel to visits and for their service.
usedReservedCapacity includes each part of a reserved period that overlaps:
-
The service of a visit.
-
The travel to a visit. The travel is the last leg of the travel to the visit, the same as for the
No conflict with capacity reservationconstraint.
usedReservedCapacity includes all visits, also the visits that a capacity reservation doesn’t permit.
It doesn’t include waiting, the travel to a break location before the last leg, or the travel to the end location of the shift.
The metrics of a shift include all its capacity reservations, also if the shift has no visits. The metrics of a vehicle and the KPIs include all the shifts, also the shifts with no visits. They don’t count a reserved period two times for a linked shift:
-
They include a linked shift only if Timefold uses it.
-
They don’t include a vehicle shift that a linked shift in use replaces.
The KPI totalReservedCapacity uses the same rule as the reservedCapacity input metric.
The two values are different only if Timefold uses a linked shift with its own capacity reservations, or stops using one.
To get the reserved time that is still free for urgent visits, subtract usedReservedCapacity from totalReservedCapacity.
This includes the reserved time of the shifts with no visits.
To find the shifts with no visits that have capacity reservations, look at the metrics of each shift.
The metrics of a shift are null if the shift has no capacity reservation.
The metrics of a vehicle and the KPIs are null if no shift of the vehicle, or of the route plan, has a capacity reservation.
For example, Carl’s shift has a capacity reservation from 13:00 to 15:00 for priority 3 or higher:
-
Carl sets off to visit C with priority
2at 12:45 and arrives at 13:15. The capacity reservation permits visit C. The service of visit C takes 1 hour, from 13:15 to 14:15. -
The capacity reservation doesn’t permit visit D with priority
6. Carl waits at visit C until 15:00 and then sets off to visit D.
Carl uses 15 minutes of the reserved period for the travel to visit C and 1 hour for its service. The waiting at visit C is not included:
{
"metrics": {
"totalReservedCapacity": "PT2H",
"usedReservedCapacity": "PT1H15M"
}
}
6. Capacity reservation validation
The model can reject a dataset with validation errors prefixed with CAPACITY_RESERVATION_, see validation errors for the list of errors and their trigger conditions.
For the CAPACITY_RESERVATION_BREAK_OVERLAP check, validation uses these periods of a break:
-
A fixed break: from its
startTimeto itsendTime. -
A floating break: from its
minStartTimeto itsmaxEndTime. If the floating break doesn’t setmaxEndTime, the period continues to the end of the shift.
A floating break overlapping with a reserved capacity time period is treated as an error even if Timefold could schedule it outside the reserved period. Make sure the time window of a floating break and the capacity reservations of its shift don’t overlap.
For a linked shift, validation uses the breaks of the linked shift.
If the linked shift has no breaks, validation uses the breaks of all the component shifts of the linked shift.
In this case, a floating break without maxEndTime ends with its own component shift, unless its component shift is the last shift in the linked shift.
See Breaks in a linked shift.
Next
-
See the full API spec, try the online API, or start a free trial.
-
Learn more about field service routing from our YouTube playlist.
-
Read Priority visits and optional visits to learn how to set the priority of a visit.