You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Route Optimization API实现邻近站点的顺序访问?

Google Route Optimization API:邻近站点未被顺序访问的问题解决

我在使用Google Route Optimization API对单车辆的50个站点做路径优化时,发现有10个处于100米半径范围内的站点,优化后的路线并没有将它们顺序访问(附图略)。我尝试通过transition_attributes来实现邻近站点的连续访问,但配置后没有效果,目标是让这些邻近站点被顺序访问,无论它们在道路的哪一侧。

当前模型配置

{
    "shipments": [
        {
            "pickups": [
                {
                    "arrival_location": {"latitude": 22.63253, "longitude": 88.21828},
                    "label": "A26731",
                    "tags": ["grp_tag"],
                }
            ]
        },
        // More stops here
    ],
    "vehicles": [
        {
            "label": "cluster2",
            "cost_per_kilometer": 10.0,
            "cost_per_hour": 10.0,
            "start_location": {"latitude": 22.62791, "longitude": 88.231},
        }
    ],
    "global_duration_cost_per_hour": 100,
    "global_start_time": "2025-01-07T07:00:00",
    "global_end_time": "2025-01-07T23:00:00",
    "transition_attributes": [
        {
            "excluded_dst_tag": "grp_tag",
            "excluded_src_tag": "grp_tag",
            "distance_limit": {
                "soft_max_meters": 200,
                "cost_per_kilometer_below_soft_max": 1,
                "cost_per_kilometer_above_soft_max": 5000,
            },
        }
    ],
}

问题分析

当前transition_attributes的配置逻辑完全错误:excluded_src_tag和excluded_dst_tag的作用是排除带有指定标签的站点作为过渡的起点/终点,这意味着你设置的距离成本规则不会应用在带有grp_tag的站点之间,自然无法约束邻近站点的访问顺序。

解决方案

方案1:修正transition_attributes规则

移除排除标签,改用required_src_tag和required_dst_tag让规则仅作用于目标站点之间的过渡:

"transition_attributes": [
    {
        "required_src_tag": "grp_tag",
        "required_dst_tag": "grp_tag",
        "distance_limit": {
            "soft_max_meters": 200,
            "cost_per_kilometer_below_soft_max": 1,
            "cost_per_kilometer_above_soft_max": 5000,
        }
    }
]
  • required_src_tag和required_dst_tag限定规则仅适用于带grp_tag的站点之间的过渡
  • 当两个目标站点间距超过200米时,会触发极高的额外成本,迫使优化器优先将邻近的目标站点连续访问

方案2:直接批量分组站点

如果这些邻近站点必须连续访问,更直接的方式是将它们合并为一个shipment,API会自动处理组内站点的最优访问顺序:

{
    "shipments": [
        {
            "pickups": [
                {"arrival_location": {"latitude": 22.63253, "longitude": 88.21828}, "label": "A26731"},
                {"arrival_location": {"latitude": 22.63300, "longitude": 88.21850}, "label": "A26732"},
                // 剩余8个邻近站点
            ]
        },
        // 其他40个独立站点
    ]
}

这种方式强制API将组内站点作为连续序列访问,完全满足需求。

额外注意事项

  • 确保global_start_time和global_end_time使用ISO 8601格式字符串(如"2025-01-07T07:00:00"),API无法直接解析Python的datetime对象
  • 若使用方案1,需确认所有目标站点都已添加grp_tag标签,避免遗漏导致规则不生效

内容的提问来源于stack exchange,提问作者Darsh Patel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 19:47:03