rodrigo-arenas / pyworkforce

Standard tools for workforce management, queuing, scheduling, rostering and optimization problems.
https://pyworkforce.readthedocs.io
MIT License
75 stars 19 forks source link

WeeklyRoster #39

Open evr194 opened 1 year ago

evr194 commented 1 year ago

Hello Rodrigo,

I have been looking into your ‘MinHoursRoster’, which does exactly what it is supposed do to. However, realistic workforce planning is conducted most often on a weekly basis. Therefore, I would like o ask you to create a ‘WeeklyRoster’ tool that would look like the existing ‘MinHoursRoster’ but with following three major differences : Instead of a number of days, the user should be able to create a roster based on a number of weeks (each week made up of 7 days) When entering a number of ‘max_rest’ days (from 0 as no resting day and 7 as the maximum number of resting days per week), whenever the ‘max_rest’ days >= 2, such two resting days should be combined to simulate the weekend (or its replacing two days) according to a revolving scheme to be calculated by the logic. I think this could be done by adapting your ‘MinHoursRoster’ code as follows :

def optimize_max_resting(shifts, num_days, max_resting): resting_days = 0 for i in range(num_days): if shifts[i] == 0: resting_days += 1 if resting_days >= 2: return True else: resting_days = 0 if max_resting > 2: return True return False

Finally, the shifts should remain stable throughout the week for each individual resource (and not having such a resource switch between 2, 3 or even 4 shifts (or more) during the days he/she will be planned for each week. E.g. someone should work 5 days the same shift during the same week in which he/she has 2 resting days. Next week this could be another shift, but always the same shift within this second week, and so on. I think this could be done by adapting your ‘MinHoursRoster’ code as follows :

def optimize_shifts(shifts, max_consecutive_shifts): consecutive_shifts = 0 for i in range(len(shifts)): if shifts[i] == 1: consecutive_shifts += 1 if consecutive_shifts >= max_consecutive_shifts: if i + 1 < len(shifts) and shifts[i + 1] == 0: consecutive_shifts = 0 else: return False else: consecutive_shifts = 0 return True I am not proficient enough to start tampering with your code, but it would be greatly appreciated if you could look into this. Creating a ‘WeeklyRoster’ tool would be a great addition to pyworkforce, I think since it would mimic more closely real life situations.