Page 1 of 1

Controlling set elements

Posted: Thu Jul 25, 2019 11:46 am
by nickelms
Hi, I want to return the set element that corresponds to a particular parameter. More specifically, I have a set (sHours) from 1 to 8760 hours in a year. I want to find the hour of peak demand and then find the available generation capacity that corresponds to that hour. I can find the maximum demand and the maximum available generation capacity in a region (see code below) but I cannot figure out how to find the hour of maximum demand in the region and use that to find the available generation in the region in the hour. Many thanks for any ideas!!

Code: Select all

pAnnRegCapBal(sRegions, sYearsMod, "Avail Cap")=    smax(sHours, sum(sGensets$(pGenRegion(sGenSets, sRegions)=1), vInstalledCap.l(sYearsMod, sGenSets) * pGenAvailFinal(sYearsMod, sHours, sGenSets)));
pAnnRegCapBal(sRegions, sYearsMod, "Peak Dem") =    smax(sHours, pHlyDemand(sRegions, sYearsMod, sHours));

Re: Controlling set elements

Posted: Thu Jul 25, 2019 4:00 pm
by Renger
Hi

Here a suggestion

Code: Select all

set i /1*8760/;

parameter test(i), maxtest, hour;

test(i) = uniform(0,100);

maxtest = smax(i, test(i));

display maxtest;

loop(i$(maxtest = test(i)),

  hour = i.val;
);

display hour;
Cheers
Renger

Re: Controlling set elements

Posted: Thu Jul 25, 2019 4:58 pm
by nickelms
Thanks, that works perfectly. I used nested loops for the 3 dimensions of the sets and it worked.