Instrucciones de origen · Vista previa de solo lectura
name
route-optimizer
description
Generate a production-grade Vehicle Routing Problem (VRP) solver using Google OR-Tools — supports CVRP (capacity), VRPTW (time windows), VRPPD (pickup + delivery), multi-depot, multi-trip, heterogeneous fleet, driver hours-of-service (HOS) compliance, and soft-vs-hard window constraints with penalty modeling. Input: stops CSV (lat/lng/demand/window) + vehicle config + depots. Output: optimized routes (one per vehicle), total miles/duration/cost, GeoJSON FeatureCollection for map rendering, OSRM/Mapbox-compatible turn-by-turn URLs, KPI report (utilization, on-time %, last-mile cost share). Last-mile delivery accounts for over 50% of total shipping cost — optimizing it is the highest-leverage logistics fix. TRIGGER on "route optimization", "VRP", "vehicle routing", "delivery routing", "last mile", "OR-Tools routing", "courier routes", "TSP/VRP", "dispatch optimization", or any user describing multi-stop dispatch.
Route Optimizer (OR-Tools VRP)
You generate a working route optimization pipeline. Last-mile delivery costs > 50% of total shipping in 2026 — squeezing it is where the savings live. The solver of choice is Google OR-Tools because it handles CVRP/VRPTW/VRPPD natively, is open-source, and scales to thousands of stops with disciplined heuristics.
Problem variant: Pure capacity (CVRP)? Time windows (VRPTW)? Pickup + delivery (VRPPD)? Multi-depot? Heterogeneous fleet?
Stop count: < 100 — exact solver. 100-1000 — OR-Tools with metaheuristics (Guided Local Search, ~30s-2min). > 1000 — split into clusters first then solve per cluster.
Distance/duration source: OSRM (free, self-host), Mapbox Matrix API (rate-limited, $0.50/1k requests), Google Distance Matrix (most accurate, pricey), Haversine (lat/lng, no traffic — only for sanity check).
Constraints: vehicle capacity (weight, volume, count), time windows (hard or soft), driver shift length, HOS compliance (US: 11hr drive / 14hr on-duty / 10hr rest), customer service time per stop, lunch breaks.
Objective: minimize total distance? Total duration? Vehicle count? Weighted blend? Default is duration-weighted.
Recovery:
If distance matrix is unavailable, fall back to Haversine + average speed factor (city: 25mph, suburb: 35mph, rural: 45mph) — mark output as "estimate, validate against real road network before dispatch."
If stop count > 1000, generate the cluster-first scaffold and warn user about runtime.
VALIDATION: Solver returns a feasible solution OR a clear "infeasible: {reason}" diagnostic, never an empty result.
============================================================
=== PHASE 4: HOS COMPLIANCE & SOFT WINDOWS ===
US DOT FMCSA rules for property-carrying drivers (49 CFR § 395.3):
11 hours max driving after 10 consecutive hours off-duty
14-hour on-duty window (driving + other on-duty)
30-min break required after 8 cumulative hours of driving
60 hours / 7 days OR 70 hours / 8 days
34-hour restart available
Model HOS as additional Time-dimension constraints with break activities. For long-haul, multi-day routes, split into legs with mandatory rest periods.
Soft time windows: instead of hard infeasibility, add a penalty cost per minute outside the window. Useful for VRPTW where some lateness is acceptable at a cost. Implement via Dimension.SetSoftUpperBound(index, soft_max, penalty_per_unit).
VALIDATION: HOS-enabled run produces routes with explicit break activities and ≤ 11 hours of drive per shift.
1. routes.geojson — FeatureCollection where each Feature is one vehicle's route (LineString) + stop Points with properties (sequence, arrival_time, service_time, demand_delivered). Renderable in Mapbox GL JS, Leaflet, kepler.gl.
2. kpi_report.md:
Total routes: N
Total stops: M
Total distance: X km (avg per route: Y km)
Total duration: X hr (avg per route: Y hr)
Vehicle utilization: (sum of capacity used) / (sum of capacity available) = X%
On-time stops: N/M = X%
Avg stops per route: X
Cost estimate: $X (at $Y/km)
3. turn-by-turn URLs — for each route, one URL the driver can open in Google Maps or Apple Maps with all stops pre-loaded. Mapbox Directions API for production navigation.
VALIDATION: GeoJSON validates against geojson.io. KPI numbers reconcile (sum of route distances = total).