2
votes

I have a mixed integer linear program (MIP or MILP). In the end I want a boolean variable im my linear program, that has the following properties.

I have two variables:

boolean b.
real x, with x being 0 or larger.

What I want to achieve is:

b == false if x == 0.
b == true if  x >  0.

I found a way to depict if x is in specific range (e.g. between 2 and 3) via:

2*b <= x
x   <= 3*b

The problem with the above testing formula is, that b will be true if x is in the given range and false if outside that range.

Does anybody know a way to set a boolean variable to false if x == 0 and to true if x is larger than 0?

2

2 Answers

3
votes

If U is an upper bound of x then

if x > 0 ==> b == 1

can be made as

x <= U*b

The second part (x == 0 => b == 0) needs to be modified to

x < epsilon ==> b == 0

which can be made as

b <= 1 + x - epsilon

where epsilon is a small number. Other than good practice this is necessary, because solvers do not work in rational arithmetic (although there are some research efforts to make them do so), but with certain precision thresholds, and therefore quantities such as 10e-12 are treated as zero.

I hope this helps!

-1
votes

You could use the signum function http://en.wikipedia.org/wiki/Signum_function take the absolute value and negate it. Since you didn't name a specific programming language I keep it general.