How do I union two different sets?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 4 years ago

How do I union two different sets?

Post by aileen »

How do I union two different sets in GAMS?
aileen
User
User
Posts: 136
Joined: 4 years ago

Re: How do I union two different sets?

Post by aileen »

Find below an example:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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.
Locked