Migrating values w/in an array (or to another if necessary!)

Use this forum to post Vensim related questions.
Post Reply
gt4569a
Junior Member
Posts: 8
Joined: Sun Mar 02, 2014 4:15 pm
Vensim version: DSS

Migrating values w/in an array (or to another if necessary!)

Post by gt4569a »

Hello,

I have a variable that stores the position of objects in a series of subareas, e.g.:

Object Position by SubArea[SubArea,ObjectID]

Currently SubArea has 3 elements: SA1, SA2, SA3
ObjectID has 60 elements: O1, O2, etc

I am trying to merge the three subareas into a single geographic area so I instead have the variable: Object Position[ObjectID]
The matrix is sparsely populated (always less than 5 objects in each subarea) and the ObjectIDs are re-used at the start of a new subarea. In other words, if there's 2 objects in SubArea 1, 2 objects in SubArea2, and 1 object in SubArea3, then the values for Object Position by SubArea[SubArea,ObjectID] might be:
[SA1,O1]: 14
[SA1,O2]: 17
[SA2,O1]: 37
[SA2,O2]: 50
[SA3,O1]: 67
(a zero is stored for any combinations of subarea and objectID with no position data)
what I would like to do is:
-retain the current value of Object Position by SubArea[SubArea,ObjectID] in the new Object Position[ObjectID] variable, if the SubArea is SA1
-if the SubArea is SA2, store the values for O1, O2, etc in O21, O22, etc (i.e. offset the location of the value by 20)
-if the SubArea is SA3, store the values for O1, O2, etc in O41, O42, etc (offset the location of the value by 40)

I've created an Object ID Number[ObjectID] variable, a SubArea ID Number[SubArea] variable, and a alternative array called "EntityID" which is the same size as "ObjectID", and tried all kinds of combinations of VECTOR functions, subranges, etc... but can't get the result I'm looking for. Is there any way to get there from here?

thank you!
Buzz
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Migrating values w/in an array (or to another if necessa

Post by tomfid »

How many objects and areas will there be eventually? It might be easier to just use brute force and track every object/area location, rather than trying to reuse IDs.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Migrating values w/in an array (or to another if necessa

Post by tomfid »

Also ... not sure I follow the problem statement. If each of 3 subareas contains up to 60 objects, wouldn't you need a vector of up to 180 elements to store the consolidated positions?
gt4569a
Junior Member
Posts: 8
Joined: Sun Mar 02, 2014 4:15 pm
Vensim version: DSS

Re: Migrating values w/in an array (or to another if necessa

Post by gt4569a »

I just need to ensure that I can accommodate a position value for up to x objects (zeroes are ignored in downstream calculations). So I can replace a zero with a non-zero value as long as I do it consistently (as above, all the non-zero values for Object IDs from SA2 are moved to the twenties- O21, O22 etc, all the SA3 to the thirties, and so on)
The number of subareas is unlikely to change but the number of objects per subarea could go up by an order of magnitude. Then I'd increase ObjectID to 600 elements to be safe, and SA2 data would go to O201, O202... and SA3 data to O301, O302...
If there is not a good solution then I think I can keep both dimensions. I was trying to avoid the processing hit in all the places where the position value is used. would rather have a 1D/ 600 element dependent variable than a 2D / 1800 element one!
thank you
Buzz
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Migrating values w/in an array (or to another if necessa

Post by tomfid »

OK, I think I get it. It seems like an inevitable consequence is that if any subarea has >20 objects, you have a problem fitting them all in with the offsets?

With that restriction, I think there's a simple solution. Do you need to pack the vector to get rid of 0s, i.e. 3,17,21,0,19 -> 3,17,21,19 ?
gt4569a
Junior Member
Posts: 8
Joined: Sun Mar 02, 2014 4:15 pm
Vensim version: DSS

Re: Migrating values w/in an array (or to another if necessa

Post by gt4569a »

I don't need to filter out the zero values for this particular model. But I'd be interested in how to do that for another project!

v/r
Buzz
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Migrating values w/in an array (or to another if necessa

Post by tomfid »

Filtering the 0s would be more complicated, but I think it's doable. I can't cook up an answer on the fly though.

Here's a stab at the simple way - not sure it's really responsive to your situation, but code is the best way to find out:

Code: Select all

objects : (o1-o60)~~|
objects1 : (o1-o20) -> objects2, objects3~~|
objects2 : (o21-o40)~~|
objects3 : (o41-o60)~~|
area : (sa1-sa3)~~|

position[area,objects] = INITIAL(area+objects/100)~~|

mapped position[objects1] = position[sa1,objects1]~~|
mapped position[objects2] = position[sa2,objects1]~~|
mapped position[objects3] = position[sa3,objects1]~~|
It seems wrong to bother with position[area,o21+] because it can't get used, so my guess is that I'm missing something.
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Migrating values w/in an array (or to another if necessa

Post by LAUJJL »

Hi

Why not just use area[object] to identify the position of the object. Of course there is only one object. This solution does not work if the same object can be in different areas.

If there are only three areas, the area[object] will be equal to 1,2 or 3 the identification number of the area. If it is needed to have a subscript named area, then the area[object] will be equal to ident[area] with subscript area=(a1,a2,a3) and ident[area] = area.

The problem is difficult to understand.

Are the areas on one dimension (one coordinate only) , do they overlap:

Are the objects unique (one object cannot be at the same time in different areas).

If they are not unique , the word objects is inadequate, and should be changed into type of objects with the subscript ‘type of objects’.

In this case there are two cases: in one area there is only one type of object at the same time, and one can define the constant ‘there is a type of object in the area’[type of objects,area] equal to 0 or 1.

In the other case, there can be more than one type of objects per area, and one can define
the constant number of object types per area[type of objects,area]

Regards.
JJ
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Migrating values w/in an array (or to another if necessa

Post by tomfid »

Yes, I think a little more information about the problem statement would help here.
Wilson
Administrator
Posts: 51
Joined: Thu Mar 06, 2003 5:05 am

Re: Migrating values w/in an array (or to another if necessa

Post by Wilson »

Hi Buzz,

Does the attached model match what your looking for ?

Wilson
Attachments
ID Model.mdl
(3.46 KiB) Downloaded 217 times
Post Reply