Given a boolean variable $x$ and nonnegative integer variable $s$, I want to select $y = \begin{cases} 0 & \text{if} \ x = 0 \\ s & \text{if} \ x = 1 \end{cases}$. Currently in the problem, $s$ is the sum of $n$ boolean variables $x_1 + x_2 + \cdots + x_n$ so I want to compute $x \land x_1 + x \land x_2 + \cdots + x \land x_n$. However, computing each individual $x \land x_i$ requires its own variable and constraints and I'm wondering if its possible to use a constant number of variables and constraints.
-
$\begingroup$ If $s$ is an integer variable then it can't be the sum of boolean variables. If the sum is known you can just compute $xs$. $\endgroup$Gaslight Deceive Subvert– Gaslight Deceive Subvert2022年04月28日 06:32:34 +00:00Commented Apr 28, 2022 at 6:32
-
$\begingroup$ @BjörnLindqvist It's possible that "s is an integer variable and s is the sum of n boolean variables x1 + ... + xn" was an informal way to say "s is an integer variable, and there is a linear equality constraint s = x1 + ... + xn". $\endgroup$Stef– Stef2022年04月28日 09:25:44 +00:00Commented Apr 28, 2022 at 9:25
1 Answer 1
Use the three inequalities
$0ドル \le y \le s$$
$$y \le Mx$$
$$y \ge s - M(1-x)$$
where $M$ is a large constant, chosen to be larger than the largest possible value of $s$ (e.g., $M=n+1$ in your example).
Explore related questions
See similar questions with these tags.