I remember one of my past threads where Mizuk had suggested implementing a Gate node. Gate node is extremely useful where we can easily add many useful constraints.I would like to share my understanding of Gate node and how I am planning to implement it in my current program.
The idea of Gate node comes as - The vehicle can not directly access the pickup node or delivery node of a location. It has to go through the Gate node to pickup or delivery. The vehicle has to visit the exit gate node as well as leave a location. Every location has 2 gate nodes one for entering and another for the exit.
In order to implement a Gate node, I have taken an example of initial inputs so that I can explain how my current program works.
3 loads (Load 1, Load 2, Load3) and
2 locations (Location A and Location B)and
2 vehicles (Vehicle X, Vehicle Y).
My program produces one of the below solutions
Vehicle X takes Load 1 and Load 2
Vehicle Y takes Load 3.
I am duplicating nodes for each pickup and delivery load as below before calling routing.AddPickupAndDelivery function as below
Load 1 pickup - Location A delivery Location B [1,4]
Load 2 pickup - Location B delivery Location B. [2,5]
Load 3 pickup - Location B delivery Location B. [3,6]
data.pickups_deliveries = [[1,4], [2,5], [3,6]]
for request in data.pickups_deliveries:
pickup_index = manager.NodeToIndex(request[0])
delivery_index = manager.NodeToIndex(request[1])
routing.AddPickupAndDelivery(pickup_index, delivery_index)
If I want to implement a gate node, then I think I need to produce 2 gate nodes (one for entry and another for exit) for each pickup node and the same for each delivery node which will give me the following list of pairs
data.pickups_deliveries = [[10,1],
[11,2],
[12,3]
[1,13],
[2,14],
[3,15],
[16,4],
[17,5],
[18,6],
[4,19],
[5,20],
[6,21]]
From the above, node 10, node 11, node 12 to enter Location A and Node 13, node 14, node 15 to exit location A for pickups.
Node 16, node 17, node 18 to enter Location B, and Node 19, Node 20, and Node 21 to exit Location B for delivery.
(I also need to include gate nodes when generating distance and time matrixes. Distance between gate nodes in my case is zero. But once entered I can add rest time, service time etc once it enters any gate node in my time matrix.)
The vehicle can pick up multiple loads or re-enter the same location after drop off but any vehicle for example Enters from Node 10, it needs to stop re-enters Node 11 as the next node. The same is true for departure which gives me the following restriction lists when implementing the Gate node.
- Restriction in among Node 10, Node 11, and Node 12.
- Restrictions among Node 13, Node 14, Node 15
- Restrictions among Node 16, Node 17, Node 18
- Restrictions among Node 19, Node 20, Node 21
Please feel free to advise.
Kind Regards
Kazi