# GAMS Support Wiki

### Site Tools

gams:a_scalar_drives_the_length_of_a_set

# Differences

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

 gams:a_scalar_drives_the_length_of_a_set [2008/06/30 16:26]support gams:a_scalar_drives_the_length_of_a_set [2020/05/22 10:36] (current)Michael Bussieck Both sides previous revision Previous revision 2020/05/22 10:36 Michael Bussieck 2008/06/30 16:26 support 2008/06/30 16:09 support 2008/06/30 16:09 support 2008/06/30 16:05 support 2007/05/24 23:20 external edit 2020/05/22 10:36 Michael Bussieck 2008/06/30 16:26 support 2008/06/30 16:09 support 2008/06/30 16:09 support 2008/06/30 16:05 support 2007/05/24 23:20 external edit 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/; + ​ In general we do it the other way around: In general we do it the other way around: Line 12: Line 14: ​ - 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 34: Line 36: set myset / 1*%dim%/ ​ set myset / 1*%dim%/ ​ ​ + + 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%/; + ​ +