Shift if true
Shift if true
Hi,
Is it possible that in future Vensim versions, the shift if true function will be made more enjoyable ;-( or replaced by another function which places something new at the end of the array? Because now every variable linked must be adjusted with this SIT-function?
Thanks
Is it possible that in future Vensim versions, the shift if true function will be made more enjoyable ;-( or replaced by another function which places something new at the end of the array? Because now every variable linked must be adjusted with this SIT-function?
Thanks
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
I am not sure I understand the question but if you think of the shift as happening from left to right the leftmost element will get the value of the 5th argument and the rightmost element will either recieve its predecessor or have its predecessor added to it depending on the value of the 4th argument. The function itself returns the amount of stuff discarded from the chain.
If you want to increase and decrease elements within the chain you can use normal equations to do that.
If you want to increase and decrease elements within the chain you can use normal equations to do that.
What we are looking for is more of a dynamic array, adding information at the end of the array. This way not all the levels containing information about this array would have to shift. Especially as this can cause some trouble.
An example of the trouble I had with Shift If true is with naming the variables. Miscalculations can depend on the name of the level suggesting the calculation order is alphabetically.
I created a new level to keep track of some time based events, just for reporting, so it wouldn't influence my model. But since it needed to use shift if true, previously correct calculations, were now miscalculated. Changing the name seemed to be the only solution.
An example of the trouble I had with Shift If true is with naming the variables. Miscalculations can depend on the name of the level suggesting the calculation order is alphabetically.
I created a new level to keep track of some time based events, just for reporting, so it wouldn't influence my model. But since it needed to use shift if true, previously correct calculations, were now miscalculated. Changing the name seemed to be the only solution.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
If you can provide an example where using SHIFT IF TRUE causes miscalculation that would be most helpful. Computation sequence is determined causally and that process is initiated alphabetically. But shift if true is executed prior to other computations since it changes variables on the right hand side.
I have moved on and can't find the exact formulation, but the situation is as follows:
The incomming value for the new Shift If True variable is calculated from another level. This level will also be shifted, but because of the new function its shift is brought forward in the calculation order, causing an miscalculation for some other values.
Actually it was only one value, were a comparison is made between a current value and a delayed value of the same variable, using a previous zero and a current larger value as an initiation flag.
Before, the delay function was calculated before the shift, reporting a value all along the way. Due to the change of order, the calculation of the delay came forward and used the zero's of the unused subscript to initiate the flag at the wrong moment.
After some consideration I could rewrite the part with the new level/shift if true function, this time not needing any level, so it solved itself. I hope the text above makes any sense, since I tried to recreate it, but to much has changed already.
The incomming value for the new Shift If True variable is calculated from another level. This level will also be shifted, but because of the new function its shift is brought forward in the calculation order, causing an miscalculation for some other values.
Actually it was only one value, were a comparison is made between a current value and a delayed value of the same variable, using a previous zero and a current larger value as an initiation flag.
Before, the delay function was calculated before the shift, reporting a value all along the way. Due to the change of order, the calculation of the delay came forward and used the zero's of the unused subscript to initiate the flag at the wrong moment.
After some consideration I could rewrite the part with the new level/shift if true function, this time not needing any level, so it solved itself. I hope the text above makes any sense, since I tried to recreate it, but to much has changed already.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
I can sort of see what you are saying but I suspect it is incomplete. Among other things delays are computed outside the computation within a time step so probably several things were going on. If you come across such a situation again and can send me something to demonstrate it that would be helpful.
It has been a while, but I came accross a similar situation.
This time some values are calculated before and some after their shift has occured. The model is a Business Game of a shipyard for Maritime students. So far I just used 1 ship in production. Problems only occur when a second ship is taken in production after some time.
In the variable "Nr of Ships Ordered" in the "Ship Data" View is responsible for the addition of the vessel.
The problems occur in the "Production Location" view: "Work in Progress" changes in the second time step after input, while "Nr Queued Parcels" and "Initial Order Size Array" change in the third time step after input.
Still I would like to get rid of the whole use of Shift If True-Functions. Is there a simple algorithm to input new input on the first open spot in a subscript series which also works for variables with more than one subscript. By this I mean, put all the input in line based on the rightmost subscript. e.g. take input[sub] and level[sub, subsub] all input is put under Level[sub,subsub3] or so for this and all other levels.
This time some values are calculated before and some after their shift has occured. The model is a Business Game of a shipyard for Maritime students. So far I just used 1 ship in production. Problems only occur when a second ship is taken in production after some time.
In the variable "Nr of Ships Ordered" in the "Ship Data" View is responsible for the addition of the vessel.
The problems occur in the "Production Location" view: "Work in Progress" changes in the second time step after input, while "Nr Queued Parcels" and "Initial Order Size Array" change in the third time step after input.
Still I would like to get rid of the whole use of Shift If True-Functions. Is there a simple algorithm to input new input on the first open spot in a subscript series which also works for variables with more than one subscript. By this I mean, put all the input in line based on the rightmost subscript. e.g. take input[sub] and level[sub, subsub] all input is put under Level[sub,subsub3] or so for this and all other levels.
- Attachments
-
- MBG.mdl
- (391.4 KiB) Downloaded 690 times
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
I have to admit I am not following your discussion. However, if what you want to do is pop something into a new subscript spot and leave everything else alone use this
next pos indicated = SAMPLE IF TRUE(
want new pos,next pos indicated+1,1)
and
next pos = MIN(next pos indicated,
ELMCOUNT(position))
Then
position is active[position] = IF THEN ELSE(
position = nex pos,1,0)
and then use position is active to manage inflows as in
inflow[position] = unsubscripted inflow *
position is active[position]
I think this is what you are after. You may also be able to make some mileage with the VECTOR ELM MAP function but that needs to be used with caution.
next pos indicated = SAMPLE IF TRUE(
want new pos,next pos indicated+1,1)
and
next pos = MIN(next pos indicated,
ELMCOUNT(position))
Then
position is active[position] = IF THEN ELSE(
position = nex pos,1,0)
and then use position is active to manage inflows as in
inflow[position] = unsubscripted inflow *
position is active[position]
I think this is what you are after. You may also be able to make some mileage with the VECTOR ELM MAP function but that needs to be used with caution.
It comes close. What I have here is a multi-project, limited resources organisation. The positions I'm refering to are building projects. Old ones will be completed and new ones will come up.
To keep track of them I used the Shift If True function, but this is not a genuine function. I found out the variable it is applied to can have two values depending on when it is read (before or after the shift). This is the problem I ran into in the model posted with my previous post.
I already have a variable which indicates which positions are active (only zeros and ones) What I'm looking for now is a generic way to find the first subscript that is zero (based on the normal order of the subscript).
I've come up with a simple (not so elegant) solution.
Postion Available = if then else (positions in use[pos1] = 0, 1, if then else (positions in use[pos2] = 0, 2, if then else (positions in use[pos3] = 0, 3, etc.
The rest is simular to your solution.
THX
[Edited on 10-8-2004 by Pruyn]
To keep track of them I used the Shift If True function, but this is not a genuine function. I found out the variable it is applied to can have two values depending on when it is read (before or after the shift). This is the problem I ran into in the model posted with my previous post.
I already have a variable which indicates which positions are active (only zeros and ones) What I'm looking for now is a generic way to find the first subscript that is zero (based on the normal order of the subscript).
I've come up with a simple (not so elegant) solution.
Postion Available = if then else (positions in use[pos1] = 0, 1, if then else (positions in use[pos2] = 0, 2, if then else (positions in use[pos3] = 0, 3, etc.
The rest is simular to your solution.
THX
[Edited on 10-8-2004 by Pruyn]
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
That's what they are supposed to do. I get something different, it might be my version of Vensim. But I get the following results. Perhaps its time I ask for an update, I'm using dss 5.1a.
Time (Month) 5 5.03125 5.0625 5.09375 6.8125
Nr Queued Parcels[PF,Ship1] 824 824 824 824 824
Nr Queued Parcels[PF,Ship2] 0 0 0 824 824
Nr Queued Parcels[SA,Ship1] 618 618 618 618 618
Nr Queued Parcels[SA,Ship2] 0 0 0 618 618
Nr Queued Parcels[A,Ship1] 206 206 206 206 206
Nr Queued Parcels[A,Ship2] 0 0 0 206 206
Nr Queued Parcels[HE,Ship1] 103 103 103 103 103
Nr Queued Parcels[HE,Ship2] 0 0 0 103 103
Nr Queued Parcels[OF,Ship1] 1 1 1 1 1
Nr Queued Parcels[OF,Ship2] 0 0 0 1 1
Nr Queued Parcels[Testing,Ship1] 1 1 1 1 1
Nr Queued Parcels[Testing,Ship2] 0 0 0 1 1
Time (Month) 5 5.03125 5.0625 5.09375 6.8125
Work In Progress Array[Metalworks,PF,Ship1] 9,308 9,365 0 0 1,555
Work In Progress Array[Metalworks,PF,Ship2] 0 0 9,422 0 1,555
Work In Progress Array[Metalworks,SA,Ship1] 6,893 6,936 0 0 1,113
Work In Progress Array[Metalworks,SA,Ship2] 0 0 6,978 0 1,113
Work In Progress Array[Metalworks,A,Ship1] 9,398 9,456 0 0 1,468
Work In Progress Array[Metalworks,A,Ship2] 0 0 9,507 0 1,468
Work In Progress Array[Metalworks,HE,Ship1] 10,578 10,578 0 0 1,409
Work In Progress Array[Metalworks,HE,Ship2] 0 0 10,712 0 1,409
Work In Progress Array[Metalworks,OF,Ship1] 0 0 0 0 0
Work In Progress Array[Metalworks,OF,Ship2] 0 0 0 0 0
Work In Progress Array[Metalworks,Testing,Ship1] 0 0 0 0 0
Work In Progress Array[Metalworks,Testing,Ship2] 0 0 0 0 0
As can be seen by counting the zeros, the first one changes one time step later than the second one. A solution that seems to work is delaying all shift if true functions by one time step, but this is not what I want.
As said before, could be the problem of an older version, but still I have decided to go for a different approach and everything works fine now.
I still thank you for your time, Jeroen
Time (Month) 5 5.03125 5.0625 5.09375 6.8125
Nr Queued Parcels[PF,Ship1] 824 824 824 824 824
Nr Queued Parcels[PF,Ship2] 0 0 0 824 824
Nr Queued Parcels[SA,Ship1] 618 618 618 618 618
Nr Queued Parcels[SA,Ship2] 0 0 0 618 618
Nr Queued Parcels[A,Ship1] 206 206 206 206 206
Nr Queued Parcels[A,Ship2] 0 0 0 206 206
Nr Queued Parcels[HE,Ship1] 103 103 103 103 103
Nr Queued Parcels[HE,Ship2] 0 0 0 103 103
Nr Queued Parcels[OF,Ship1] 1 1 1 1 1
Nr Queued Parcels[OF,Ship2] 0 0 0 1 1
Nr Queued Parcels[Testing,Ship1] 1 1 1 1 1
Nr Queued Parcels[Testing,Ship2] 0 0 0 1 1
Time (Month) 5 5.03125 5.0625 5.09375 6.8125
Work In Progress Array[Metalworks,PF,Ship1] 9,308 9,365 0 0 1,555
Work In Progress Array[Metalworks,PF,Ship2] 0 0 9,422 0 1,555
Work In Progress Array[Metalworks,SA,Ship1] 6,893 6,936 0 0 1,113
Work In Progress Array[Metalworks,SA,Ship2] 0 0 6,978 0 1,113
Work In Progress Array[Metalworks,A,Ship1] 9,398 9,456 0 0 1,468
Work In Progress Array[Metalworks,A,Ship2] 0 0 9,507 0 1,468
Work In Progress Array[Metalworks,HE,Ship1] 10,578 10,578 0 0 1,409
Work In Progress Array[Metalworks,HE,Ship2] 0 0 10,712 0 1,409
Work In Progress Array[Metalworks,OF,Ship1] 0 0 0 0 0
Work In Progress Array[Metalworks,OF,Ship2] 0 0 0 0 0
Work In Progress Array[Metalworks,Testing,Ship1] 0 0 0 0 0
Work In Progress Array[Metalworks,Testing,Ship2] 0 0 0 0 0
As can be seen by counting the zeros, the first one changes one time step later than the second one. A solution that seems to work is delaying all shift if true functions by one time step, but this is not what I want.
As said before, could be the problem of an older version, but still I have decided to go for a different approach and everything works fine now.
I still thank you for your time, Jeroen