Tuning manual edits: travel, waiting and lateness
When a planner inserts a booking into a route or moves a time window, the Manual Edit API sends the affected route to the optimization engine. The engine decides where the new stops go and when every stop is served. It weighs three costs against each other:
| Cost | What it means for the driver |
|---|---|
| Travel | Extra driving caused by the edit, such as a detour to reach the new stop. |
| Waiting (slack) | Idle time at a stop because the vehicle arrives before the time window opens. See Vehicle slack. |
| Lateness | Arriving after a stop's time window has closed. See Lateness. |
You can't drive all three to zero at once. A shorter detour can push a later stop past its window. Arriving on time can mean arriving early and waiting. This guide shows which settings control the balance and how to adjust them.
Which edits this applies to
The balance matters only when the engine chooses the stop order. It does that for two actions:
vehicle_assign_booking_list(force-assign bookings to a vehicle)shift_nodes_time_windows(adjust delivery windows)
For vehicle_reorder_nodes and vehicle_shift_nodes, you set the order, so travel is already fixed. The engine only recalculates arrival times. The travel and waiting settings below have no effect on those actions.
Assignment edits must place the booking. If on-time delivery is impossible, the engine accepts some lateness or reports that the edit is infeasible. It never drops the booking to save cost.
How the engine compares the three costs
All three costs use the same scale, so you can compare them directly. With the default algo_optimize_quantity of total_time:
- 1 second of driving costs 1.
- 1 second of lateness costs
manual_edit_lateness_penalty_coefficient, which defaults to10. - 1 second of waiting costs
slack_cost_factor, which defaults to10. This applies only when slack optimization is switched on (see Waiting time).
Each coefficient is an exchange rate against driving. A lateness coefficient of 10 means the engine accepts up to 10 extra seconds of driving to avoid 1 second of lateness.
Worked example
A planner inserts a new delivery into a route. The engine finds two options:
| Option A: short detour | Option B: longer detour | |
|---|---|---|
| Extra driving | 5 min (300 s) | 25 min (1,500 s) |
| Lateness at a later stop | 20 min (1,200 s) | 0 |
Cost with coefficient 10 | 300 + 1,200 × 10 = 12,300 | 1,500 |
Cost with coefficient 1 | 300 + 1,200 × 1 = 1,500 | 1,500 |
With the default coefficient of 10, the engine picks Option B: it drives 20 extra minutes to stay on time. With a coefficient of 1, the two options cost the same, and any further increase in Option B's driving would make the late option win.
The settings
All of these keys go in logistics_api_settings on the simulation. Keys with the manual_edit_ prefix apply only to manual edits. They don't change your main optimization runs.
Lateness
| Setting | Effect | Default |
|---|---|---|
manual_edit_allow_vehicle_late | Lets edits make vehicles arrive after a window closes. When false, any edit that can't stay on time fails. | true |
manual_edit_lateness_penalty_coefficient | Cost of 1 second of lateness, relative to 1 second of driving. Must be a whole number. | 10 |
manual_edit_max_possible_lateness | Maximum lateness per stop, in seconds. Not set means no limit. | not set |
manual_edit_try_strict_time_windows_request | Tries the edit with strict time windows first, then accepts lateness only if that fails. Use it together with manual_edit_allow_vehicle_late: true. | false |
Waiting time (slack)
Edits charge for waiting only when both of these are set:
path_constraints_modeislogistics.- Slack optimization is on for the vehicles:
manual_edit_api_vehicle_logistics_optimize_slackistrue. If you don't set it, the engine uses your generallogistics_optimize_slacksetting.
In any other configuration, edits treat waiting as free.
| Setting | Effect | Default |
|---|---|---|
manual_edit_api_vehicle_logistics_optimize_slack | Switches slack costing on or off for manual edits. If not set, logistics_optimize_slack applies. | not set |
manual_edit_slack_cost_factor | Cost of 1 second of waiting, relative to 1 second of driving. If not set, slack_cost_factor applies, and if neither is set, the default is 10. | not set |
In logistics mode the slack factor is rounded down to a whole number. A value such as 0.5 becomes 0, which switches slack costing off. Use 1 or higher.
0 also doesn't switch slack costing off for edits on its own. A manual_edit_slack_cost_factor of 0 is treated as "not set", so the main slack_cost_factor applies instead. To stop edits from charging for waiting, set manual_edit_api_vehicle_logistics_optimize_slack to false.
Travel
| Setting | Effect | Default |
|---|---|---|
manual_edit_optimize_quantity | What "travel" means for edits: total_time (seconds of driving) or total_distance (metres). If not set, algo_optimize_quantity applies. | total_time |
total_distance changes the balanceThe lateness and slack coefficients are always charged per second. With total_distance, travel is charged per metre, so 1 second late costs the same as coefficient metres of driving. At 36 km/h (10 m/s), that is about one tenth of the weight it has under total_time. If you switch, multiply both coefficients by roughly your fleet's average speed in metres per second to keep a similar balance.
Tuning recipes
Change one value at a time. Test each change with dry_run: true in the edit request first.
| What you see after edits | What to change |
|---|---|
| Edits make later stops late just to save a short detour. | Raise manual_edit_lateness_penalty_coefficient, for example from 10 to 30–100. Or turn on manual_edit_try_strict_time_windows_request so the engine looks for an on-time option first. |
| Edits create long detours to avoid a minute or two of lateness. | Lower manual_edit_lateness_penalty_coefficient, for example to 2–5. |
| Lateness after an edit is sometimes unacceptably large. | Set manual_edit_max_possible_lateness, for example 1800 for 30 minutes. See How an edit is attempted for how this interacts with enable_fallback. |
| Drivers sit idle at stops after edits. | Set path_constraints_mode to logistics, turn on manual_edit_api_vehicle_logistics_optimize_slack, and raise manual_edit_slack_cost_factor. |
| Edits add driving just to avoid arriving early. | Lower manual_edit_slack_cost_factor, for example to 1–3. Or set manual_edit_api_vehicle_logistics_optimize_slack to false. |
| Edits trade lateness for waiting in the wrong direction. | Compare the two coefficients. If lateness is worse for your business than waiting, keep the lateness coefficient clearly above the slack factor. |
| Edits must never be late. | Set manual_edit_allow_vehicle_late to false. Expect more edits to fail where staying on time is impossible. |
Two starting points:
- Delivery promises come first: lateness
50, slack5. - Fleet efficiency comes first: lateness
5, slack10, with slack optimization on.
Example
{
"logistics_api_settings": {
"path_constraints_mode": "logistics",
"manual_edit_allow_vehicle_late": true,
"manual_edit_try_strict_time_windows_request": true,
"manual_edit_lateness_penalty_coefficient": 50,
"manual_edit_max_possible_lateness": 1800,
"manual_edit_api_vehicle_logistics_optimize_slack": true,
"manual_edit_slack_cost_factor": 5
}
}
With these settings, an edit first tries to keep every stop on time. If that fails, it accepts lateness: 1 second of lateness costs 50 seconds of driving, and lateness is capped at 30 minutes per stop. Waiting is discouraged, but less strongly than lateness.
How an edit is attempted
For vehicle_assign_booking_list, the engine prepares up to three versions of the edit, runs them, and uses the first one that succeeds, in this order:
- Strict time windows, if
manual_edit_try_strict_time_windows_requestistrueandmanual_edit_allow_vehicle_lateistrue. Lateness isn't allowed. - Main, using your settings exactly as configured.
- Fallback, if
enable_fallbackistruein the edit request (the default). This version allows unlimited lateness and ignoresmanual_edit_max_possible_lateness, so the planner's edit can still go through.
shift_nodes_time_windows uses only steps 1 and 2. It tries strict time windows, then allows lateness, depending on the same two settings.
manual_edit_max_possible_lateness is a hard limit only when the fallback can't run. To guarantee the cap, send "enable_fallback": false with the edit. The edit then fails instead of exceeding the cap.