python - 使用 or-tools 的不同车辆类型的 VRP
问题描述
我正在尝试使用 OR-Tools 优化最佳路线 VRP。我在文档中找不到正确的功能。
案例:有些客户只接受皮卡车,有些只接受卡车,有些接受卡车、皮卡和货车。有一个单一的仓库位置,车辆应通过接受的车辆向合适的客户运送订单。
我拥有的那些车辆
客户接受这些车辆类型
这些车辆应定向到适当的客户。
您对此有什么想法或有任何或工具功能吗?
解决方案
您可以使用RoutingModel::VehicleVar(index)
Python 中的伪代码(使用 customer_id 作为 node_id)
# Vehicles list
trucks = [1, 3, 6, 7, 9, 10]
vans = [4, 5]
pickups = [2, 8]
# location list with a tuple (location, truck, van pickup)
locations = [
(1, True, True, True), # C-01
(2, True, True, False), # C-02
(3, True, False, False), # C-03
(4, True, True, True), # C-04
...
]
for location, truck_allowed, van_allowed, pickup_allowed in locations:
index = manager.NodeToIndex(location)
allowed_vehicles = [] # you can add -1 iff the location can be dropped
if truck_allowed:
allowed_vehicles.extend(trucks)
if van_allowed:
allowed_vehicles.extend(vans)
if pickup_allowed:
allowed_vehicles.extend(pickups)
routing.VehicleVar(index).SetValues(allowed_vehicles)
旁注:求解器车辆 ID 从 0 开始,但在这里我遵循了从 1 开始的车辆 ID 约定...
推荐阅读
- python - 尽管绑定了套接字,Python Packet Sniffer 不输出任何内容
- android - 为什么我来自 ContentValues 的 newUri 为空?以编程方式设置铃声
- c++ - Qt DownloadManager 在单独的线程块主 GUI
- mongodb - 聚合后的MongoDB匹配
- python - 如何在列之间比较值后删除行
- autotools - 我需要设置哪些标志才能将 SDL2_mixer 与外部库静态链接?
- multithreading - NoSuchSessionException:无效的会话 id - TestNG 并行 = 具有 PageObjects 的类
- sql - 聚合子查询
- excel - VBA代码,对一行中的单个单元格中的值求和,并与另一个单元格中的数字范围相加
- ios - 如何在 swift iOS 应用程序中创建简单的播放器