gams:a_scalar_drives_the_length_of_a_set

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

Both sides previous revision Previous revision | |||

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 |
||
---|---|---|---|

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 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 NOTICE
PRIVACY POLICY
gams/a_scalar_drives_the_length_of_a_set.txt · Last modified: 2020/05/22 10:36 by Michael Bussieck