使用ortools的不同车辆类型的VRP

2024-10-03 17:25:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用或工具优化VRP的最佳路径。我在documentation中找不到正确的函数

案例:有些客户只接受皮卡车,有些客户只接受皮卡车,有些客户同时接受皮卡车、皮卡车和货车。只有一个仓库位置,车辆应使用接受的车辆将订单发送给正确的客户

我的那些车

enter image description here

客户接受这些车型

enter image description here

应将这些车辆导向相应的客户

您对此有何想法,或是否有任何工具或功能


Tags: 工具函数订单路径客户documentation案例仓库
1条回答
网友
1楼 · 发布于 2024-10-03 17:25:19

您可以使用RoutingModel::VehicleVar(index)

Python中的伪代码(使用客户id作为节点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)

参考:https://github.com/google/or-tools/blob/b37d9c786b69128f3505f15beca09e89bf078a89/ortools/constraint_solver/routing.h#L1224-L1226

旁注:解算器车辆ID从0开始,但这里我遵循了从1开始的车辆ID约定

相关问题 更多 >