OptimizeToursRequest
消息(REST、gRPC)包含与费用相关的多个属性。这些费用参数共同代表请求的费用模型。费用模型会捕获请求的许多高级优化目标,例如:
- 优先使用更快的
Vehicle
路线,而不是更短的路线,反之亦然 - 确定提交
Shipment
的费用是否值得Shipment
完成 - 仅在这样做经济高效时,才在时段内进行上门取件和送货
查看包含费用的请求示例
{ "model": { "globalStartTime": "2023-01-13T16:00:00-08:00", "globalEndTime": "2023-01-14T16:00:00-08:00", "shipments": [ { "deliveries": [ { "arrivalLocation": { "latitude": 37.789456, "longitude": -122.390192 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 100.0 }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.789116, "longitude": -122.395080 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 5.0 }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.795242, "longitude": -122.399347 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 50.0 } ], "vehicles": [ { "endLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "startLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "costPerHour": 40.0, "costPerKilometer": 10.0 } ] } }
Vehicle
个费用属性
Vehicle
消息(REST、gRPC)具有多个费用属性:
Vehicle.cost_per_hour
:表示车辆每小时的运营费用(含公交、等待、造访和休息时间)。Vehicle.cost_per_kilometer
:表示车辆每公里移动的费用。Vehicle.cost_per_traveled_hour
:表示仅在运输期间运营车辆的费用,不包括等待、拜访和休息时间。
借助这些费用参数,优化器可以权衡时间与行驶距离。优化路线产生的费用会以 metrics.costs
的形式显示在响应消息中:
随着 costPerHour
的增加,优化器会尝试找到更快的路线,但这些路线可能不是最短的路线。在此示例中,最快路线恰好是最短路线,因此更改费用参数几乎没有影响。
Shipment
个费用属性
Shipment
消息(REST、gRPC)还包含多个费用参数:
Shipment.penalty_cost
表示跳过发货所产生的费用。Shipment.VisitRequest.cost
表示特定上门取件或送货服务的费用,主要用于在单个配送订单的多个上门取件或送货选项之间进行费用权衡。
Shipment
费用参数与 Vehicle
费用参数使用相同的无量纲单位。如果完成 Shipment
所产生的费用超过了其违规处罚费用,则 Shipment
不会包含在任何 Vehicle
的路线中,而是会显示在响应消息的 skipped_shipments
列表中。
ShipmentModel
费用属性
ShipmentModel
消息(REST、gRPC)包含单个费用属性 globalDurationCostPerHour
。此费用是根据所有车辆完成 ShipmentRoute
所需的总时间计算得出的。提高 globalDurationCostPerHour
会优先提前完成所有配送。
路线优化响应费用属性
OptimizeToursResponse
消息(REST、gRPC)具有费用属性,表示完成 ShipmentRoute
过程中产生的费用。metrics.costs
和 metrics.totalCost
属性表示响应中所有路线产生的费用单位数。每个 routes
条目都有 routeCosts
和 routeTotalCosts
属性,分别表示该特定路线的费用。
查看包含费用的示例请求响应
{ "routes": [ { "vehicleStartTime": "2023-01-14T00:00:00Z", "vehicleEndTime": "2023-01-14T00:28:22Z", "visits": [ { "isPickup": true, "startTime": "2023-01-14T00:00:00Z", "detour": "0s" }, { "shipmentIndex": 2, "isPickup": true, "startTime": "2023-01-14T00:02:30Z", "detour": "150s" }, { "startTime": "2023-01-14T00:08:55Z", "detour": "150s" }, { "shipmentIndex": 2, "startTime": "2023-01-14T00:21:21Z", "detour": "572s" } ], "transitions": [ { "travelDuration": "0s", "waitDuration": "0s", "totalDuration": "0s", "startTime": "2023-01-14T00:00:00Z" }, { "travelDuration": "0s", "waitDuration": "0s", "totalDuration": "0s", "startTime": "2023-01-14T00:02:30Z" }, { "travelDuration": "235s", "travelDistanceMeters": 795, "waitDuration": "0s", "totalDuration": "235s", "startTime": "2023-01-14T00:05:00Z" }, { "travelDuration": "496s", "travelDistanceMeters": 1893, "waitDuration": "0s", "totalDuration": "496s", "startTime": "2023-01-14T00:13:05Z" }, { "travelDuration": "171s", "travelDistanceMeters": 665, "waitDuration": "0s", "totalDuration": "171s", "startTime": "2023-01-14T00:25:31Z" } ], "metrics": { "performedShipmentCount": 2, "travelDuration": "902s", "waitDuration": "0s", "delayDuration": "0s", "breakDuration": "0s", "visitDuration": "800s", "totalDuration": "1702s", "travelDistanceMeters": 3353 }, "routeCosts": { "model.vehicles.cost_per_kilometer": 33.53, "model.vehicles.cost_per_hour": 18.911111111111111 }, "routeTotalCost": 52.441111111111113 } ], "skippedShipments": [ { "index": 1 } ], "metrics": { "aggregatedRouteMetrics": { "performedShipmentCount": 2, "travelDuration": "902s", "waitDuration": "0s", "delayDuration": "0s", "breakDuration": "0s", "visitDuration": "800s", "totalDuration": "1702s", "travelDistanceMeters": 3353 }, "usedVehicleCount": 1, "earliestVehicleStartTime": "2023-01-14T00:00:00Z", "latestVehicleEndTime": "2023-01-14T00:28:22Z", "totalCost": 57.441111111111113, "costs": { "model.vehicles.cost_per_kilometer": 33.53, "model.vehicles.cost_per_hour": 18.911111111111111, "model.shipments.penalty_cost": 5 } } }
在示例响应中,顶级 metrics.costs
如下所示:
{
"metrics": {
...
"costs": {
"model.vehicles.cost_per_hour": 18.911111111111111,
"model.vehicles.cost_per_kilometer": 33.53,
"model.shipments.penalty_cost": 5
}
}
}
model.shipments.penalty_cost
值表示因跳过发货而产生的费用。skippedShipments
属性列出跳过了哪些运单。
在此示例中,系统仅会跳过示例请求中的 model.shipments[1]
。model.shipments[1]
的惩罚费用为 5 个单位,与示例响应中的总 model.shipments.penalty_cost
键相匹配。与 Vehicle
的 40.0 costPerHour
和 10.0 costPerKilometer
相比,该运输的 penaltyCost
较低,因此跳过该运输比完成该运输更具成本效益。
高级主题:费用和软约束条件
一些 OptimizeToursRequest
消息(REST、gRPC)属性表示软约束条件,即如果无法满足这些约束条件,则会产生费用。
例如,车辆 LoadLimit
(REST、gRPC)约束具有 softMaxLoad
和 costPerUnitAboveSoftMax
属性。总的来说,这些进程产生的费用与超过 softMaxLoad
的加载单元成正比,这样,只有在从费用的角度来看,这样才能超出限制。
同样,TimeWindow
约束条件(REST、gRPC)具有 soft_start_time
和 soft_end_time
属性,相应的 cost_per_hour_before_soft_start_time
和 cost_per_hour_after_soft_end_time
会根据受约束事件相对于 TimeWindow
的发生时间而产生。
与所有成本模型参数一样,软约束条件成本采用与其他成本参数相同的无量纲单位表示。
负载需求和限制中详细介绍了 LoadLimit
约束条件。上门取件和送货时间范围限制中详细介绍了 TimeWindow
约束条件。