How to constrain the integer variable staying out of an integer interval

102 views Asked by At

As mentioned in the title, how to use a linear constrain to ensure an integer n is staying out of (n1, n2), in which n,n1,n2 are all integers, and the interval is not [n1, n2].

I formulate the problem in GAMS as

n2 - n1 =l= abs(2*n - n2 - n1)

but the abs() is not allowed in a MIP model.

THX

1

There are 1 answers

0
Catyes On

You need to define a binary variable (nlow) for n beening eighter below or above the interval. Then use two constraints to inforce this. The number M should be large egnouf that it does not limit your variable n.

Scalar M /1000/;    
Integer Variable n;    
Binary Variable nlow;    
Equation below, above;

below ..  n =L= n1 + M*(1-nlow);    
above ..  n =G= n2 - M*nlow;