AMPL: selecting variable matrix indices to be integers

27 Views Asked by At

If I declear var x {1..3}; is there a way to specify specific indices to be integer variables?

i.e. x[1] & x[3] are integer variables while x[2] is continuous.

var x{1..3}; 
x[1] integer;
x[3] integer;
1

There are 1 best solutions below

0
fdabrandao On

Typically indexed variables are all integer or all continuous, but you can do that by having another indexed variable (e.g., y) that is integer and using a constraint to enforce x[2] and x[3] to be equal to integer variables (e.g., y[2] and y[3]) as follows:

var x{1..3};
var y{i in {1, 3}} integer;
s.t. xinteger{i in {1,3}}: x[i] = y[i];

The constraint xinteger ensures x[1] = y[1] and x[3] = y[3]. Since y is integer, x[1] and x[3] must be integer too.