I am trying to find a solution to the following problem:

There are 6 teachers

Each teacher can only work for 8 hours a day

Each teacher must have a 30 minute break ideally near the middle of his shift

The following table shows the number of teacher needed in the room at certain times:

7am - 8am 1 teacher

8am - 9am 2 teacher

10am - 11am 5 teacher

11am - 5pm 6 teacher

5pm - 6pm 2 teacher

What is a good way to solve this (ideally in python and Google OR-Tools) ?

Thank you

#### Initial analysis

From the demand data we see that we need all 6 teachers from 11am-5pm working without lunch break. This is 6 hours. So there is no way to allow a lunch break near the middle of the shift.

We have more problems. The picture of the demand data indicates we have no demand between 9am and 10am. That does not look right. Bad data is fact of life. Optimization models are especially sensitive to bad data.

I believe that looking critically at your data is essential for successful optimization applications. You can learn a lot from just a bit of staring.

#### Alternative problem 1

We can ask a few different questions. If we only allow shifts of the form: 4 hours work, 0.5 hour lunch, 4 hours work (i.e. lunch perfectly in the middle of the shift), how many teachers do we need to meet the demand. To model this, we can assume time periods of half an hour. The number of possible shifts is small:

With an enumeration of the shifts, we can model this as a covering problem:

Covering Model |
---|

\[\begin{align} \min\> &\color{darkblue}z= \sum_s \color{darkred} x_s \\ & \sum_{s|\color{darkblue}{\mathit cover}(s,t)} \color{darkred} x_s \ge \color{darkblue}{\mathit demand}_{t} && \forall t \\ &\color{darkred} x_i \in \{0,1,2,\dots\}\end{align} \] |

Here \(\mathit{cover}(s,t)=\text{True}\) if shift \(s\) covers time period \(t\). If we would interpret \(\mathit cover(s,t)\) as a binary (data) matrix \[\mathit cover_{s,t} = \begin{cases} 1 & \text{if shift $s$ covers time period $t$}\\ 0 & \text{otherwise}\end{cases}\] we can also write:

Covering Model (alternative interpretation) |
---|

\[\begin{align} \min\> &\color{darkblue}z= \sum_s \color{darkred} x_s \\ & \sum_s \color{darkblue}{\mathit cover}_{s,t} \cdot \color{darkred} x_s \ge \color{darkblue}{\mathit demand}_{t} && \forall t \\ &\color{darkred} x_i \in \{0,1,2,\dots\}\end{align} \] |

Our new assumptions are:

- we only allow shifts with a lunch break in the middle
- we add to our demand data: 4 teachers needed between 9am and 10am

---- 55 VARIABLE x.L number of shifts needed shift1 2.000, shift4 2.000, shift5 2.000, shift6 2.000 ---- 55 VARIABLE z.L = 8.000 total number of shifts

The picture shows we are overshooting demand in quite a few periods. Note: this picture illustrates the left-hand side (orange bars) and right-hand side (blue line) of the demand equation in the Covering Model.

We now have 55 different shifts to consider.

The results look like: #### Alternative problem 2

Lets make things a bit more complicated. We allow now the following rules for a single shift:- The work period before the lunch bread is between 3 and 5 hours (or between 6 and 10 time periods)
- There is a lunch break of 0.5 or 1 hour.
- After lunch there is another work period of between 3 and 5 hours. The total number of working hours is 8.

When we enumerate the shifts, we see:

We now have 55 different shifts to consider.

---- 72 VARIABLE x.L number of shifts needed shift1 1.000, shift22 1.000, shift26 1.000, shift39 1.000, shift49 1.000, shift52 1.000 shift55 1.000 ---- 72 VARIABLE z.L = 7.000 total number of shifts

We see the number of teachers needed is 7. We are closer to the demand curve:

We see that if we add more flexibility we can do a bit better. Achieving 6 teachers is almost impossible. We would need to introduce shifts like: work 2 hours, lunch, work 6 hours. The teachers union would object.

It is noted there are quite a few other methods to solve models like this where we don't need to enumerate all possible shifts [2,3]. For larger problems it may not be feasible to employ the shift enumeration scheme we used here.

#### References

- Constraint programming scheduling problem, https://stackoverflow.com/questions/57473085/constraint-programming-scheduling-problem
- Employee Scheduling II: Column Generation, http://yetanothermathprogrammingconsultant.blogspot.com/2017/01/employee-scheduling-ii-column-generation.html
- Employee Scheduling IV: Direct Optimization, http://yetanothermathprogrammingconsultant.blogspot.com/2017/03/employee-scheduling-iv-direct.html

## No comments:

## Post a Comment