3
$\begingroup$

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?

$\endgroup$
4
  • $\begingroup$ 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$” $\endgroup$
    – Sune
    Commented May 25, 2023 at 17:14
  • $\begingroup$ Woopsie. I meant for all. $\endgroup$
    – mingabua
    Commented May 25, 2023 at 17:20
  • $\begingroup$ Are the "lamp" variables binary? If not, what are their domains? $\endgroup$
    – prubin
    Commented May 25, 2023 at 17:56
  • $\begingroup$ Yes they are. Both are binary $\endgroup$
    – mingabua
    Commented May 25, 2023 at 17:57

2 Answers 2

3
$\begingroup$

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}$$

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
2
  • 2
    $\begingroup$ This is also correct. Your (1) is my (2), and your (2) is an aggregation of my (1). Yes, $M=\tau$ is valid. $\endgroup$
    – RobPratt
    Commented May 25, 2023 at 19:16
  • $\begingroup$ You are right. Calling this a "different way" is maybe not the most correct statement ;) $\endgroup$
    – PeterD
    Commented May 25, 2023 at 19:22

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.