python - 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)
- 不确定如何继续设置约束,即 vehicle_type_2 不应为任何小于或等于 20 需求的节点提供服务。
- 也有未使用的车辆。因此它们的容量/需求将为 0,但这将与上述没有节点少于 20 个需求的约束相冲突。如何使其仅适用于二手车?
解决方案
解决方案:
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 访问。
推荐阅读
- python - 检测图像中最大的多边形?
- javascript - 使用带有对象的状态作为下拉菜单中的选项:REACT
- vue.js - Vue2、Vuex - 从一个地方在所有模块中使用 Axios
- ruby-on-rails - 将 Ruby on Rails 总和查询显示为数据透视表
- vb.net - 释放 COM 对象
- react-navigation - 作为模态导航到新屏幕
- java - Spring MVC 默认身份验证如何添加用户/注册
- php - 当我删除存储/图像文件夹的快速链接时,Laravel 文件上传出错
- docker - 在 docker 容器中设置活动的 gcloud 帐户
- testing - 可用于网站性能测试的好工具有哪些?