help in declaring a variable with a limited range

529 views
Skip to first unread message

Prashant PSE

unread,
Jun 19, 2011, 3:42:49 PM6/19/11
to AMPL Modeling Language
dear sir

i need help in declaring a variable which is let say lies between 0
and 100.
i can set minimum value Pmin =20 for this variable and maximum Pmax
=100.
like
var P{t} >= Pmin, =< Pmax
but the problem is how can i set a constraint that this variable
should not lies between let say P1=40 to P2=50.

it means i want to set this variabe between 20 to 40 and 50 to 100.

if there is any way to do this please suggest me.

Robert Fourer

unread,
Jun 20, 2011, 1:58:09 PM6/20/11
to am...@googlegroups.com
You can specify the condition "20 <= X <= 40 or 50 <= X <= 100" though the
use of an auxiliary binary (zero-one) variable as follows:

var X;
var Z binary;

subject to EitherOr1: 20 + 30*Z <= X;
subject to EitherOr2: X <= 40 + 60*Z;

Alternatively, you can define X to lie in the union of two disjoint
intervals, by writing:

var X in interval[20,40] union [50,100];

Then AMPL will introduce define the needed binary variable automatically
when it generates the problem for the solver. (The currently implemented
transformation tends to create a larger number of variables, however.)
Either way, you will need to use a solver that can handle mixed-integer
optimization problems -- for example CPLEX or Gurobi, but not MINOS.

Bob Fourer
4...@ampl.com

Reply all
Reply to author
Forward
0 new messages