User Tools

Site Tools


gams:a_scalar_drives_the_length_of_a_set

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
gams:a_scalar_drives_the_length_of_a_set [2020/05/22 10:36]
Michael Bussieck
gams:a_scalar_drives_the_length_of_a_set [2020/05/28 11:31] (current)
Michael Bussieck
Line 7: Line 7:
 </​code>​ </​code>​
  
-In general ​we do it the other way around:+Before going into the details please note that set elements are not numbers -- even if you choose labels that look like numbers. In fact, our recommendation is to avoid using set elements that look like numbers since it can cause confusion in different circumstances. If you write 
 + 
 +   Set t /t1 * t5/; 
 +   Set i /i1 * i5/; 
 + 
 +you won't get the two confused. If you write 
 + 
 +   Set i /5 * 9/; 
 +   Set j /3 * 8/; 
 + 
 +you'll be surprised to find that the order of elements in Set j is 5, 6, 7, 8, 3, 4. That's because the ordering comes from the collection of all unique set elements in a GAMS program -- and the order is defined by when they appear. The only advantage of labels that look like numbers is that you can use the [[https://​www.gams.com/​latest/​docs/​UG_SetDefinition.html#​INDEX__2f_val_22_set_21_attributes_2d__21_set|.val]] suffix. 
 + 
 +But now back to the original question. ​In general ​GAMS prefers to do this the other way around:
 <​code>​ <​code>​
-set myset /1*10/;+set myset /i1*i10/;
 scalar dim; scalar dim;
 dim = card(myset);​ dim = card(myset);​
Line 16: Line 28:
 In the GAMS philosophy sets drive the model. Creating sets based on data (eg scalars) requires the use of dynamic sets, which are a little bit more difficult to use than static sets. Moreover, you need to have an estimate of how big your scalar will maximal ever be. Here is a fragment that illustrates how you can use dynamic sets: In the GAMS philosophy sets drive the model. Creating sets based on data (eg scalars) requires the use of dynamic sets, which are a little bit more difficult to use than static sets. Moreover, you need to have an estimate of how big your scalar will maximal ever be. Here is a fragment that illustrates how you can use dynamic sets:
 <​code>​ <​code>​
-set univ the universe /1*1000/;+set univ the universe /i1*i1000/;
 scalar dim /6/; scalar dim /6/;
 set myset(univ);​ set myset(univ);​
Line 34: Line 46:
 $if not set dim $set dim 5 $if not set dim $set dim 5
  
-set myset / 1*%dim%/ ​+set myset / i1*i%dim%/ ​
 </​code>​ </​code>​
  
Line 42: Line 54:
 scalar dim /10/;  scalar dim /10/; 
 $eval DIM dim $eval DIM dim
-set myset /1*%DIM%/;+set myset /i1*i%DIM%/;
 </​code>​ </​code>​
  
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/a_scalar_drives_the_length_of_a_set.txt · Last modified: 2020/05/28 11:31 by Michael Bussieck