# Linear programming, Checking a constraint based on condition

I have a constraint $X \ge Y$ in a Linear programming formulation, where both $X$ and $Y$ are binary. I want to check this constraint on a condition like:

if (Y==1)
then check the constraint
else


How to do it.

• Check page 7 – adrianN Dec 19 '16 at 9:32
• You do it by introducing a large number, say $M$, and writ $X+(1-Y)M\geqslant Y$. – drzbir Dec 19 '16 at 13:26
• If $Y=1$ then $X$ must be greater than or equal to $1$ and since $X$ is binary, then you must have that $X=1$. So there is no need to introduce a large number $M$. You can simply write $X\geqslant Y$. In case $Y=1$, you get $X=1$ and in case $Y=0$, you have no restriction on $X$. – drzbir Dec 19 '16 at 15:36
• I don't think this is a duplicate of cs.stackexchange.com/q/67459/755. That other question asks about if Y==1: X=1 else: X=0. That's a different situation. The solution listed for the other question doesn't solve this question. – D.W. Dec 19 '16 at 15:39

If $X$ and $Y$ are zero-or-one (binary) integer variables, then this is encoded as
$$X \ge Y.$$
Why does this work? If $Y=1$, then this enforces the constraint $X \ge Y$, as you wanted. If $Y=0$, this enforces the constraint $X \ge 0$, i.e., it doesn't impose any rstrictions on $X$, which is also as you wanted.