具有多次行程的 OR-Tools CVRP

问题描述

我正在尝试使用 OR-Tools 的路由求解器来解决多行程电容 VRP。我需要的是

  • 一个车站,路线起点和终点在这里
  • 一个卸货地点(不同于仓库)
  • 为每个节点设置时间窗口和需求

所以车辆应该从每个节点取货,直到容量填满为止。然后去“卸货地点”,卸掉他们所有的重量,不断地收集节点的需求,直到达到时间限制或所有的货物都被收集起来。然后返回仓库。

CVRP Reload Example 看起来很近,但在我的情况下,在路线的尽头,车辆应该在仓库之前到达卸货地点。换句话说,车辆不能带负载去车站(起点、终点)。

示例:

0: Depot
1: Unloading Location
2,3,4,5,6,7: Nodes to pick up demand


0 > 2 > 3 > 4 > 1 (unload) > 5 > 6 > 7 > 1 (unload) > 0
0 > 2 > 3 > 4 > 1 (unload) > 5 > 6 > 7 > 0 This is the result cvrp_reload returns.

我对 or-tools 相当陌生,并试图弄清楚。如果您有任何想法,可以帮助我吗?

  • 我使用的是 Python 和 or-tools v8.2
  • 这是来自github的交叉帖子。

我认为,可以通过使用 count_dimension 在最后一点(在仓库之前卸载)之前实现前面的约束,但我不知道如何实现。

解决方法

只需添加

    # Vehicles must be empty upon arrival
    capacity_dimension = routing.GetDimensionOrDie("Capacity")
    for v in range(manager.GetNumberOfVehicles()):
        print(f"vehicle {v}")
        end = routing.End(v)
        #routing.solver().Add(capacity_dimension.CumulVar(end) == 0) # see comment below
        capacity_dimension.SetCumulVarSoftUpperBound(end,100_000)

可能的输出:

./2442_unload.py
...
I0417 23:53:02.181640 17437 search.cc:260] Solution #317 (372696,objective maximum = 4838552,time = 2969 ms,branches = 3223,failures = 940,depth = 33,MakeInactiveOperator,neighbors = 265820,filtered neighbors = 317,accepted neighbors = 317,memory used = 14.93 MB,limit = 99%)
I0417 23:53:20.290527 17437 search.cc:260] Solution #318 (469816,objective minimum = 372696,time = 2987 ms,branches = 3239,failures = 945,neighbors = 267395,filtered neighbors = 318,accepted neighbors = 318,limit = 99%)
I0417 23:53:21.045410 17437 search.cc:260] Solution #319 (469816,time = 2988 ms,branches = 3247,failures = 947,MakeActiveOperator,neighbors = 267415,filtered neighbors = 319,accepted neighbors = 319,limit = 99%)
I0417 23:53:22.304931 17437 search.cc:260] Solution #320 (372696,time = 2989 ms,branches = 3253,failures = 949,neighbors = 267464,filtered neighbors = 320,accepted neighbors = 320,limit = 99%)
I0417 23:53:30.987548 17437 search.cc:260] Finished search tree (time = 2998 ms,branches = 3259,failures = 982,neighbors = 268318,accepted neigbors = 320,memory used = 14.93 MB)
I0417 23:53:31.046630 17437 search.cc:260] End search (time = 2998 ms,speed = 1087 branches/s)
Objective: 372696
dropped orders: [25]
dropped reload stations: [3,5]
Route for vehicle 0:
 0 Load(0) Time(0,0) -> 20 Load(0) Time(75,506) -> 12 Load(3) Time(94,525) -> 14 Load(6) Time(119,550) -> 13 Load(10) Time(140,700) -> 8 Load(13) Time(159,1000) -> 0 Load(0) Time(237,1500)
Distance of the route: 2624m
Load of the route: 0
Time of the route: 237min

Route for vehicle 1:
 1 Load(0) Time(0,0) -> 19 Load(0) Time(2,182) -> 24 Load(3) Time(20,200) -> 26 Load(7) Time(42,400) -> 4 Load(15) Time(89,770) -> 7 Load(15) Time(92,773) -> 11 Load(0) Time(169,850) -> 17 Load(3) Time(188,959) -> 10 Load(11) Time(229,1000) -> 1 Load(0) Time(307,1500)
Distance of the route: 2648m
Load of the route: 0
Time of the route: 307min

Route for vehicle 2:
 2 Load(0) Time(0,0) -> 23 Load(0) Time(15,63) -> 22 Load(4) Time(37,85) -> 21 Load(7) Time(85,101) -> 9 Load(10) Time(104,120) -> 18 Load(0) Time(184,200) -> 16 Load(8) Time(226,600) -> 15 Load(12) Time(248,800) -> 6 Load(15) Time(268,1000) -> 2 Load(0) Time(346,1500)
Distance of the route: 2624m
Load of the route: 0
Time of the route: 346min

Total Distance of all routes: 7896m
Total Load of all routes: 0
Total Time of all routes: 890min

注意:我使用软约束,否则求解器更喜欢删除所有节点,并且永远不会设法逃离此解决方案搜索空间点。