How do I union two different sets?
Moderator: aileen
Forum rules
Please ask questions in the other sub-forums
Please ask questions in the other sub-forums
How do I union two different sets?
How do I union two different sets in GAMS?
Re: How do I union two different sets?
Find below an example:
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:
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:
Please also check the Union Operator in the GAMS User's Guide.
Code: Select all
set i / i1*i10 /,
j / j1*j10 /,
i_u_j / set.i, set.j /;
display i_u_j;
Code: Select all
set i / i1*i10 /,
j / j1*j10, i5 /,
i_u_j / set.i, set.j /;
display i_u_j;
Code: Select all
Set
food
fruits(food<) / apple, orange /
$onMulti
vegetable(food<) / carrot, cauliflower /
meat(food<) / beef, pork /;
Display food;