How to define "if and only if" rule in linear programming?

时间:2017-12-18 05:33:43

标签: linear-programming gurobi

Now I have two binary decision variables X1 and X2. If I intend to define a constraint that X2 could be 1 if and only if X1 is 1. In other word, X2 is a sequel to X1. How could I define this kind of logic in linear programming?

Any hint will be appreciated, many thanks in advance!

1 个答案:

答案 0 :(得分:1)

I am a bit confused by your question.

x1 = 1 <=> x2 = 1

is the same as

x1=x2

I think you want

x1 = 1 => x2 = 1

i.e. no "if and only if" but only "if". This can be written as:

x2 >= x1

The reverse

x1=0 => x2=0

is of course just as trivial:

x2 <= x1 

Also note that LPs don't have binary variables (LP refers to continuous variables). Binary variables can be used only in (mixed) integer programs.