I have to solve this real problem, it seemed trivial to me at first but I am having difficulty and I don't have much time to solve it. I would like to solve it possibly with python so then I can print the result to a csv. This is the problem:
Problem
7 employees must divide the work shifts (M,A,N, morning afternoon and night) over 7 weeks. Each day of the 49 days must have a different employee for each shift.( e.g. day1: M:employee 1, A:employee 3, N:employee 6 )
Each employee works weekday/time slot only 1 time in the 49-day cycle (e.g. employee 1 does 1 Monday morning, 1 Monday afternoon, 1 Monday night, 1 Tuesday morning etc)
If an employee works a night shift, it cannot work shifts on the next 2 days.
CodePudding user response:
Mapping shift (M, A, N) to (0, 1, 2) with variable s
, day (Monday, Tuesday, ..., Sunday) to (0, 1, ..., 6) with variable d
, and week in variable w
, you can use the formula (w d-s)%7 1
to get the employee assigned to shift w,d,s
(%
is the modulo operator).
(in some languages like C , you might have to add 7 in the parentheses if modulo of negative numbers outputs a negative number)