How do you implement 44 hours of rest consecutively within 7 days period?
Prepare a CSV file, which should contain the shift name, shift start time, and shift duration minutes as in the following example.
At the end of the enumeration, also describe the off shift.
Matin,6:30,480
Journée,8:00,510
Après-midi,13:30,480
Nuit,20:45,600
Off,0:00,0
You can get the all patterns of 44 hours rest by reading the CSV file using the following project file
Specify the CSV file.
Specify a rest time of 44 hours.
The python code will appear on the right screen of the solving pane.
All of 44 hours pattern will be displayed on the pane.
Consecutive 44 Code Generation.
Matin → Off → Après-midi 47.0 hours
Matin → Off → Nuit 54.25 hours
Matin → Off → Off 57.5 hours
Journée → Off → Après-midi 45.0 hours
Journée → Off → Nuit 52.25 hours
Journée → Off → Off 55.5 hours
Après-midi → Off → Nuit 47.25 hours
Après-midi → Off → Off 50.5 hours
Off → Off → Matin 47.75 hours
Off → Off → Journée 49.25 hours
Off → Off → Après-midi 54.75 hours
Off → Off → Nuit 62.0 hours
Off → Off → Off 65.25 hours
So we constrain all of the sliding window of 7 days should include at least one pattern of the above.
###### Copy & paste from here
import sc3
def check_pat3(list44,person,day,patterns):
list=[]
if patterns==3:
for s in list44:
v0=sc3.GetShiftVar(person,day,s[0])
v1=sc3.GetShiftVar(person,day+1,s[1])
if s[2]!='*':#wild card
v2=sc3.GetShiftVar(person,day+2,s[2])
list.append(v0&v1&v2)
else:
list.append(v0&v1)
elif patterns==2:
S=set()
for s in list44:
word=s[0]+s[1]
if word in S:
continue
S.add(word)
v0=sc3.GetShiftVar(person,day,s[0])
v1=sc3.GetShiftVar(person,day+1,s[1])
list.append(v0&v1)
elif patterns==1:
S=set()
for s in list44:
if s[0] in S:
continue
S.add(s[0])
v0=sc3.GetShiftVar(person,day,s[0])
list.append(v0)
return sc3.Or(list)
def check_44h_sub(list44,person):
for day in FromStartDateMinus6:#-6 -5 -3 -2 -1 0(StartDate)
if day >=FinishDate-3:# 6 5 4 3 2 1 0 | :patterns 3
break # 6 5 4 3 2 1 |0 :patterns 2
# 6 5 4 3 2 |1 0:patterns 1
list=[]
#print(daydef[day],end=' ')
for i in range(0,7,1):
#print(daydef[day+i],end=' ')
if i>=3 and i<=4 and day+i==FinishDate-1:
print("FinishDate-1 ",person,daydef[day+i])
v=check_pat3(list44,person,day+i,2)
list.append(v)
elif i==4 and day+i==FinishDate:
print("FinishDate ",person,daydef[day+i])
v=check_pat3(list44,person,day+i,1)
list.append(v)
elif day+i<=FinishDate-2:
v=check_pat3(list44,person,day+i,3)
list.append(v)
s=staffdef[person]+' '+daydef[day]
#sc3.AddSoft(sc3.Or(list),s,7)
sc3.AddHard(sc3.Or(list),s)
def check_44h(list):
for person in A_Member_in_All:
check_44h_sub(list,person)
rest_pattern_list= [('Matin', 'Off', 'Après-midi'), ('Matin', 'Off', 'Nuit'), ('Matin', 'Off', 'Off'), ('Journée', 'Off', 'Après-midi'), ('Journée', 'Off', 'Nuit'), ('Journée', 'Off', 'Off'), ('Après-midi', 'Off', 'Nuit'), ('Après-midi', 'Off', 'Off'), ('Off', 'Off', '*')]
[('Matin', 'Off', 'Après-midi'), ('Matin', 'Off', 'Nuit'), ('Matin', 'Off', 'Off'), ('Journée', 'Off', 'Après-midi'), ('Journée', 'Off', 'Nuit'), ('Journée', 'Off', 'Off'), ('Après-midi', 'Off', 'Nuit'), ('Après-midi', 'Off', 'Off'), ('Off', 'Off', '*')]
check_44h(rest_pattern_list)
######## To here
Copy the code above and paste it to your project.
Check “Use Language Constraint”, and solve it.
Solution
Simpler Implementation without Python
If we have minimum consecutive two days off, we can make simpler implementation without Python.
Make minimum consecutive off days two or more days
Remind the remaining 44 hours rest pattern as follows.
Consecutive 44 Code Generation.
Matin → Off → Off 57.5 hours
Journée → Off → Off 55.5 hours
Après-midi → Off → Off 50.5 hours
Off → Off → Matin 47.75 hours
Off → Off → Journée 49.25 hours
Off → Off → Après-midi 54.75 hours
Off → Off → Nuit 62.0 hours
Off → Off → Off 65.25 hours
We note the above using “Don’t Care” as follows.
Consecutive 44 Code Generation.
Matin → Off → Off 57.5 hours
Journée → Off → Off 55.5 hours
Après-midi → Off → Off 50.5 hours
Off → Off →*(Don't Care) 47.75 hours
Basic Time Chart
Implementation
Solution
Code Generation Algorithm
Basic Time Chart
We should be special care for terminal.
44 hours rest pattern
We put together a 3-day pattern to ensure 44 hours of rest, considering the possibility of a night shift.
Load Python Code Generator Project File
File → Open Project File from GitHub
Load the Example Project File
File → Open Project File from GitHub