Modelling a shift change

binary-programmingconstraintsinteger programmingoperations research

I have the following problem. I am currently modeling shift schedules. There is the variable $x_{itk}$ which tells whether the cashier $i$ completes the shift $k$ on day $t$. Now I want to model the following. I want to introduce a binary variable $l_{it}$ that takes the value 1 if there was a shift change and 0 if not. Here, a shift change is defined as follows. There are three shifts per day, and a cashier must always take a shift, but never more than one. There is an early, day, and late shift. Assume that cashier $i$ has the early shift on day $t$. However, on day $t+1$, he has the day shift. So there was a shift change. The variable $l_{it}$ should therefore take the value 1 on day $t+1$. How can I model this relationship?

I have tried the following so far but I would like it to be a constraint and not a case distinction so I can use it for modeling as well.
$l_{i(t+1)}=\begin{cases}
1, & \text{if}~x_{it3}+x_{i(t+1)1}+x_{i(t+1)2}=1~~\forall i\in I,~t\in\left| T \right|-1,\\
0, & \text{else.}
\end{cases}$

Best Answer

You want to enforce the logical implication $$(x_{i,t,k}\land \lnot x_{i,t+1,k})\implies l_{i,t+1}.$$ You can somewhat automatically derive linear constraints via conjunctive normal form: $$ \lnot (x_{i,t,k}\land \lnot x_{i,t+1,k})\lor l_{i,t+1}\\ \lnot x_{i,t,k}\lor x_{i,t+1,k}\lor l_{i,t+1}\\ (1- x_{i,t,k})+ x_{i,t+1,k}+ l_{i,t+1}\ge 1 \\ \color{red}{x_{i,t,k} - x_{i,t+1,k} \le l_{i,t+1}} $$

If shift changes are undesirable (perhaps because of a cardinality constraint or the objective), you can get away without forcing $l_{i,t}=0$ and instead relying on the solver to do so when it is advantageous. Otherwise, you can again use conjunctive normal form to derive linear constraints that enforce $$l_{i,t+1}\implies \bigvee_k (x_{i,t,k}\land \lnot x_{i,t+1,k}).$$ Alternatively (because each cashier takes exactly one shift per day), you can enforce $$(x_{i,t,k}\land x_{i,t+1,k}) \implies \lnot l_{i,t+1},$$ which yields $$\color{red}{x_{i,t,k} + x_{i,t+1,k} + l_{i,t+1} \le 2}.$$

Related Question