# Switching of decision variables to be equal to a certain decision variable according to a binary (indicator) variable

I would like to seek some advice on modeling the following:

I have two integer decisions variables, $$x, x'$$, that are either equal or greater than zero and either of them is to be equated to a third integer decision variable, $$z$$, which is also equal or greater than zero in accordance to the value of a binary indicator variable, $$\beta$$.

$$\beta=1$$ $$\implies$$ $$x=z$$

$$\beta=0$$ $$\implies$$ $$x'=z$$

Thank you!

$$x \le z + M(1-\beta) \\ x \ge z - M(1-\beta) \\ x' \le z + M\beta \\ x' \ge z - M\beta \\$$

If $$\beta=1$$, we have

$$x \le z \\ x \ge z \\ x' \le z + M \\ x' \ge z - M \\$$

which leads to $$x=z$$ and $$x'$$ unconstrained. And likewise if $$\beta=0$$.

• Dear Kuifje, thank you for your speedy answer. May I ask you in detail with regard to the case of $\beta=1$. Would last two constraints that result in an interval of integers, i.e., $z-M$$\le$$x'$$\le$$z+M$ force $x'$ to be strictly positive? For my problem zero has to be included as $x'$ is set to zero due to other constraints in the model. Appreciate your inputs!
– Mike
Sep 10 '20 at 10:15
• You can add another constraint $x' \ge 0$ if you need $x'$ to be non negative no matter what. In this case $z-M \le x'$ will have no effect (if $M$ is large enough). Sep 10 '20 at 10:24
• Dear Kuifje, pardon me for missing out on the bottom portion on $x'$ unconstrained. Could you help elaborate on the mechanism which enables it to be unconstrained as I treating it from the perspective where $z$ is a integer decision variable though which might be equal or greater than zero, it could possibly be of a certain large value that could overwhelm M causing $x'$ to not include 0. Thank you!
– Mike
Sep 10 '20 at 10:28
• Yes that is why you have to choose $M$ big enough, in this case larger than the upper bound for $z$. Sep 10 '20 at 10:31
• Your last comment is exact: you need $M$ large enough to prevent $z-M >0$, but not too large otherwise you might run into numerical issues. Sep 10 '20 at 10:33