Model legal shift constraints

69 Views Asked by At

I need your help. My decision variable $b_{fds}$ indicates whether a fireman $f$ works shift $s$ on day $d$. I need two constraints:

a) No more than 5 consecutive working days

b) At least 2 consecutive days off after a working period

c) At least 2 consecutive working days

How would I model those constraints in a linear way?

2

There are 2 best solutions below

5
On BEST ANSWER

Because each fireman works at most one shift per day, you can think of $\sum_s b_{f,d,s}$ as a binary variable. You can derive linear constraints somewhat automatically by rewriting the logical propositions in conjunctive normal form.

For part a), disallow $6$ shifts in each consecutive $6$-day interval: $$ \lnot \left(\sum_s b_{f,d,s} \land \sum_s b_{f,d+1,s} \land \dots \land \sum_s b_{f,d+5,s}\right) \\ \lnot \sum_s b_{f,d,s} \lor \lnot \sum_s b_{f,d+1,s} \lor \dots \lor \lnot \sum_s b_{f,d+5,s} \\ \left(1-\sum_s b_{f,d,s}\right)+\left(1-\sum_s b_{f,d+1,s}\right)+\dots+\left(1-\sum_s b_{f,d+5,s}\right)\ge 1 \\ \sum_s (b_{f,d,s} + b_{f,d+1,s} + \dots + b_{f,d+5,s}) \le 5 $$

Part b) is similar, except that you want to avoid the work pattern $101$ instead of $111111$: $$ \lnot \left(\sum_s b_{f,d,s} \land \lnot \sum_s b_{f,d+1,s} \land \sum_s b_{f,d+2,s}\right) \\ \lnot \sum_s b_{f,d,s} \lor \sum_s b_{f,d+1,s} \lor \lnot \sum_s b_{f,d+2,s} \\ \left(1-\sum_s b_{f,d,s}\right) + \sum_s b_{f,d+1,s} + \left(1-\sum_s b_{f,d+2,s}\right) \ge 1 \\ \sum_s \left(b_{f,d,s} - b_{f,d+1,s} + b_{f,d+2,s}\right) \le 1 $$

For part c), introduce a new binary variable $z_{f,d}$ to indicate whether fireman $f$ works on days $d$ and $d+1$, and impose \begin{align} \sum_d z_{f,d} &\ge 1 \\ z_{f,d} &\le \sum_s b_{f,d,s} \\ z_{f,d} &\le \sum_s b_{f,d+1,s} \end{align} A weaker but more compact formulation replaces the last two constraints with their aggregation $$2z_{f,d} \le \sum_s \left(b_{f,d,s} + b_{f,d+1,s}\right)$$

0
On

Assuming by working period you mean atmost 3 day, you may try
$\sum_s (b_{f,s,d}+b_{f,s,d+1}) \le \sum_s (3b_{f,s,d-1} - \sum_{k=d-1}^{d-3}b_{f,s,k}) \ \ \forall d,f$