VRP with time windows

271 views
Skip to first unread message

Hanna Hamilton

unread,
Nov 22, 2021, 12:11:06 AM11/22/21
to or-tools-discuss
Hello - 

I have this time windows constraint:

for location_idx, time_window in enumerate(time_windows):
        index = manager.NodeToIndex(location_idx)
        time_dimension.CumulVar(index).SetRange(time_window[0], time_window[1])

Since it's a VRP, some time_windows are the hours that the stops are open, while other time_windows are the shifts of the drivers. Does this ensure that each stop is not visited outside its time_windows and each driver is not working outside their shift? 


Also, does solution.Value(time_dimension.CumulVar(current_index)) provide the arrival time at a given node? 

Mizux Seiha

unread,
Nov 22, 2021, 5:15:54 AM11/22/21
to or-tools-discuss
To manage vehicle driver's shift you should instead add constraint on vehicle start/end node

Something like this ?
```python
for vehicle in range(manager.GetNomberOfVehicles()):
  start_index = routing.Start(vehicle)
  end_index = routing.End(vehicle)
  time_dimension.CumulVar(start_index).SetRange(shift_start_time_window[0], shift_start_time_window[1])
  time_dimension.CumulVar(end_index).SetRange(shift_end_time_window[0], shift_end_time_window[1])
  # can also create some constraint on shift duration
  routing.solver().Add(time_dimension.CumulVar(end_index) - time_dimension.CumulVar(start_index) <= MAX_SHIFT_DURATION)
```

Hanna Hamilton

unread,
Nov 22, 2021, 2:42:15 PM11/22/21
to or-tools-discuss
Thank you for your response. For each shift, I just have a start and end time. So, the driver cannot start before their shift or finish after their shift. Does this also work?

for vehicle, time_window in enumerate(food_rescuer_time_windows):
        start_index = routing.Start(vehicle)
        end_index = routing.End(vehicle)
        time_dimension.CumulVar(start_index) >= time_window[0]
        time_dimension.CumulVar(end_index) <= time_window[1]

Madhumita Tripathy

unread,
May 9, 2023, 7:50:45 AM5/9/23
to or-tools-discuss
I have to include driver's shift timings in VRP problem with time window. For example, I have 5 drivers and 56 deliveries. Driver's shift timings are :

            data_model['shift_start_time_window']=[[480,495],[480,495],[480,495],[900,915],[900,915]]
            data_model['shift_end_time_window']=[[1020,1035],[1020,1035],[1020,1035],[1440,1455],[1440,1455]]

That means three drivers are working in the morning shift and two drivers are working in the evening shift. Among 56 deliveries 10 deliveries will be done in the morning shift, 10 deliveries will be done in the evening and rest can be done in any time. I fixed time window at each time widow like that
[["1",[495, 1020]], ["2",[495,1020]]],
[["11",[1035,1440]],["12",[1035,1440]]],
 [["21",[0,1440]],["22",[0,1440]]],

I am able to get result VRP with time window without any Driver's shift time from the document given in ( https://developers.google.com/optimization/routing/vrptw) but I am not getting any proper document with explanation which includes driver's shift.
I read above discussion and requesting you if you can provide me some documents or sample code to include driver shift, then it will help me a lot.
Reply all
Reply to author
Forward
0 new messages