Page 1 of 1

Subscript reshape (stitching)

Posted: Tue Dec 05, 2017 3:01 pm
by warrick
Good day,

Using: Vensim 7.1 DSS

After hours of trying to figure this out, including review of the reference material I hope you can help.

Background: I am modelling electricity demand. An input is the sub-hourly daily demand profiles (48 off per day) per Customer Group (for instance residential). Per Customer Group there are 6 daily profiles - Demand Season [Low Demand, High Demand] by Day of Week [Weekday, Saturday, Sunday]. These profiles are repeated over the year (366 days (2016 was a leap year)):

Demand[Customer Group,Year Day,Time of Day]=
IF THEN ELSE( Month DoY[Year Day]<K Season[K1] :OR: Month DoY[Year Day]>K Season[K2],
IF THEN ELSE( Day of Week DoY[Year Day]<=K DoW[K1],
Demand Profile[Customer Group,Low Demand,Weekday,Time of Day],
IF THEN ELSE( Day of Week DoY[Year Day]=K DoW[K2],
Demand Profile[Customer Group,Low Demand,Saturday,Time of Day],
IF THEN ELSE( Day of Week DoY[Year Day]=K DoW[K3],
Demand Profile[Customer Group,Low Demand,Sunday,Time of Day],0))),

IF THEN ELSE( Day of Week DoY[Year Day]<=K DoW[K1],
Demand Profile[Customer Group,High Demand,Weekday,Time of Day],
IF THEN ELSE( Day of Week DoY[Year Day]=K DoW[K2],
Demand Profile[Customer Group,High Demand,Saturday,Time of Day],
IF THEN ELSE( Day of Week DoY[Year Day]=K DoW[K3],
Demand Profile[Customer Group,High Demand,Sunday,Time of Day],0)))
)

Problem: For further calculations I need to 'reshape' two subscripts - Year Day (YD 1 to YD366) and Time of Day (h0030, h0100, h0130, etc) - to one subscript Annual HalfHours (AHH1 to AHH17568) which is simply YD1's 48 Time of Days then YD2's 48 Time of Days and so on. The other option is to 'reshape' Annual HalfHours to Year Day and Time of Day subscripts. I believe with Matlab this is achieved with the function "reshape". How is this done in Vensim?

I am busy with IF THEN ELSE per Time of Day but this is tedious with loads of repetition and, at times, around 50 brackets (and still have not got it to run). I am sure there is a more eloquent and simple way to achieve subscript 'stitching' in Vensim. Please assist.

Thank you in advance

Re: Subscript reshape (stitching)

Posted: Tue Dec 05, 2017 4:20 pm
by tomfid
I think VECTOR ELM MAP might be the easiest way to do this.

First you want to pre-calculate the mappings:

HalfHr of DateTime[D,T] = INITIAL( (D-1)*ELMCOUNT(T) + T-1 )
DateTime of HalfHr[HH] = INITIAL( HH-1 )

Note the -1, because VECTOR ELM MAP uses zero-based arrays, but subscript values are one-based.

Now:

Demand[HH] = VECTOR ELM MAP( Demand2[D1,T1], DateTime of HalfHr[HH] )

etc.

I'm working from memory, so hopefully I haven't botched this. There are examples in the help system.

Re: Subscript reshape (stitching)

Posted: Tue Dec 05, 2017 4:23 pm
by Administrator
I don't follow at all what you are trying to do.

One thing is for certain, don't bother nesting the IF THEN ELSE statements. It makes it impossible to debug a model if there are loads of nested statements. Chances are you can do what you need with some SUM statements or using VECTOR_ELM_MAP.

It would help is you uploaded a sample model with the constants/lookups in it to help describe what you need to achieve.

Re: Subscript reshape (stitching)

Posted: Tue Dec 05, 2017 5:22 pm
by tomfid
I was close. See attached.
halfhour datetime.mdl
(15.91 KiB) Downloaded 243 times

Re: Subscript reshape (stitching)

Posted: Wed Dec 06, 2017 8:32 am
by warrick
Thanks Tom. :D

I got the long clumsy IF THEN ELSE way to work but that is a total of 295 of them! Yes, the Administrator is correct it is not fun to debug that.

The example Tom attached allows one to go from two subscripts (for example subscript A by Subscript B) to one subscript (for example C) the length of A x B. Or even go the other way round - subscript C to subscript A by subscript B. This is all done with VECTOR ELM MAP.

This way is much more eloquent and simple. Thanks again