Subscript reshape (stitching)

Use this forum to post Vensim related questions.
Post Reply
warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

Subscript reshape (stitching)

Post 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
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Subscript reshape (stitching)

Post 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.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Subscript reshape (stitching)

Post 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.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Subscript reshape (stitching)

Post by tomfid »

I was close. See attached.
halfhour datetime.mdl
(15.91 KiB) Downloaded 235 times
warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

Re: Subscript reshape (stitching)

Post 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
Post Reply