User Tools

Site Tools


gams:union_two_different_sets

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gams:union_two_different_sets [2017/09/02 19:08]
support
gams:union_two_different_sets [2020/05/18 17:57] (current)
Lutz Westermann add links to docu; mentin implicit set definiton as the nicer approach
Line 1: Line 1:
 ====== How do I union two different sets ====== ====== How do I union two different sets ======
 Find below an example: Find below an example:
 +
 <​code>​ <​code>​
-set i / i1*i10 /, +set i     ​/ i1*i10 /, 
-     ​j / j1*j10 /, +        ​/ j1*j10 /, 
-     ​i_u_j / set.i, set.j /;+    i_u_j / set.i, set.j /;
  
 display i_u_j; display i_u_j;
 </​code>​ </​code>​
 +
 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 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**: create a **compilation error**:
 +
 <​code>​ <​code>​
 set i / i1*i10 /, set i / i1*i10 /,
Line 17: Line 20:
 display i_u_j; ​ display i_u_j; ​
 </​code>​ </​code>​
-Please also check ''​unions'' ​in the GAMS User's Guide.+ 
 +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 [[https://​www.gams.com/​latest/​docs/​UG_SetDefinition.html#​UG_SetDefinition_ImplicitSetDefinition|Implicit Set Definitions]] as in this example: 
 + 
 +<​code>​ 
 +Set 
 +   ​food 
 +   ​fruits(food<​) ​   / apple, orange ​      / 
 +$onMulti 
 +   ​vegetable(food<​) / carrot, cauliflower / 
 +   ​meat(food<​) ​     / beef, pork          /; 
 + 
 +Display food; 
 +</​code>​ 
 + 
 +Please also check the [[https://​www.gams.com/​latest/​docs/​UG_DynamicSets.html?​search=union#​UG_DynamicSets_SetOperations|Union Operator]] ​in the GAMS User's Guide.
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/union_two_different_sets.txt · Last modified: 2020/05/18 17:57 by Lutz Westermann