I am trying to find a constraint for the following relationship, but am failing a bit at it right now. I want to find a linear constraint that does the following. The binary variable $switch_{ot}$ is to be introduced. It should always take the value 1, if the variable $lamp_{ot}$ was $=0$ in every of the periods $t-\tau$ to $t-1$. Otherwise $switch_{ot}=0$ shall be valid. How do I model something like this?
- 1
- 2
- 11
- 31
- 3
-
Do you mean “if the variable $lamp_{ot’}=0$ for one $t-\tau\leq t’\leq t-1$” or “if the variables $lamp_{ot’}=0$ for all $t-\tau\leq t’\leq t-1$” – Sune May 25 '23 at 17:14
-
Woopsie. I meant for all. – mingabua May 25 '23 at 17:20
-
Are the "lamp" variables binary? If not, what are their domains? – prubin May 25 '23 at 17:56
-
Yes they are. Both are binary – mingabua May 25 '23 at 17:57
2 Answers
In other words, you want to linearize this relationship: $$\text{switch}_{ot} \iff \bigwedge_{u=t-\tau}^{t-1} \lnot \text{lamp}_{ou}$$
Or as a product: $$\text{switch}_{ot} = \prod_{u=t-\tau}^{t-1} (1 - \text{lamp}_{ou})$$
Because $\text{lamp}_{ou}$ is binary, so is its "complement" $1 - \text{lamp}_{ou}$, and the usual linearization of a product of binary variables yields: \begin{align} \text{switch}_{ot} &\le 1 - \text{lamp}_{ou} &&\text{for $u \in \{t-\tau, \dots, t-1\}$} \tag1\label1\\ \text{switch}_{ot} &\ge \sum_{u=t-\tau}^{t-1} (1 - \text{lamp}_{ou}) - \tau + 1 \tag2\label2 \end{align}
Of course, \eqref{2} can be simplified as $$\text{switch}_{ot} \ge 1 - \sum_{u=t-\tau}^{t-1} \text{lamp}_{ou}$$
- 32,006
- 1
- 44
- 84
The answer of Rob is great. Another way to model this with fewer constraints needed is the following:
\begin{alignat}1 (1- \text{switch}_{ot}) &\le \sum_{u=t-\tau}^{t-1} \text{lamp}_{ou} \tag{1}\label{1A}\\ M \cdot (1- \text{switch}_{ot}) &\ge \sum_{u=t-\tau}^{t-1} \text{lamp}_{ou} \tag{2} \label{2A} \end{alignat}
Where $M$ is a large enough number. In your case this might be $\tau$. If all $\text{lamp}_{ou}$ variables are $0$, equation \eqref{1A} makes sure that the switch variable is 1. If any $\text{lamp}_{ou}$ is greater $0$, \eqref{2A} states that the switch variable must be 0.
- 5,412
- 5
- 22
- 55
- 1,501
- 4
- 16
-
2This is also correct. Your (1) is my (2), and your (2) is an aggregation of my (1). Yes, $M=\tau$ is valid. – RobPratt May 25 '23 at 19:16
-
You are right. Calling this a "different way" is maybe not the most correct statement ;) – PeterD May 25 '23 at 19:22