首页 > 解决方案 > 如何在 Google OR-Tools 中设置每条路线的最小位置?

问题描述

我正在尝试限制每辆车访问的最小位置,我已经成功实施了最大位置约束,但在确定最小位置时遇到了问题。我的最大位置代码:

def counter_callback(from_index):
    """Returns 1 for any locations except depot."""
    # Convert from routing variable Index to user NodeIndex.
    from_node = manager.IndexToNode(from_index)
    return 1 if (from_node != 0) else 0;

counter_callback_index = routing.RegisterUnaryTransitCallback(counter_callback)

routing.AddDimensionWithVehicleCapacity(
    counter_callback_index,
    0,  # null slack
    [16,16,16],  # maximum locations per vehicle
    True,  # start cumul to zero
    'Counter')

标签: pythonconstraint-programmingor-toolsvehicle-routing

解决方案


您不应该对节点数量进行硬性限制,因为这很容易使模型不可行。

推荐的方法是创建一个只计算访问次数的新维度(评估器始终返回 1),然后在每辆车的末尾推动该维度的累积量的软下限。


推荐阅读