Iterative models/ Dynamic sets

Problems with modeling
Fred
Posts: 70
Joined: 2 years ago

Re: Iterative models/ Dynamic sets

Post by Fred » 4 months ago

Peter,

If you don't share your model please don't expect others to write code for you that works with your model out of the box!
Please find further comments below.
PeterBe wrote:
4 months ago
Thanks Fred for your answer,

there are still a few things that I do not understand.

Code: Select all

$eval tSlices ceil(card(tt)/288)
why do we need a Compile-Time Variable here? You anyways specify the number of total timeslots. So the number of time slices can be computed based on this.
Actually what this line does is exactly that. It computes the number of time slices based on the number of total timeslots.
You could also enter this number manually and define

Code: Select all

set tSlice          / ts1*ts31 /;
PeterBe wrote:
4 months ago

Code: Select all

map(tSlice,tt) = (ord(tSlice)-1)*288 < ord(tt) and (ord(tSlice))*288 >= ord(tt);
I could not find a good description of the mapping operator. What is done in the statement "(ord(tSlice)-1)*288 < ord(tt) and (ord(tSlice))*288 >= ord(tt)"?
There is no mapping operator. map(tSlice,tt) is just a two dimensional set that maps time slots to time slices if the right hand side evaluates to true.
You could rewrite this as:

Code: Select all

map(tSlice,tt)$[(ord(tSlice)-1)*288 < ord(tt) and (ord(tSlice))*288 >= ord(tt)] = yes;
Maybe that's easier to understand. I guess you know about the ord operator. If not, please consult the documentation (https://www.gams.com/latest/docs/UG_Ord ... rdOperator).
PeterBe wrote:
4 months ago

Code: Select all

option map:0:0:1; display map;
The same question here. What does 0:0:1 mean?
This just changes the formatting of the display statement in a way that I sometimes like better than the default (https://www.gams.com/latest/docs/UG_Dis ... layControl).
PeterBe wrote:
4 months ago
Regarding my code I changed the name of the variable that I used before from t to t_a. This set (and all other parameters) are loaded from the file "data_5min_Jan_DayAhead_1HH.gdx."

Code: Select all

Set
    t_a timeslices
    household households;

$call gdxxrw data_5min_Jan_DayAhead_1HH.xlsx index=index!A1
$ife errorlevel<>0 $abort Problems running GDXXRW

$GDXIN 'data_5min_Jan_DayAhead_1HH.gdx';
$LOAD t_a
$LOAD household




set tt 'super set of time steps' /t1*t8928/;
$eval tSlices ceil(card(tt)/288)
set tSlice          / ts1*ts%tSlices% /
    t(tt)           'dynamic subset of tt'
    map(tSlice,tt)  'mapping of time slice to time steps'
;
map(tSlice,tt) = (ord(tSlice)-1)*288 < ord(tt) and (ord(tSlice))*288 >= ord(tt);
option map:0:0:1; display map;
....
I also load other parameters from that file and define variables.

Code: Select all

...
Parameter


demand_heating(t, household)
$LOAD  demand_heating

demand_electrical(t, household)
$LOAD  demand_electrical

...

temperature_level_DHWTank.lo(t, household) = minimalDHWTankTemperature;
temperature_level_DHWTank.up(t, household) = maximalDHWTankTemperature;
...
If I run the model I get many error messages stating "Values for domain 1 are unknown - no checking possible" and "Set has not been initialized".
My questin is whether I have to adjust the arguments for all those variables and parameters? For example shall I change "demand_electrical(t, household)" to "demand_electrical(tt, household)" or something like that?
What is in the set you now define as t_a? Isn't that the superset of timeslots? And if so, why does the explanatory text say 'time slices'? In any case, you are defining super set tt of time slots and another set for time slices later again. That does not make sense to me. You need to understand the example first and then transfer it to your code and get the names consistent. Of course you get tons of errors if you declare parameters that are indexed with sets you did not (yet) declare.
As I said at the very beginning, if you don't share your code or at least an executable example, it makes helping you difficult!

Fred

Post Reply