Here is a scheduling problem I need to solve. Given the demand for 2 positions in 1 week with 3 shifts per position, I need to allocate the employees accordingly with some extra operational constraints. Note that each employee can work at any position but only one shift per day totally.The main objective here is to minimize the total shift switches within week. First I shall introduce my variables and the constarints and then how I formulated it mathematically.
Binary variables:
- Employee: $x_{i}$, i=1:N
- Working day per employee: $y_{i,j}$, i=1:N | j=1:7
- Wroking day/shift/position per employee: $z_{i,j,k,l}$, i=1:N | j=1:7 | k = 1:3 | l = 1:2
- Shift switch per employee per day: $s_{i,j,k}$, i=1:N | j=1:7 | k = 1:3
Constraints:
- One shift per day per employee: $\sum_{k,l} z_{i,j,k,l} \leqslant y_{i,j} \ \ \forall i,j$
- One position per day per employee: $z_{i,j,k,1}+ z_{i,j,k,2} \leqslant1 \ \ \forall i,j,k$
- Maximum working days per employee (6 days): $\sum_{j} y_{i,j} \leq x_{i}\cdot D_{max} \ \ \forall i=1:N$
- Minimum working days per employee (5 days): $\sum_{j} y_{i,j} \geq x_{i}\cdot D_{min} \ \ \forall i=1:N$
- Comply with weekly demand (D): $\sum_{i} z_{i,j,k} = D_{j,k,l} \ \ \forall j,k,l$
- Detect any shift switch day over day: $\sum_{l}z_{i,j,k,l}- \sum_{l}z_{i,j-1,k,l} \leqslant s_{i,j,k} \ \ \forall i,j=2:7,k$
I followed this method to introduce continuity in shift assignment and reduce switches
Objective:
Minimize shift switches day over day across all employees:$min \sum_{i,j,k}s_{i,j,k} \ \ \forall i,j=2:7,k$
Running this in R with ompr package I get this results:
Employees are placed to rows and columns depict the day of the week. Values denote the shift an employee is assigned to. Missing values (NA) correspond to employee's day off according to the constraints.
This is not the best solution, at first glance, this can be solved with very few employees having shift change within week and the rest to be assigned to a single shift throughout the week. I guess this is due to the fact that any day off followed by a shift assignment is considered as change. Any thoughts?