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 /t7t18 10, t19t6 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?
One way to do this, is using the “mod” function together with the “ord” operator:
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;
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;