## Iterative models/ Dynamic sets

Problems with modeling
Fred
Posts: 70
Joined: 1 year ago

### Re: Iterative models/ Dynamic sets

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!
PeterBe wrote:
3 months ago

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:
3 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:
3 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:
3 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;

\$ife errorlevel<>0 \$abort Problems running GDXXRW

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)

demand_electrical(t, household)