pythonor-toolsvehicle-routing

In or-tools, VRPTW, how can I incorporate the constraint that some stops should be visited by only one subset of vehicles?


vehicle 1 vehicle 2 vehicle 3 vehicle 4
node 1 1 1 0 0
node 2 0 1 1 0
node 3 0 0 1 1

As could be seen from the matrix, a node could only be served by a specified list of vehicles. Node 1 should be served by vehicle 1 or vehicle 2, but not vehicle 3 or vehicle 4.

I tried to modify the solution proposed here (In or-tools, VRPTW, how can I give each vehicle a different weight/score for each node?), but it didn't work. Is there any way to add this type of constraint to VRPTW.


Solution

    1. you can use routing.VehicleVar(node_index).RemoveValues([list of vehicle to remove])

    e.g. for node 1

    node_one_idx = manager.NodeToIndex(1)
    routing.VehicleVar(node_one_idx).RemoveValues([3, 4]) # forbidd vehicle 3 and 4
    

    note: vehicle index start at 0 so 3rd and 4th vehicle should be vehicle index 2 and 3...

    ref: https://github.com/google/or-tools/blob/5a3b2f304438dad72b3a877b26e9cf2d9cf6f8a2/ortools/constraint_solver/routing.h#L1499-L1501