问题描述
我正在尝试限制每辆车访问的最少位置,我已成功实现最大位置约束,但在确定最少位置时遇到问题。我的最大位置代码:
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,# null slack
[16,16,16],# maximum locations per vehicle
True,# start cumul to zero
'Counter')
解决方法
您不应该对节点数量设置硬性限制,因为它很容易使模型不可行。
推荐的方法是创建一个只计算访问次数的新维度(评估器总是返回 1),然后在每辆车的末尾对该维度的累积量推一个软下限。