Page 1 of 1
Stop When Reaching to Zero
Posted: Fri Nov 18, 2016 11:52 pm
by duplicating99
Hello everyone,
I'm working on repeat a model using Vensim PLE 6.4b (32-bit) from a paper I read, but the model I create does not match the result in that paper. In brief, I need every stocks to be zero when they reached to the zero, since I cannot get negative number in this model. I've tried to use if else then statement like this:
IF THEN ELSE(Iraq Tanks >= 0,-Iraq Tanks Attrition Rate, Iraq Tanks=0),
and I set zero as the minimum for those stocks but it won't work.
Is there any way that I could ask Vensim to avoid getting negative numbers? Thank you!
Re: Stop When Reaching to Zero
Posted: Sun Nov 20, 2016 1:39 am
by tomfid
Generally the constraint to impose is:
Code: Select all
Stock = INTEG( inflow - outflow, init stock)
init stock = ...
inflow = ...
outflow = MIN( desired outflow, max outflow)
desired outflow = ...
max outflow = stock/min time to drain stock
Often min time to drain stock is equal to time step for convenience, so you can use the following shortcut:
Code: Select all
outflow = MIN(desired outflow, stock/TIME STEP)
Re: Stop When Reaching to Zero
Posted: Sun Nov 20, 2016 4:35 am
by duplicating99
Thank you Tom. I searched the forum with some of the key words, but it did not give me what I wanted. However, the website in that post really helps!
Any way, I appreciate your reply!
tomfid wrote:Generally the constraint to impose is:
Code: Select all
Stock = INTEG( inflow - outflow, init stock)
init stock = ...
inflow = ...
outflow = MIN( desired outflow, max outflow)
desired outflow = ...
max outflow = stock/min time to drain stock
Often min time to drain stock is equal to time step for convenience, so you can use the following shortcut:
Code: Select all
outflow = MIN(desired outflow, stock/TIME STEP)
Re: Stop When Reaching to Zero
Posted: Thu Feb 06, 2020 6:57 pm
by daler6
Another, perhaps simpler way to do this without adding in a new auxiliary variable (desired outflow) is to modify the equation for the stock from:
Stock = INTEG( inflow - outflow, init stock)
to
Stock = INTEG(max(inflow-outflow,-Stock/TIME STEP), init stock)
As light disadvantage to this is, in your diagram, you now you have an arrow going from TIME STEP directly to your Stock. This is a bit ugly and breaks the (my) rule of not having anything go into your Stock other than flows and initial values.
Re: Stop When Reaching to Zero
Posted: Thu Feb 06, 2020 7:17 pm
by Administrator
daler6 wrote: ↑Thu Feb 06, 2020 6:57 pm
Another, perhaps simpler way to do this without adding in a new auxiliary variable (desired outflow) is to modify the equation for the stock from:
Stock = INTEG( inflow - outflow, init stock)
to
Stock = INTEG(max(inflow-outflow,-Stock/TIME STEP), init stock)
As light disadvantage to this is, in your diagram, you now you have an arrow going from TIME STEP directly to your Stock. This is a bit ugly and breaks the (my) rule of not having anything go into your Stock other than flows and initial values.
I'd always advise against this approach. Keep things simple and clear, it means others can easily see what you are doing (and you can as well if you come back to the model after time away).
Re: Stop When Reaching to Zero
Posted: Thu Feb 06, 2020 7:48 pm
by tomfid
An equally simple limit is:
outflow = MIN( desired outflow, stock/TIME STEP )
The assumption here is that the dynamics of the constraint are not of much interest, so that it's OK to assume that the minimum outflow time is equal to TIME STEP. This is usually fine.
This avoids having TIME STEP as an input to the stock on the diagram.
Re: Stop When Reaching to Zero
Posted: Thu Feb 06, 2020 7:49 pm
by tomfid
Re: Stop When Reaching to Zero
Posted: Mon Feb 10, 2020 3:24 am
by daler6
Thanks for the advice. I guess it is better to have TIME STEP as an input to the flow on the diagram.