ampl

Is there a way to make a specific variable from a set an integer in Ampl?


set P;
set K;
set I:= {i in K};
set J:={j in P};
param C {P} >=0;
param A {K,P} >=0;
param B {K} >=0;
var X{j in P} >=0;

P consists of 4 set values, namely sweatshirt-f, sweatshirtB/F, tshirtf and tshirtBF, but I would like sweatshirt-f only to return an integer:

maximize f: sum{j in P} C[j]*X[j];

s.t. Constraint {i in K}:

sum{j in P} A[i,j]*X[j]<=B[i];

Solution

  • Option 1: declare all of them as integer, then relax integer constraints for the others:

    var X{j in P} >=0 integer;
    let {i in P: i <> "sweatshirt-f"} X[i].relax := 1;
    

    Option 2: declare a dummy variable as integer, then constrain relevant value to match it:

    var X{j in P} >=0;
    var int_dummy integer;
    s.t. force_integer: X["sweatshirt-f"] = int_dummy;
    

    I'm not able to test those right now, so you may have to do a little debugging, but that should get you in the neighbourhood of a solution.