I think an easy question - how can I generalize the last two equations?

Set bottom /a,b,c/;

Set top /one, two/;

Set one(bottom) /a,b/;

Set two(bottom) /c/;

Parameter benefits(bottom) /a 1, b 2, c 3/;

Parameter limits(top) /one 5, two 4 /;

Variables

totbenefits total benefits

q(bottom) letters chosen

Positive Variable q ;

Equations

totalben total benefits

limit1 limits choices

limit2 limits choices;

totalben … totbenefits =e= sum(bottom,benefits(bottom)*q(bottom)) ;

limit1… q(‘a’)+q(‘b’) =l= limits(‘one’);

limit2… q(‘c’) =l= limits(‘two’);

model calc /all/;

solve calc using lp maximizing totbenefits;

It should be noted that simply by defining a set top /one, two/, GAMS does not anything about sets one(bottom) and two(bottom). The way to simplify this is using a multidimensional set and one to one mapping https://www.gams.com/latest/docs/UG_SetDefinition.html#UG_SetDefinition_Multi-dimensionalSets

In the following code I create a 2D set and use it to replace the constraints limit1 and limit2.

```
Set bottom /a,b,c/;
set top/one,two /;
set trial(top, bottom);
set two_d_set(top, bottom)
/
one.a
one.b
two.c
/
;
Parameter benefits(bottom) /a 1, b 2, c 3/;
parameter limits(top) /one 5, two 4 /;
Variables
totbenefits total benefits
q(bottom) letters chosen
Positive Variable q ;
Equations
totalben total benefits
limit
;
totalben .. totbenefits =e= sum(bottom,benefits(bottom)*q(bottom)) ;
limit(top).. sum(bottom $two_d_set(top, bottom), q(bottom))=l= limits(top);
model calc /all/;
solve calc using lp maximizing totbenefits;
```

Hope this helps.

It does, I greatly appreciate it.