Optimize route
optimize_routeCompute optimized stop order for one or more vehicles, respecting capacity and time windows, and return per-vehicle routes with arrival, wait, departure, distance, and unassigned stops.
Instructions
Order stops for one or more vehicles (TSP/VRP) starting at waypoints[startIndex], with optional capacity and time windows in minutes after route start. Returns per-vehicle stop order (waypoint indices) with arrival/wait/departure minutes, distance in km, time-window violations and unassigned stops. Uses straight-line distances unless useOsrm is true.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| closed | No | true = every vehicle returns to the depot; false = routes end at their last stop | |
| useOsrm | No | Use OSRM road distances and durations instead of straight-line estimates (network call) | |
| capacity | No | Per-vehicle capacity in the same unit as waypoint demand. Omit for unlimited | |
| waypoints | Yes | Stops including the depot at startIndex (2-200). With useOsrm the limit is OSRM_MAX_TABLE_SIZE (default 100) | |
| startIndex | No | Index in waypoints of the depot where every route starts; must be less than waypoints.length | |
| vehicleCount | No | Number of vehicles. Stops are split into balanced angular sectors around the depot | |
| averageSpeedKmh | No | Average speed in km/h used for travel times when useOsrm is false |