Scheduling: Connecting the end and the beginning of the planning horizon

I would like to create a rota that repeats every 28 days and adheres to the usual rules. These include the minimum/maximum number of consecutive working days and the break days. I have created a model that adheres perfectly to these rules within the period, but has problems with the transitions from $$t=28$$ to $$t=1$$. How do I need to adjust my constraints to make it work? These are my constraints.

$$\sum_{d=t-6}^{t}\sum_{k\in K}^{}x_{idk}\le 6\quad\forall i\in I,~t\in \left\{ 7,\ldots,T \right\}$$

$$\sum_{d=t+1}^{t+4}y_{id}\ge 4\cdot(y_{i(t+1)}-y_{it})\quad\forall i\in I,~t\in \left\{ 1,\ldots,\mid T\mid -4\right\}$$

$$1+y_{it}\ge y_{i(t-1)}+y_{is} \quad\forall i\in I, s\in \left\{ t+1,\ldots,t+2 \right\},t\in\left\{ 2,\ldots,\mid T\mid-2 \right\}$$

• Should the first summation's upper index limit be $t$ rather than $d?$ Also, what should repeat every 28 days: just $x$; just $y$; or both? If both, why not just solve for the first 28 days?
– prubin
Jan 30 at 16:45
• You're right. I fixed the OP. $x$ determines $y$ in another constraint (which i havent mentioned). I don't get your last point. Whenever i solve the model for 28 days, it could very well be that a person works f.e. on $t=1$, but has $t=2-4$ off and starts working again afterwards. Then the person also works on day $t=22-27$ (which doesnt violate any constraint, but then has off on day $t=28$. But then, seeing the whole as a rota, it violates the constraint regarding the minimum number off working days. Of course i could introduce a hard coded constraint, but i want it to behave "dynamically". Jan 30 at 18:00

You can take time indexes mod $$T$$ to make it work. Rewrite the first constraint as $$\sum_{d=t-6}^t \,\sum_{k\in K} x_{i,d\bmod T,k} \le 6 \quad \forall i\in I, t\in \lbrace 1,\dots, T\rbrace.$$
So, for example, for $$T=28$$ $$t=1$$ and each $$k\in K$$ the left side contains $$x_{i,23,k} + x_{i,24,k}+\cdots + x_{i,28,k} + x_{i,1,k}.$$