Google Cloud Optimization的optimizeTours未返回优化路由问题
Google Cloud Optimization optimizeTours API 路由优化问题
我正在使用Google Cloud Optimization的optimizeTours API进行车辆路由优化,API地址为https://cloudoptimization.googleapis.com/v1/projects/MY。
请求内容
{ "model": { "shipments": [ { "label": "987", "deliveries": [ { "arrivalLocation": { "latitude": -0.2034733, "longitude": -78.49189695 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "983", "deliveries": [ { "arrivalLocation": { "latitude": -0.20334675, "longitude": -78.490163733333 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "957", "deliveries": [ { "arrivalLocation": { "latitude": -0.20329959035475, "longitude": -78.489062200445 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "935", "deliveries": [ { "arrivalLocation": { "latitude": -0.20290136666667, "longitude": -78.490132566667 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "690", "deliveries": [ { "arrivalLocation": { "latitude": -0.2002005, "longitude": -78.4924999 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "910", "deliveries": [ { "arrivalLocation": { "latitude": -0.20324258333333, "longitude": -78.49150005 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "729", "deliveries": [ { "arrivalLocation": { "latitude": -0.19757333333333, "longitude": -78.481011666667 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "719", "deliveries": [ { "arrivalLocation": { "latitude": -0.19855, "longitude": -78.485678333333 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "720", "deliveries": [ { "arrivalLocation": { "latitude": -0.19947166666667, "longitude": -78.486215 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] }, { "label": "721", "deliveries": [ { "arrivalLocation": { "latitude": -0.19409166666667, "longitude": -78.491781666667 }, "duration": "300s", "timeWindows": [ { "startTime": "2023-10-21T07:00:00-05:00", "endTime": "2023-10-21T17:00:00-05:00" } ] } ] } ], "vehicles": [ { "loadLimits": { "weight": { "maxLoad": 5000 } }, "startLocation": { "latitude": -0.192298, "longitude": -78.4877 }, "endLocation": { "latitude": -0.192298, "longitude": -78.4877 } } ], "globalStartTime": "2023-10-21T07:00:00-05:00", "globalEndTime": "2023-10-21T17:00:00-05:00" } }
API返回内容
{ "routes": [ { "vehicleStartTime": "2023-10-21T12:00:00Z", "vehicleEndTime": "2023-10-21T13:36:13Z", "visits": [ { "shipmentIndex": 9, "startTime": "2023-10-21T12:03:26Z", "detour": "0s", "shipmentLabel": "721" }, { "shipmentIndex": 8, "startTime": "2023-10-21T12:14:23Z", "detour": "581s", "shipmentLabel": "720" }, { "shipmentIndex": 7, "startTime": "2023-10-21T12:23:57Z", "detour": "1116s", "shipmentLabel": "719" }, { "shipmentIndex": 6, "startTime": "2023-10-21T12:31:52Z", "detour": "1557s", "shipmentLabel": "729" }, { "shipmentIndex": 5, "startTime": "2023-10-21T12:43:53Z", "detour": "2214s", "shipmentLabel": "910" }, { "shipmentIndex": 4, "startTime": "2023-10-21T12:52:41Z", "detour": "2831s", "shipmentLabel": "690" }, { "shipmentIndex": 3, "startTime": "2023-10-21T13:03:45Z", "detour": "3394s", "shipmentLabel": "935" }, { "shipmentIndex": 2, "startTime": "2023-10-21T13:09:54Z", "detour": "3773s", "shipmentLabel": "957" }, { "shipmentIndex": 1, "startTime": "2023-10-21T13:16:37Z", "detour": "4215s", "shipmentLabel": "983" }, { "startTime": "2023-10-21T13:24:04Z", "detour": "4676s", "shipmentLabel": "987" } ], "vehicleDetour": "5773s" } ], "metrics": { "aggregatedRouteMetrics": { "performedShipmentCount": 10, "travelDuration": "2773s", "waitDuration": "0s", "delayDuration": "0s", "breakDuration": "0s", "visitDuration": "3000s", "totalDuration": "5773s", "travelDistanceMeters": 11105 }, "usedVehicleCount": 1, "earliestVehicleStartTime": "2023-10-21T12:00:00Z", "latestVehicleEndTime": "2023-10-21T13:36:13Z" } }
问题
返回结果仅按shipmentIndex降序排列,未进行路由优化;提交60个运单的请求时,结果同样按shipmentIndex从59到1降序返回。如何操作才能让API返回优化后的路由?
解决方案
1. 添加搜索模式参数
在请求的顶层添加searchMode字段,指定API使用的优化算法级别:
{ "searchMode": "SEARCH_MODE_ADVANCED", "model": { // 原model内容 } }
SEARCH_MODE_SIMPLE:适合小规模运单,优化速度快;SEARCH_MODE_ADVANCED:启用更复杂的启发式算法,适合多运单场景,优化效果更优。
2. 补充车辆速度参数
为车辆配置speed(单位:米/秒),帮助API更精准计算行驶时间和距离:
"vehicles": [ { "loadLimits": { "weight": { "maxLoad": 5000 } }, "startLocation": { "latitude": -0.192298, "longitude": -78.4877 }, "endLocation": { "latitude": -0.192298, "longitude": -78.4877 }, "speed": 10.0 // 根据实际车辆速度调整,比如城市道路可取8-12米/秒 } ]
3. 明确优化目标
在model中添加objective字段,定义优先优化的指标(如行驶距离、时间):
"model": { "objective": { "costs": [ { "travelDistance": { "coefficient": 1.0 // 权重越高,越优先最小化行驶距离 } }, { "travelDuration": { "coefficient": 0.5 // 次优先最小化行驶时间 } } ] }, // 原model其他内容 }
4. 检查冗余参数
确保请求中没有allowSplitting等会干扰运单完整分配的参数,若有则移除,保证每个运单由单一车辆完成。
这些配置会触发API执行真正的路径优化,而非简单的顺序分配,最终返回基于距离/时间最优的路由结果。
内容的提问来源于stack exchange,提问作者Alexey Ignatyev
相关产品推荐
相关产品推荐

