this is a follow-up question to this post here and to @RobPratt's answer. I have implemented the whole thing, and now it happened that on day 1 the machine did not run and was only used for the first time on day 2, but a shift change was modeled, even though there was actually none. What could be the reason for this and how do I have to adjust the constraints to prevent this from happening? That is the answer:

\begin{align} \rho_{ptm} &\le 1-s_{ptm} &&\text{for all $p,t,m$} \\ \rho_{ptm} &\le d_{ptm} &&\text{for all $p,t,m$} \\ \rho_{ptm} &\ge d_{ptm} - s_{ptm} &&\text{for all $p,t,m$}\\ \sum_m d_{ptm} + x_{pt} &= 1 &&\text{for all $p,t$} \\ s_{p,t+1,m} &= d_{ptm} + y_{ptm} &&\text{for all $p,t\not=T,m$} \\ y_{ptm} &\le s_{ptm} &&\text{for all $p,t,m$} \\ y_{ptm} &\le x_{pt} &&\text{for all $p,t,m$} \\ y_{ptm} &\ge s_{ptm} + x_{pt} - 1 &&\text{for all $p,t,m$} \end{align}

The variables are defined as:

  1. $d_{ptm}$: Binary variable indicating if product $p$ was serviced by machine $m$ in period $t$
  2. $\rho_{ptm}$: Binary variable indicating if there was a switch in machines for product $p$ in period $t$ to machine $m$
  3. $s_{ptm}$: State variable indicating if the last servicing of product $p$ prior to period $t$ was by machine $m$
  4. $y_{ptm}$: Auxiliary variable to assist in defining constraints related to $s_{ptm}$ and $x_{pt}$
  5. $x_{pt}$: Binary variable indicating if product $p$ is not being serviced in period $t$

And that is the original question:

I have the following question / concern. I have a modeling problem with the decision variable $d_{ptm}$ which indicates whether product $p$ was serviced by machine $m$ in period $t$. It takes the value 1 if so, and 0 otherwise. A product can be serviced by different machine in different periods. In addition, a product may not be serviced for two days and then again, possibly by a different machine. I now want to introduce a binary variable $\rho$ that indicates such a switch in machines a product was serviced by. It should take the value = 1 if there was a machine switch from the last time a product was serviced till the current period. How can I model this?

  • 1
    $\begingroup$ Please add to your question the definition of every variable. $\endgroup$
    – prubin
    Commented Jun 7 at 15:36
  • $\begingroup$ As mentioned in the comments to the linked question, there is some ambiguity about a switch for the first servicing. Is there anything in the rest of your model that encourages switches? $\endgroup$
    – RobPratt
    Commented Jun 8 at 12:56

1 Answer 1


I'm going to assume that time indexing starts at 1. You can introduce a new binary variable $\gamma_{p,t}$ together with the constraints $$\gamma_{p,1}=1$$ $$\gamma_{p,t} \le \gamma_{p, t-1}$$ $$\gamma_{p,t} \le x_{p,t-1}$$ and $$\gamma_{p,t} \ge \gamma_{p,t-1} + x_{p,t-1} - 1.$$ Collectively this ensures that $\gamma_{p,t}=1$ if and only if $p$ has not been in production (on any machine) prior to time $t.$

Now adjust your first and third constraints as follows: $$\rho_{p,t,m}\le 1-s_{p,t,m}-\gamma_{p,t}$$ $$\rho_{p,t,m} \ge d_{p,t,m}-s_{p,t,m} - \gamma_{p,t}.$$


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.