首页 > 解决方案 > ORTools:Multiple Vehicles:大型车辆不应该为低于给定需求的节点提供服务

问题描述

我已经在具有多种车辆类型的工作代码上定义了各种约束。现在,我想添加一个新的约束。

对于给定的车辆,它不应该为低于给定需求的节点提供服务。因此,当此约束应用于一种类型的车辆时,任何低于该需求的节点都将由其他车辆提供服务[没有此约束。]

需要帮忙。我目前坚持这一点。

2 种车辆的示例代码

for i in range(vehicle_type_1_starting_index, vehicle_type_1_ending_index):        
    # [my constraints here, setting arc costs etc]


for i in range(vehicle_type_2_starting_index, vehicle_type_2_ending_index):        
    # [my constraints here, setting arc costs etc]
    # NEW CONSTRAINT LIKE: routing.solver().Add((routing.ActiveVehicleVar(int(i)) * capacity_dimension.[? minimum demand each visited node ?] >= 20)

  1. 不确定如何继续设置约束,即 vehicle_type_2 不应为任何小于或等于 20 需求的节点提供服务。
  2. 也有未使用的车辆。因此它们的容量/需求将为 0,但这将与上述没有节点少于 20 个需求的约束相冲突。如何使其仅适用于二手车?

标签: pythonor-tools

解决方案


解决方案:

for node_index in range(len(nodes)): 
    if nodes[node_index] according to criteria:
        routing.SetAllowedVehiclesForIndex(list(allowed_vehicle_list)), node_index)

我刚刚禁止我的车辆类型 B 访问需求小于 X 的节点。它们由没有此类限制的车辆类型 A 访问。


推荐阅读