User Tools

Site Tools


This is an old revision of the document!

A scalar drives the length of a set

I need my set to be able to changing depending on the value of a scalar. e.g:

 scalar dim /10/; set myset /1*dim/;

In general we do it the other way around:

set myset /1*10/;
scalar dim;
dim = card(myset);

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:

set univ the universe /1*1000/;
scalar dim /6/;
set myset(univ);

myset(univ)$(ord(univ) <= dim) = yes;

Display myset; 

* declare equations, variables and parameters over the universe set
* but use them over myset
parameter p(univ);
p(myset) = 1;

You can also pass compile time information through the command line: gams x.gms –mydim=5 with x.gms''

$if not set mydim $set mydim 5

set myset / 1*%mydim%/ 
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/a_scalar_drives_the_length_of_a_set.1214834950.txt.gz · Last modified: 2008/06/30 16:09 by support