How do I union two different sets?

How do I union two different sets in GAMS?

Find below an example:

set i     / i1*i10 /,
    j     / j1*j10 /,
    i_u_j / set.i, set.j /;

display i_u_j;

The trouble is that i and j need to be disjoint. Otherwise you get a compilation error about a redefined element when defining i_u_j. Moreover, i and j are not subsets of i_u_j. The following code will create a compilation error:

set i / i1*i10 /,
     j / j1*j10, i5 /,
     i_u_j / set.i, set.j /;

display i_u_j;

A much nicer way to define a superset as a union of its dependent sub-sets (which also does not complain about elements being in more than one of the sub-sets) is through Implicit Set Definitions as in this example:

Set
   food
   fruits(food<)    / apple, orange       /
$onMulti
   vegetable(food<) / carrot, cauliflower /
   meat(food<)      / beef, pork          /;

Display food;

Please also check the Union Operator in the GAMS User’s Guide.