Search code examples
gnulinear-programmingamplglpk

GLPK: Indexing variables with elements of a set


Let's say that I have a set and variables defined this way:

set Objectes;
var x{i in Objectes}>=0, integer;

s.t. rest: x[i in Objectes]>=7;


data;
set Objectes:= Animals Plantes Persones;
end;

I have 3 variables, let's say x[Animals], x[Plantes] and x[Persones]. I want x[Animals] and x[Plantes] to be >=0, and x[Persones] to be >=7. I tried every logic way that came to my mind to define it on the "subject to" section, but it's not working. How I can do third variable <=7?


Solution

  • You can do it as follows:

    s.t. rest: x['Persones'] >= 7;