python - 如何在 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')
解决方案
您不应该对节点数量进行硬性限制,因为这很容易使模型不可行。
推荐的方法是创建一个只计算访问次数的新维度(评估器始终返回 1),然后在每辆车的末尾推动该维度的累积量的软下限。
推荐阅读
- jquery - 使用 jquery 将 ID 设置为 div 并在单击按钮后显示 div
- reactjs - 当我在 map 命令中使用 if case 时,为什么会在 JSX 部分中得到意外的令牌?
- html - 与元素大小相关的 CSS
- c++ - 在类中声明一个静态指针
- python - flask-sqlalchemy 使用单表过滤多列
- android - 从数据库导入字符串时,android中的字符串比较失败
- r - 用 R 绘制 cox 回归的预测变量的二次关系
- angular - Angular 2 入门
- javascript - 使用 React-spring 淡出和卸载加载屏幕组件
- java - 通过代理绕过请求不支持 jaxws rs api