Page 1 of 1

order of calculation of subscripts

Posted: Wed Jul 04, 2018 7:43 am
by LAUJJL
Hi

When you have a suscript like say period: (p1-p100) and vensim has to calculate for instance the variable var[period] it starts to calculate p1 then p2 etc…
Is there anyway to make Vensim calculate backwards p100 then p99 etc…

Regards.

JJ

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 8:12 am
by Administrator
You can force the calculation order.

some calc[P99] = a + B + 0 * some calc[P100]
some calc[P98] = a + B + 0 * some calc[P99]
some calc[P97] = a + B + 0 * some calc[P98]
some calc[P96] = a + B + 0 * some calc[P97]

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 8:23 am
by LAUJJL
Hi

This solution works if the subscript size is limited, although entering 100 individual equations is rather cumbersome, but if you have a subscript period: (p1-p1000) it is not tractable, especially if you want to modify the size of the subscript.

Regards.

JJ

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 9:44 am
by Administrator
If you can give me an example of what you have (and why you need to do this), I can probably figure something out for you.

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 10:05 am
by LAUJJL
Hi

The subscript represents time.

I need this to calculate optimal policies each time period, using dynamic programming methods starting most of the time in the past (infinite horizon or not) and going backwards to the present.
When one uses traditionnal mapping going from the past, if the number of periods is to big, after about 1000 periods, Vensim stops and warns about too many recursions. These recursions are generated by the way Vensim calculates the subscripted variables. If it was calculated going from the future there would be no recursion.

The solution I have found so far is to build a special variable that inverses the order of the subscripts: invers var[p0] = var[p100], invers var[p1] = var[p99] etc… et make the calculation from the invers var with forward going subscripts that does not generate any recursion. Once the calculation is done I invers the invers var back to the var.

my objective is to keep the readability of the model and use a subscript value equal to the time.

I could use an invers subscript right at the beginning something that works too but it makes the model difficult to read.

See joined a simplistic model summarising the method but with 10000 periods, long to analyse when one load it, but generating no recursion.

Best regards.

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 2:46 pm
by tomfid
I think inverting the order of the subscript is the only easy option.

It might be easier to do with VECTOR ELM MAP.

Re: order of calculation of subscripts

Posted: Wed Jul 04, 2018 4:14 pm
by LAUJJL
Hi

thank you for your answers.

Regards.

JJ