首页 > 解决方案 > 使用 or-tools 的不同车辆类型的 VRP

问题描述

我正在尝试使用 OR-Tools 优化最佳路线 VRP。我在文档中找不到正确的功能。 

案例:有些客户只接受皮卡车,有些只接受卡车,有些接受卡车、皮卡和货车。有一个单一的仓库位置,车辆应通过接受的车辆向合适的客户运送订单。

我拥有的那些车辆

在此处输入图像描述

客户接受这些车辆类型

在此处输入图像描述

这些车辆应定向到适当的客户。 

您对此有什么想法或有任何或工具功能吗?

标签: pythonor-toolsvehicle-routing

解决方案


您可以使用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)

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

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


推荐阅读