AI-generated Key Takeaways
-
The Route Optimization API returns optimized routes for vehicles, assigning shipments and potentially skipping some based on constraints and costs.
-
The API response includes
routesfor each vehicle, detailing their assigned shipments, start and end times, along with aggregatedmetricsfor the entire solution. -
Shipments that cannot be performed within the specified constraints or are too costly are listed in
skippedShipments. -
validationErrorshighlight issues with the request when usingVALIDATE_ONLYsolving mode, aiding in debugging. -
Each route includes
visitsrepresenting shipment pickups and deliveries, andtransitionsdetailing travel between them, with associated metrics like duration and distance.
The Route Optimization API returns routes for vehicles in the corresponding request. Shipments are assigned to vehicles, or may be skipped depending on the request's properties.
An OptimizeToursResponse message (REST, gRPC) has two main top-level
properties:
routes[]are the routes for each vehicle with its assigned shipments. EachRoutecontains metrics reflecting properties of that individual route.metricsare aggregated metrics for the entire response, across all vehicles and route plans. Top-level metrics contain the same properties as per-Route metrics, with values aggregated across all Routes.
Some properties may not always be populated depending on optimization results:
skippedShipments[]lists shipments that are not performed by any vehicle. A shipment can be skipped if it cannot be performed within specified constraints or if the cost to perform the shipment exceeds its penalty cost. For example, if a shipment's pickup or delivery has a very narrowtimeWindowit may not be possible or cost effective for a vehicle to perform the visit during the required time window.validationErrors[]specifies errors that makes the request invalid or impossible to solve when the request'ssolvingModeis set toVALIDATE_ONLY. In normalDEFAULT_SOLVEmode, validation errors will appear in an error message instead of the response body. Note thatVALIDATE_ONLYsolving mode can report multiple errors at once, which is useful for quickly debugging requests.
Route properties
Each routes[] entry is a ShipmentRoute message (REST, gRPC). Each
ShipmentRoute represents the route assignment for a particular vehicle from
the request. Important ShipmentRoute properties related to its corresponding
Vehicle include:
vehicleIndexis the zero-based index of theVehiclein the corresponding request message. REST responses omit this property when the value is zero.vehicleStartTimeis the time when the vehicle must begin its route.vehicleEndTimeis the time when the vehicle is expected to finish its route.
In a response, routes will look like:
{
"routes": [
{
"vehicleStartTime": "2024-02-13T00:00:00Z",
"vehicleEndTime": "2024-02-13T00:38:42Z",
"visits": [
...
],
"transitions": [
...
],
"metrics": {
...
},
...
}
],
...
}
Each ShipmentRoute includes an ordered list of visits that the vehicle will
complete. Each Visit (REST, gRPC) represents a VisitRequest
(REST, gRPC) from the corresponding request. Important Visit
properties include:
shipmentIndexis the zero-based index of the shipment this visit belongs to in the corresponding request.isPickupis true when a visit is a pickup and false when a visit is a delivery. REST responses omit this property when the value is false.visitRequestIndexis the zero-based index of theVisitRequestfromShipment.pickupsorShipment.deliveriesin the corresponding request that theVisitrepresents. REST responses omit this property when the value is zero.startTimeis the time the visit is expected to start.loadDemandsmaps load type to load amount demanded to complete theVisit. Load amounts are negative for delivery visits, representing load being removed from the vehicle.
An example Visit looks like:
{
"routes": [
{
...
"visits": [
{
"isPickup": true,
"startTime": "2024-02-13T00:00:00Z",
"detour": "0s"
},
...
],
},
...
],
...
}
Each ShipmentRoute includes an ordered list of transitions that represent
travel between visits for a given vehicle. Important Transition message
(REST, gRPC) properties include:
startTimeis the time at which the vehicle will start to perform the transition.travelDurationis the duration for which the vehicle must travel to complete the transition.travelDistanceMetersis the distance in meters that the vehicle must travel to complete the transition.trafficInfoUnavailableindicates whether traffic data is available for the transition.waitDurationrepresents idle time the vehicle spends waiting before it can start its nextVisit. This may be incurred due to thestart_timeof the followingVisit.totalDurationis the total duration of the transition, including travel, wait, break, and delay times.vehicleLoadsmaps load type to load amount carried by the vehicle during this transition.
An example Transition looks like:
{
"routes": [
{
...
"transitions": [
...
{
"travelDuration": "1171s",
"travelDistanceMeters": 9004,
"waitDuration": "0s",
"totalDuration": "1171s",
"startTime": "2024-02-13T00:00:00Z"
},
...
],
...
}
],
...
}
For more information on the relationship between vists and transitions, see
Pickup and Delivery Stop Order Optimization and the ShipmentRoute
reference documentation (REST, gRPC). For more information on the
routePolyline and routeToken properties of a Transition message, see
Transition Polylines and Route Tokens.
Metrics properties
The Metrics message (REST, gRPC) summarizes the entire solution.
Some important Metrics properties include:
totalCostis the total cost incurred in completing the routes. Read more about costs in Cost Model Parameters.usedVehicleCountis the total number of vehicles used in the solution. Vehicles may have empty routes when the optimizer determines that their use is unnecessary.skippedMandatoryShipmentCountis the number of skipped shipments that are "mandatory." A mandatory shipment doesn't specify apenaltyCostthat is incurred if the shipment is skipped. Mandatory shipments can still be skipped if their performance is not feasible under specified constraints. Read more about costs in Cost Model Parameters.
Additional metrics are reported as AggregatedMetrics messages (REST,
gRPC). The AggregatedMetrics message type is used for the
Metrics.aggregatedRouteMetrics property and for the ShipmentRoute.metrics
property Metrics.aggregatedRouteMetrics contains metrics aggregated across all
ShipmentRoutes in the OptimizeToursResponse. Each ShipmentRoute.metrics
property contains metrics for that specific ShipmentRoute.
Important AggregatedMetrics properties include:
performedShipmentCountis the number of shipments performed by vehicles over their entire routes.travelDurationis the total time the vehicles spend in transit while completing their routes.waitDurationis the total time the vehicles spend waiting while completing their routes.delayDurationis the total delay time for the vehicles. This is usually zero unlessTransitionAttributesare used in the request.breakDurationis the total time the vehicles spend in breaks while completing their routes.visitDurationis the total time the vehicles spend performing visits while completing their routes. This is effectively the sum of allVisitRequest.durationvalues forVisitRequests corresponding toVisits assigned to applicable vehicle.totalDurationis the total duration required to complete the vehicles' routes.travelDistanceMetersis the total distance traveled by the vehicles while completing their routes.maxLoadsmaps load types to the maximum load amount carried by the vehicles at any point on their routes.
An example Metrics message looks like:
{
"routes": [
...
],
"metrics": {
"aggregatedRouteMetrics": {
"performedShipmentCount": 1,
"travelDuration": "2322s",
"waitDuration": "0s",
"delayDuration": "0s",
"breakDuration": "0s",
"visitDuration": "0s",
"totalDuration": "2322s",
"travelDistanceMeters": 18603
},
"usedVehicleCount": 1,
"earliestVehicleStartTime": "2024-02-13T00:00:00Z",
"latestVehicleEndTime": "2024-02-13T00:38:42Z",
"totalCost": 18.603,
"costs": {
"model.vehicles.cost_per_kilometer": 18.603
}
}
}
Complete example
A complete example response for the request from Construct a Request looks like:
{
"routes": [
{
"vehicleStartTime": "2024-02-13T00:00:00Z",
"vehicleEndTime": "2024-02-13T00:38:42Z",
"visits": [
{
"isPickup": true,
"startTime": "2024-02-13T00:00:00Z",
"detour": "0s"
},
{
"startTime": "2024-02-13T00:19:31Z",
"detour": "0s"
}
],
"transitions": [
{
"travelDuration": "0s",
"waitDuration": "0s",
"totalDuration": "0s",
"startTime": "2024-02-13T00:00:00Z"
},
{
"travelDuration": "1171s",
"travelDistanceMeters": 9004,
"waitDuration": "0s",
"totalDuration": "1171s",
"startTime": "2024-02-13T00:00:00Z"
},
{
"travelDuration": "1151s",
"travelDistanceMeters": 9599,
"waitDuration": "0s",
"totalDuration": "1151s",
"startTime": "2024-02-13T00:19:31Z"
}
],
"metrics": {
"performedShipmentCount": 1,
"travelDuration": "2322s",
"waitDuration": "0s",
"delayDuration": "0s",
"breakDuration": "0s",
"visitDuration": "0s",
"totalDuration": "2322s",
"travelDistanceMeters": 18603
},
"routeCosts": {
"model.vehicles.cost_per_kilometer": 18.603
},
"routeTotalCost": 18.603
}
],
"metrics": {
"aggregatedRouteMetrics": {
"performedShipmentCount": 1,
"travelDuration": "2322s",
"waitDuration": "0s",
"delayDuration": "0s",
"breakDuration": "0s",
"visitDuration": "0s",
"totalDuration": "2322s",
"travelDistanceMeters": 18603
},
"usedVehicleCount": 1,
"earliestVehicleStartTime": "2024-02-13T00:00:00Z",
"latestVehicleEndTime": "2024-02-13T00:38:42Z",
"totalCost": 18.603,
"costs": {
"model.vehicles.cost_per_kilometer": 18.603
}
}
}