提出包含装载成本的请求,以便优化器考虑车辆在访问之间承载的装载量。产生的费用取决于所携带的 ShipmentRoute.VehicleLoad
量以及过渡的距离或时长(分别使用 cost_per_kilometer
或 cost_per_traveled_hour
)。
包含负载费用的最简示例请求
以下是包含加载费用的请求的部分示例。在此示例中,单辆车可承载的总weightKg
负荷不得超过 1,000 千克,当承载的weightKg
负荷超过 500 千克时,每公里会产生 1 个单位的费用。
{ "model": { "vehicles": [{ "loadLimits": { "weightKg": { "maxLoad": "1000", "costPerKilometer": { "loadThreshold": "500", "costPerUnitAboveThreshold": 1 } } } }] } }
此示例的负载费用计算方式如下:
cost = max(carried load - load threshold, 0) * distance * cost per unit above threshold
因此,如果车辆载重 weightKg
600 行驶 10 公里,计算公式如下:
(600 - 500) * 10 * 1 = 1000 cost units
负荷成本可用于模拟各种概念,例如运输重物时车辆能耗增加,或车辆超载造成的车辆磨损。
另一个包含加载费用的请求示例
以下是另一个负载费用示例,该示例规定了高于和低于阈值的每单位行驶时间费用:
{ "model": { "vehicles": [{ "loadLimits": { "weightLbs": { "maxLoad": "1000", "costPerTraveledHour": { "loadThreshold": "900", "costPerUnitAboveThreshold": 10, "costPerUnitBelowThreshold": 1 }, }, } }] } }
此示例的负载费用计算方式如下:
cost = max(carried load - load threshold, 0) * time * cost per unit above threshold
+ min(carried load, load threshold) * time * cost per unit below threshold
因此,如果车辆以 950 的 weightLbs
负荷运行 5 小时,计算公式如下:
max(950 - 900, 0) * 5 * 10 + min(950, 900) * 5 * 1 = 7000
在此示例中,weightLbs
载荷费用的 load_threshold
接近 max_load
。如果车辆在行驶时负载过重,cost_per_unit_above_threshold
会应用较高的每小时行驶费用,从而惩罚可能会增加车辆磨损或消耗过多燃料的路线。cost_per_unit_below_threshold
会增加车辆所载每单位重量的费用(最高达到阈值),表示车辆载重越大,燃油消耗量就越高。
常见问题解答
以下是有关负载费用的一些常见问题解答:
问题 | 答案 |
---|---|
在哪里指定负载费用? | 在 Vehicle.LoadLimit 中指定负载费用。 |
如何将装载成本与货件相匹配? | 如果货件的装载需求类型与车辆的装载限制类型(例如重量或体积)相符,则该货件需支付装载费用。 如负载需求和限制中所述,负载类型是任意字符串。 |
如何表示负载费用? | 负载成本以过渡距离或时长表示。使用 cost_per_kilometer 指定按距离计算的费用,使用 cost_per_traveled_hour 指定按时长计算的费用。
|
何时收取加载费用? | 将车辆负荷与负荷成本的 load_threshold 进行比较。如果指定了 cost_per_unit_above_threshold ,则会根据车辆的负荷(高于 load_threshold )按比例增加费用,计算公式为 max(0, load - load_threshold) 。如果指定了 cost_per_unit_below_threshold ,则会根据车辆负载低于 load_threshold 的比例增加费用,计算公式为 min(load, load_threshold) 。
|
加载费用参数的默认值是多少? | load_threshold 、cost_per_unit_above_threshold 和 cost_per_unit_below_threshold 默认均为零。
|
负载费用以什么单位表示? | 加载费用与其他所有费用形参(例如 global_duration_cost_per_hour 或 Shipment.penalty_cost )一样,以相同的无量纲单位表示。
|
在响应中,我在哪里可以找到负载费用? | 产生的负载费用会显示在响应消息的 metrics 和 route_metrics 属性中。例如,产生的 cost_per_kilometer 将显示为 model.vehicles.load_limits.cost_per_kilometer 。
|
如需详细了解负载费用,请参阅参考文档 (REST、gRPC)。
示例:发出 OptimizeTours
请求
您还可以使用 REST 或 gRPC 发出 OptimizeTours
请求。
在发出请求之前,请将以下参数替换为适合您环境的值:
- 确保您已按照使用 OAuth 中的说明配置应用默认凭据。
将 PROJECT_NUMBER_OR_ID 设置为您的 Cloud 项目编号或 ID。
以下命令会向路线优化 API 发送
OptimizeTours
请求,并同步接收响应。curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeTours' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ --data @- << EOM { "model": { "shipments": [ { "deliveries": [ { "arrivalLocation": { "latitude": 37.789456, "longitude": -122.390192 }, "duration": "250s" } ], "penaltyCost": 100.0, "loadDemands": { "weightKg": { "amount": 50 } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.789116, "longitude": -122.395080 }, "duration": "250s" } ], "penaltyCost": 30.0, "loadDemands": { "weightKg": { "amount": 10 } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.795242, "longitude": -122.399347 }, "duration": "250s" } ], "penaltyCost": 50.0, "loadDemands": { "weightKg": { "amount": 80 } } } ], "vehicles": [ { "endLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "startLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "costPerHour": 40.0, "costPerKilometer": 10.0, "loadLimits": { "weightKg": { "maxLoad": "100", "costPerKilometer": { "loadThreshold": "15", "costPerUnitAboveThreshold": 1 } } } } ] } } EOM
请求完成后,您会收到一条回复消息。