Please comment on attachment.
Thanks
[Edited on 6-10-2004 by mike]
arbitrary access to subscripts in Vensim
arbitrary access to subscripts in Vensim
- Attachments
-
- VensimSubscriptFunctionality.doc
- (20.5 KiB) Downloaded 602 times
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Just so we can see the contents of the Word document on the forum, here it is.
Comment on Vensim;
How come users do not have arbitrary access/manipulation/control
of subscripts ?
the following psuedo code hopefully makes the point:
MACRO: manageArray( array[a], arbitrary-a-subscript, adjValue )
For a-sub = 1 to elmcount
if a-sub = arbitrary-a-subscript then
array[a-sub] = adjValue
EXIT loop
Next a-sub
return array[a]
:END MACRO:
At present External functions need to be called to do this sort of thing !
Not being an SD heavy; it could be Vensim’s aversion to letting users get flexible access to subscripts
may be at odds with other important criteria for the Vensim language functionality. ?????
It would be nice to have ... even if Vensim constrained such manipulation only to auxilliary variables
leaving the rates and levels alone !
[Edited on 10-6-2004 by Administrator]
[Edited on 10-6-2004 by Administrator]
Comment on Vensim;
How come users do not have arbitrary access/manipulation/control
of subscripts ?
the following psuedo code hopefully makes the point:
MACRO: manageArray( array[a], arbitrary-a-subscript, adjValue )
For a-sub = 1 to elmcount
if a-sub = arbitrary-a-subscript then
array[a-sub] = adjValue
EXIT loop
Next a-sub
return array[a]
:END MACRO:
At present External functions need to be called to do this sort of thing !
Not being an SD heavy; it could be Vensim’s aversion to letting users get flexible access to subscripts
may be at odds with other important criteria for the Vensim language functionality. ?????
It would be nice to have ... even if Vensim constrained such manipulation only to auxilliary variables
leaving the rates and levels alone !
[Edited on 10-6-2004 by Administrator]
[Edited on 10-6-2004 by Administrator]
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
You can do loops in Vensim fairly easily, the following should do what you gave as an example.
manageArray[a-sub] =
sum (
if then else (
Array ID[a-sub!] = arbitrary-a-subscript
, adjValue
, 0 )
)
Array ID[a-sub] = a-sub
The sum loops over all elements in the array, and only takes the value where
a-sub = arbitrary-a-subscript
as all the other values will be zero.
I find it is only very advanced things that I need to put into external functions (custom allocation routines etc).
Hope this helps,
Tony.
manageArray[a-sub] =
sum (
if then else (
Array ID[a-sub!] = arbitrary-a-subscript
, adjValue
, 0 )
)
Array ID[a-sub] = a-sub
The sum loops over all elements in the array, and only takes the value where
a-sub = arbitrary-a-subscript
as all the other values will be zero.
I find it is only very advanced things that I need to put into external functions (custom allocation routines etc).
Hope this helps,
Tony.
Thank you; I should have elaborated; the challenge is when one has to do this sort of thing on arrays with more than one dimension and where the arbitrary subscript value sent in can itself be an array applying adjustments to a number of elements in one dimension; I've found SAMPLE IF TRUE solutions in 1 dimension doesn't work in more dimensions similtaneously. Also Vensim does not allow mapping sub-ranges of one index into another index ( where something like summation would be cumulative;
i.e. varA[a2] =sum(varB[b10,b20] ,
varA[a3] = sum(varB[b10,b20,b30] ....
which kind of defeats the purpose of subscripts in that they can no longer be used ....
but in fact my problem is an allocation problem; so as you pointed out; in that case one must resort to external function calls. Co-flows don't provide the discreet-ness I'm looking for.
Thank you Tony; I appreciate the guidance.
Mike
[Edited on 6-10-2004 by mike]
[Edited on 6-10-2004 by mike]
i.e. varA[a2] =sum(varB[b10,b20] ,
varA[a3] = sum(varB[b10,b20,b30] ....
which kind of defeats the purpose of subscripts in that they can no longer be used ....
but in fact my problem is an allocation problem; so as you pointed out; in that case one must resort to external function calls. Co-flows don't provide the discreet-ness I'm looking for.
Thank you Tony; I appreciate the guidance.
Mike
[Edited on 6-10-2004 by mike]
[Edited on 6-10-2004 by mike]
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Custom allocation I always do in an external function (you have complete control then about what you allocate where). Just be careful to not use array external functions when you pass in a subrange.
Are the Vensim allocation routines any use?
A side note (in case it helps) regarding the following.
>> varA[a2] =sum(varB[b10,b20] ,
>> varA[a3] = sum(varB[b10,b20,b30] ....
If this is what you want to do then you can do that as well.
varA[SUBA] =
sum (
if then else (
SUB B ID[SUBB!] <= SUB A ID[SUBA]
, varB[SUBB!]
, 0 )
)
SUB B ID[SUBB] = SUBB
That will do a cumulative sum over the B subscript range.
Are the Vensim allocation routines any use?
A side note (in case it helps) regarding the following.
>> varA[a2] =sum(varB[b10,b20] ,
>> varA[a3] = sum(varB[b10,b20,b30] ....
If this is what you want to do then you can do that as well.
varA[SUBA] =
sum (
if then else (
SUB B ID[SUBB!] <= SUB A ID[SUBA]
, varB[SUBB!]
, 0 )
)
SUB B ID[SUBB] = SUBB
That will do a cumulative sum over the B subscript range.