Is there something like varible in other languages in GAMS for softcoding?

Hi friends,

I’d like to write a model in GAMS and run it for a number of different data. So, for example, in one run I might have a set j /130/ and in other run I might want to change it to set j/150/. And many other similar cases.
So, when this is the case, in other languages you go with softcoding like: total_nodes = 30 and then set j /1* total_nodes/

However, it seems as if there’s no such thing as variable (with that definition) in GAMS. One thing is to use parameters. But it there any direct thing available?

The size of a static set needs to be known at compile time. So you have two ways:

  1. use a compile time variable (https://www.gams.com/latest/docs/UG_GamsCall.html#INDEX_compile_2e_time_21_variable) and use that to set the size of set j:
$if not set jsize $set jsize 30
set j /1*%jsize% /;

When you run GAMS you can pass jsize as --jsize=50 as a command line parameter.

  1. if jsize is calculated with some complex logic in your model and not easily known at compile time, you can use a super set jj with a size that is an overestimation of jsize and use a dynamic set with the calculated size:
set jj /1*1000 /, j(jj);
scalar jsize; jsize = uniformInt(10,1000);
j(jj) = ord(jj)<=jsize;
display jsize, j;

-Michael

Thanks!