## Controlling set elements Topic is solved

Problems with modeling
nickelms
User
Posts: 2
Joined: 1 year ago

### Controlling set elements

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));
``````

Renger
Posts: 633
Joined: 4 years ago

### Re: Controlling set elements

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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

nickelms
User
Posts: 2
Joined: 1 year ago

### Re: Controlling set elements

Thanks, that works perfectly. I used nested loops for the 3 dimensions of the sets and it worked.