Relaxing integrality on specific index values of a variable

Hi, I have the following variable in my .mod:

var X {CKLLT} >= 0;

Which is defined in the .dat file as:

set CKLLT :=
(commodity1, vehicle, location1, location2, time)
(commodity2, vehicle, location1, location2, time)

As you can see, the variable X is continuous. However, I would like to know if it is possible to force integrality for one of the commodities in the X{CKLLT} set. For example, when C in CKLLT =“commodity2”, the variable X must be integer, but the rest of the X variable solutions where the commodity does not equal “commodity2” can be continuous.

Thanks!

You can define the variables as integer, and then use AMPL’s builtin .relax suffix to specify the ones that should be treated as continuous. For example,

var X {CKLLT} integer >= 0;
let {(c,v,l1,l2,t) in CKLLT: c <> "commodity2"} 
   X[c,v,l1,l2,t].relax := 1;