How to specify an IF-THEN-ELSE constraint with an Integer Linear Programming (ILP) solver
Problem :
For example: if (P = 1) then A < B else A > B. (Note that P is a binary variable, that is, P = {0, 1}.)
Answer :
if (P = 1) then A <
B else A > B.
==>
if (P =
1) then A < B else B <
A.
==>
if (P =
1) then (A - B < 0) else (B -
A < 0).
==>
A - B < M1*(1-P)
.......... (1)
B - A < M2*P .......... (2)
Note
that P
is a binary variable, that is, P = {0, 1}. In addition, M1 and M2 are constants
whose values should be large enough.
If
P=1, then A < B and constraint (2) is redundant.
If
P=0, then B < A and constraint (1) is redundant.
==>
A - B <= M1*(1-P)
- 1 .......... (3)
B - A <= M2*P
- 1 .......... (4)
Note that "<=" denotes "less than or equal".
last update: May 29, 2009