Wednesday, March 31, 2010

Creating Load Duration Curves with GAMS

In power generation analysts often want to see a Load Duration Curve ( This involves sorting, a task that is not always immediately obvious how to do in GAMS. Here is some optimized code to perform the creation of a load curve:

alias (st,month,m);
alias (d,day);
alias (tp,tradingperiod);
set k /k1*k10000/;

parameter NatlLoadByHH(month,day,tradingperiod);
parameter NatlLoadByHHsorted(month,k);

set dt(day,tradingperiod);
sum(m,NatlLoadByHH(m,d,tp)) = yes;

* map (d,tp) onto a 1 dim set k.
set map(day,tradingperiod,k);
option map(dt:k);

set monthsub(month) 'only months that are really used';

* gdxrank only sorts one dimensional parameters so we use mapping 
parameter unsorted(k),sorted(k);
parameter indx(k);
$libinclude rank
   unsorted(k) =
$  libinclude rank unsorted k indx
   sorted(k + (
card(k) + 1 - indx(k) - ord(k)) ) = unsorted(k);
   NatlLoadByHHsorted(m,k) =

It uses some obscure GAMS syntax. The advantage is that they are fast but obviously this code is difficult to read: it is no longer intuitive what is happening here. The resulting graphs in the GAMS IDE and in Excel are:



No comments:

Post a Comment