Daily subsets of annual data Topic is solved

Problems with modeling
Post Reply
unyelf
User
User
Posts: 3
Joined: 6 years ago

Daily subsets of annual data

Post by unyelf »

I am trying to optimize an energy production process in a year, based on the hourly resolutions. The purchased electricity price from the grid has two different values based on the two times of a day; between 07:00-18:00 the price is 10, between 18:00-07:00 the price is 5.

The time sets are:

P_el electricityprice /t7*t18 10, t19*t6 5, ....../
t time /t1*t8760/
How can create the P_el automatically, so that I dont' need to write different sets by hand until the 8760th hour?
Lutz
User
User
Posts: 59
Joined: 7 years ago

Re: Daily subsets of annual data

Post by Lutz »

Hi,

One way to do this, is using the "mod" function together with the "ord" operator:

Code: Select all

set t hours of a year /t1*t8760/;

* Init everything to 5
parameter P_el(t) electricity price /#t 5/;

* Set peak hours to 10
P_el(t)$(mod(ord(t),24)>=7 and mod(ord(t),24)<=18 ) = 10;
If you need more structure about the time steps in your model anyway, like a mapping between your set t and the days of the year and the hours of a day, you could also build up such a mapping first, using the matching operator (https://www.gams.com/latest/docs/usergu ... ny-to-many) and use that to assign the different prices:

Code: Select all

set h          hours of a day                                     / h1*h24   /
    d          days of a year                                     / d1*d365  /
    dh(d,h)    each day has 24 h                                  / #d.#h    /
    t          hours of a year                                    / t1*t8760 /
    tdh(t,d,h) map hours of year to days of year and hours of day / #t:#dh   /;

* Init everything to 5
parameter P_el(t) electricity price /#t 5/;

* Set peak hours to 10
P_el(t)$sum(tdh(t,d,h)$(ord(h)>=7 and ord(h)<=18), 1) = 10;
Hope that helps!
Lutz
unyelf
User
User
Posts: 3
Joined: 6 years ago

Re: Daily subsets of annual data

Post by unyelf »

Lutz wrote:Hi,

One way to do this, is using the "mod" function together with the "ord" operator:

Code: Select all

set t hours of a year /t1*t8760/;

* Init everything to 5
parameter P_el(t) electricity price /#t 5/;

* Set peak hours to 10
P_el(t)$(mod(ord(t),24)>=7 and mod(ord(t),24)<=18 ) = 10;
If you need more structure about the time steps in your model anyway, like a mapping between your set t and the days of the year and the hours of a day, you could also build up such a mapping first, using the matching operator (https://www.gams.com/latest/docs/usergu ... ny-to-many) and use that to assign the different prices:

Code: Select all

set h          hours of a day                                     / h1*h24   /
    d          days of a year                                     / d1*d365  /
    dh(d,h)    each day has 24 h                                  / #d.#h    /
    t          hours of a year                                    / t1*t8760 /
    tdh(t,d,h) map hours of year to days of year and hours of day / #t:#dh   /;

* Init everything to 5
parameter P_el(t) electricity price /#t 5/;

* Set peak hours to 10
P_el(t)$sum(tdh(t,d,h)$(ord(h)>=7 and ord(h)<=18), 1) = 10;
Hope that helps!
Lutz
thank you so very much Lutz! A great explanation. Thank you for your effort!
Post Reply