Monday, January 25, 2010

Unneeded loops in GAMS

From a post on the GAMS list:

yes if the data are to be aggregated one would have a one to many tuple and do sums, sma, smin or whatever is needed 

ie

tuple(period,month,year) /1.(jar.1970,feb.1970,....)

loop(period,

    newdata(period)=sum(tuple(period,month,year),data(month,year));

);

I see many, many models where the LOOP is used without much reason. This is an example. The more correct way of writing this is by removing the loop construct and using the GAMS parallel assignment which gives an implicit loop:

    newdata(period)=sum(tuple(period,month,year),data(month,year));