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
Next revision
Previous revision
Last revision Both sides next revision
gams:a_scalar_drives_the_length_of_a_set [2008/06/30 16:09]
support
gams:a_scalar_drives_the_length_of_a_set [2020/05/22 10:36]
Michael Bussieck
Line 3: Line 3:
 I need my set to be able to changing depending on the value of  I need my set to be able to changing depending on the value of 
 a scalar. e.g: a scalar. e.g:
-   scalar dim /10/; set myset /1*dim/;+<​code>​ 
 +scalar dim /10/; set myset /1*dim/; 
 +</​code>​
  
 In general we do it the other way around: In general we do it the other way around:
Line 12: Line 14:
 </​code>​ </​code>​
  
-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. 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 /1*1000/;
Line 28: Line 30:
 </​code>​ </​code>​
  
-You can also pass compile time information through the command line: ''​gams x.gms --dim=5 with ''​x.gms'' ​+You can also pass compile time information through the command line: ''​gams x.gms --dim=5'' ​with ''​x.gms'' ​
 <​code>​ <​code>​
 $if not set dim $set dim 5 $if not set dim $set dim 5
Line 34: Line 36:
 set myset / 1*%dim%/ ​ set myset / 1*%dim%/ ​
 </​code>​ </​code>​
 +
 +In addition, if the value of the scalar is known at compile time (e.g. due to a data statement) you can use ''​$eval''​ to build a corresponding set:
 +
 +<​code>​
 +scalar dim /10/; 
 +$eval DIM dim
 +set myset /1*%DIM%/;
 +</​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