How to solve driver's shift time using Google OR tools

129 views
Skip to first unread message

Madhumita Tripathy

unread,
May 10, 2023, 1:01:16 AM5/10/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 am requesting you if you can provide me some documents or sample code to include driver shift, then it will help me a lot.

Fuzzy Mind

unread,
May 14, 2023, 1:39:47 AM5/14/23
to or-tools-discuss
Checking "SetBreakIntervalsOfVehicle" might help you

Madhumita Tripathy

unread,
May 15, 2023, 2:56:24 AM5/15/23
to or-tools...@googlegroups.com
Thanks for your reply. I will explore  "SetBreakIntervalsOfVehicle" to manage driver shift management. Is there another way to resolve this issue?
I tried to add shift time as constraint in the time dimension as explained by Mizux
'''
for vehicle in range(manager.GetNumberOfVehicles()):
  start_index = routing.Start(vehicle)
  print(start_index)
  end_index = routing.End(vehicle)
  print(end_index)
  shift_start_time_window=data_model["shift_start_time_window"][vehicle]
  print(shift_start_time_window)
  shift_end_time_window=data_model["shift_end_time_window"][vehicle]
  print(shift_end_time_window)
  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
  MAX_SHIFT_DURATION=720
  routing.solver().Add(time_dimension.CumulVar(end_index) - time_dimension.CumulVar(start_index) <= MAX_SHIFT_DURATION) ''''

In that case I have taken 20 delivery stops and 1 depot. That means the total length of data is 21. Two driver working in two different shifts such as
                data_model['shift_start_time_window']=[[480,495],[900,915]]
                data_model['shift_end_time_window']=[[1020,1035],[1440,1455]]

The output of shift time constraint is

0
22
[480, 495]
[1020, 1035]
21
23
[900, 915]
[1440, 1455]

But I did not understand why the start and end index of the first driver is 0,22 and the second driver index is 21,23. 
How can I match this index with the index of the original dataframe(0,21).

Can anybody explain? There is a special request to @Mizux.



--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/3119c454-6443-40a2-a60f-db9483c3860fn%40googlegroups.com.

Fuzzy Mind

unread,
May 15, 2023, 3:43:38 AM5/15/23
to or-tools-discuss
It's not possible to explain until we see your code and data model

regards,
Fuzzy Mind

Madhumita Tripathy

unread,
May 25, 2023, 6:15:22 AM5/25/23
to or-tools-discuss
Sorry for the delay response. I am attaching .ipnyb file for your reference. I used fixed 10 min service time. Without driver shift code works well. But I am not able to integrate driver shift with main program. Please guide me.
driver_shift_OR_tools.ipynb
Reply all
Reply to author
Forward
0 new messages