Designing an ML-Driven Workload Allocator for Delivery Drivers
Machine LearningModel answerLast updated
Design a system that forecasts stop service times with ML and feeds them to a constrained optimizer to split a shift's deliveries across drivers, balancing punctuality and fairness.
A last-mile delivery station has always split each shift's parcels among drivers by hand. You are asked to replace this with an automated allocation system that decides how much work each driver gets on each shift.
The system should maximize on-time delivery while keeping workloads fair across drivers.
Describe a complete design that covers:
- Objective. One or more objective functions. For example, reward on-time probability and penalize overtime and distance, with a fairness term or constraint on workload spread.
- Constraints. Shift length, vehicle capacity (weight and volume), delivery windows, geographic contiguity of each driver's area, required skills or certifications, and the observed distribution of time spent at stops.
- Data and features. For example, stop density, hour- and weather-dependent travel-time forecasts, parcel size class, stop difficulty, and each driver's historical productivity.
- Algorithm. Predict per-stop service time with an ML model (such as gradient boosting), then pass the predictions to a constrained optimizer (integer or linear programming, or min-cost flow).
- Operational robustness.
- How you handle brand-new drivers with no history (cold start).
- How you protect the system against distribution shift.
- A fast rebalancing heuristic for last-minute spikes in volume or driver availability.
- End-to-end loop. Pseudocode for forecast, optimize, simulate, assign, and monitor, plus what the system does if the optimizer fails or times out.
State any assumptions about scale and latency, and explain the trade-offs behind your choices.
Hints
Hint 1
Decide what fairness means before modeling: equalizing predicted work hours is very different from equalizing parcel counts. Also plan against an upper quantile (e.g. P80) of service time rather than the mean.
Hint 2
Split the problem: group stops into small geographic clusters, assign clusters to drivers with an integer program, then sequence each route with a routing heuristic. This keeps the optimization tractable at tens of thousands of stops.
Hint 3
For the operational pieces, think about shrinkage toward a cohort average for new drivers, monitoring quantile coverage to detect drift, a freeze-and-repair heuristic for spikes, and a deterministic greedy fallback when the solver fails.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Scope and success metrics
Assume one station and one shift: about 250 drivers, 40k parcels, roughly 25k stops, and 8 to 10 hour shifts. The full plan is due about an hour before dispatch, so the solver gets 5 to 10 minutes. Mid-shift rebalancing must finish in under 30 seconds.
- Primary metric: on-time delivery rate.
- Secondary metrics: overtime hours, miles driven, workload fairness, and the rate at which dispatchers override the plan (a good proxy for trust).
- Fairness is defined on predicted work hours, not parcel count. Fifty parcels in one apartment block and fifty rural stops are very different workloads. Stating this up front matters.
2. Decomposition
A full vehicle-routing problem with time windows over 25k stops cannot be solved in minutes, so split it:
- Group stops into geo-contiguous micro-clusters (for example H3 cells with 10 to 20 stops).
- Assign clusters to drivers with an integer program (binary x_ck: cluster k goes to driver c).
- Sequence each driver's clusters with a VRPTW heuristic (local search, or OR-Tools).
3. Objective
maximize Σ OnTime_c − λ·Σ Overtime_c − μ·Σ Distance_c − ν·(W_max − W_min)
- On-time: inside the MIP, use a linear proxy, namely a penalty when the P80 route duration exceeds the shift. The true probability is estimated later by simulation.
- Overtime: max(0, P80 route hours − shift length).
- Fairness: a min-max spread penalty, plus a hard band around mean workload, e.g. (1−δ)·W̄ ≤ W_c ≤ (1+δ)·W̄ with δ ≈ 0.15.
- Weights: agree λ, μ, ν with operations so trade-offs are explicit (for example, one overtime hour is worth about 2 points of on-time rate).
4. Constraints
| Constraint | Treatment |
|---|---|
| Coverage | Each cluster is assigned once or marked unassigned with a large penalty (sent to flex drivers or deferred). |
| Shift hours | Sum of P80 service plus travel time ≤ shift length + overtime slack. |
| Capacity | Weight and volume sums within vehicle limits. |
| Skills | Variable fixed to 0 when a driver lacks a required certification (hazmat, lift gate, gated access, EV range). |
| Contiguity | Distance-to-anchor penalty; optional adjacency constraints. |
| Delivery windows | Enforced in sequencing; the MIP only adds aggregate checks (e.g. number of morning-window stops per driver). |
| Stop-time variability | Use quantiles from the model, not means. |
5. Data and models
Service-time model: gradient boosting (LightGBM) with quantile loss at P50 and P80.
- Stop features: parcel count, size/weight class, building type, floor, elevator, access code, signature requirement, historical median dwell at the address, parking difficulty.
- Context: hour, day of week, weather, peak-season flag.
- Driver: tenure, vehicle type, and a shrunken productivity effect.
Travel-time model: segment-level forecasts by hour and weather, aggregated to cluster-to-cluster times, plus stop density.
Labels: arrive-to-deliver scan timestamps, with GPS-noise outliers removed.
6. End-to-end loop
def plan_shift(station, shift):
pkgs, couriers = load_manifest(station, shift), load_roster(station, shift)
clusters = build_h3_clusters(pkgs, target_stops=15)
# 1. Forecast
svc = service_model.predict_quantiles(clusters, couriers, q=[.5, .8])
travel = travel_model.predict(clusters, shift.start, weather_forecast())
if drift_monitor.alarm():
svc = inflate(svc, conformal_scale())
# 2. Optimize (time-limited, warm-started)
plan = None
try:
plan = solve(build_mip(clusters, couriers, svc, travel),
time_limit=300, warm_start=yesterday_template(station), mip_gap=0.02)
except SolverError:
log_incident()
if plan is None or not plan.feasible:
plan = greedy_fallback(clusters, couriers, svc, travel)
routes = {c: sequence_vrptw(plan.clusters_for(c), time_limit=5) for c in couriers}
# 3. Simulate
for _ in range(3):
sims = monte_carlo(routes, svc, travel, n=500)
risky = [c for c in couriers if sims.p_on_time(c) < 0.95]
if not risky: break
routes = local_search_relocate(routes, risky, budget_s=20)
# 4. Assign
publish(routes, require_dispatcher_ack=True)
# 5. Monitor
stream_scans(lambda e: rebalance_if_needed(routes, e))
log_outcomes(routes, actual_scans) # feeds retraining
7. Cold-start drivers
Use hierarchical shrinkage on the productivity effect:
effect_c = (n_c·mean_c + k·cohort_mean) / (n_c + k)
- The cohort is tenure band × vehicle × station; k is roughly 20 stops of evidence.
- For the first few shifts, cap load near 85% of standard, prefer dense low-difficulty clusters close to the station, and plan against P90 instead of P80.
- Update the posterior after every shift so the driver converges within about a week.
- Never one-hot encode driver IDs; feed the shrunken effect so the model generalizes.
8. Distribution shift
Sources: peak season, new buildings, extreme weather, new stations, policy changes.
- Detect: PSI on key features, rolling residuals, and quantile coverage (does P80 really cover about 80%?). Alarm below roughly 75%.
- Adapt: daily conformal recalibration, weekly recency-weighted retraining, explicit peak/holiday features, and station-level priors for unseen areas.
- Robust planning: plan on upper quantiles and widen buffers automatically when an alarm fires, trading some efficiency for reliability.
- Evaluation: use switchback tests (alternate days or stations), not per-driver A/B tests. Drivers share a parcel pool, so per-driver randomization breaks the no-interference assumption.
9. Fast rebalancing for spikes
Triggers: late trucks, call-outs, same-day surges. Re-solving the MIP is too slow and too disruptive.
- Freeze routes that are loaded or departed; only touch unloaded clusters and available drivers.
- Compute each driver's predicted slack (shift length − P80 load).
- Greedy repair: move the cluster with the highest overload contribution to the neighboring driver with the most slack, subject to skills and capacity. Repeat until no driver is overloaded or the budget is spent.
- Limit the number of changed assignments to avoid confusing drivers, and flag leftovers for flex drivers or deferral.
This runs in seconds because it is local and incremental.
10. Fallback when the optimizer fails
Use a layered fallback: (1) return the best incumbent solution at the time limit; (2) if none exists, apply a greedy heuristic that sorts clusters by difficulty and assigns each to the feasible driver with the lowest current predicted load; (3) if that is infeasible, reuse the last similar day's template and escalate to a dispatcher. Always log the incident and alert.
Common mistakes
- Equalizing parcel counts instead of predicted hours.
- Planning on mean service time, which guarantees overtime about half the time.
- Treating the optimizer as the whole system and skipping simulation and monitoring.
- Randomizing experiments at the driver level.
- Having no fallback path, so a solver failure blocks dispatch.