I have to impose that my MPVar can takes integer values 0, 1 or 2. The constraint is: x(i,j) ∈ [0,1,2], where, obviously, "x "is an MPVar.Can someone helps me?
The 'x(i,j)' must be declared as an array of type 'mpvar', I am assuming the index sets are called I and J respectively.
The bounds (lower bound 0 is the default, so no need to state it explicitly) and variable type (here: integer) can then be stated as follows:
forall(i in I, j in J) do
x(i,j) <= 2
NB: if you only have values 0 and 1 then you would use 'is_binary'. Other available decision variable types include semi-continuous and partial integer.
Retrieving data ...