Workforce scheduling is a classical optimization problem. Improved schedules can be better both for the workers and for the business, but are often surprisingly hard to find. One common variant of scheduling is called Rotating Workforce Scheduling (shortened as RWS), and is sometimes called cyclic scheduling. In RWS, a weekly schedule is created for a group of workers covering the projected needs. Each worker will rotate through the schedule, working all different weeks.
Solving RWS is a challenging problem, both for manual and automatic approaches. This post will describe developing a reasonably realistic variant of finding an RWS schedule using MiniZinc. Starting with the basic structure and then adding more and more typical requirements to get realistic schedules.
What does it mean to rotate through a schedule? If there are n n n employees, then n n n different weekly schedules are created. Each employee follows one week-schedule, and every week all employees shift to the next schedule in the rotation. This ensures fairness: everyone eventually experiences each schedule pattern. Using this type of schedule is useful for cases where there is a variety of requirements, usually involving work outside of normal office hours.
In this post we will keep to a fairly simple model that is still realistic, with D day shifts, E evening shifts, N night shifts, and finally · off days.
# Mon Tue Wed Thu Fri Sat Sun 1 E E E E · · · 2 D D D · · D D 3 D · · N N N N 4 · · · · E E E 5 D D D D D · · 6 N N N N N · · 7 N N N · · D D Week: ▼ 1 ▲ · Off D Day shift E Evening shift N Night shift
Use the week buttons above to see how each employee’s schedule changes as the rotation progresses.
There are many cases where the scheduling needs are for more detailed levels, not just three types of shifts. Still, this level of detail is often usable, and will allow us to reason about the problem at a simple level.
First we will look at a basic model that handles the data, the instances, and the basic constraints and printing. In the next section, we will add the constraints for the labor rules to turn a basic schedule into something that could be used in practice.1
The first step in writing a MiniZinc model is to set up the data-definitions. There are three axis that are needed, the days, the employees, and the shifts.
enum Days = {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; set of Days: Weekend = {Sat, Sun}; enum ShiftsAndOff = {Day, Evening, Night, Off}; set of ShiftsAndOff: Shifts = {Day, Evening, Night};
... continue reading