HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Converting If-else condition to Linear Programming

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
linearconditionelseprogrammingconverting

Problem

I have a constraint in a linear programming formulation with two variables: $X \ge Y$

To which I want to apply the following if-else conditions:

if Y=1:
    X=1
else:
    X=0


Where $X$ and $Y$ are binary.

How can I fit this if-else into linear programming? Do I need to define another variable? It looks as an AND operation, between $X$ and $Y$.

Solution

This can be expressed with just the equation $X=Y$. Since $X,Y$ are zero-or-one variables, the only possible assignments that are consistent with your condition are $X=Y=0$ and $X=Y=1$.

See Express boolean logic operations in zero-one integer linear programming (ILP) for many more boolean conditions and how to express them as linear inequalities.

Context

StackExchange Computer Science Q#67459, answer score: 5

Revisions (0)

No revisions yet.