Stop When Reaching to Zero

Use this forum to post Vensim related questions.
Post Reply
duplicating99
Junior Member
Posts: 2
Joined: Fri Nov 18, 2016 5:14 pm
Vensim version: PLE

Stop When Reaching to Zero

Post 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!
Attachments
Model_wo_Boundary_Graph.png
Model_wo_Boundary_Graph.png (9.65 KiB) Viewed 5211 times
Model_wo_Boundary.png
Model_wo_Boundary.png (29.43 KiB) Viewed 5211 times
Combat_Tanks_Helos.mdl
(3.45 KiB) Downloaded 246 times
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Stop When Reaching to Zero

Post 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)
duplicating99
Junior Member
Posts: 2
Joined: Fri Nov 18, 2016 5:14 pm
Vensim version: PLE

Re: Stop When Reaching to Zero

Post 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)
daler6
Member
Posts: 21
Joined: Tue May 28, 2013 3:19 am
Vensim version: PLE

Re: Stop When Reaching to Zero

Post 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.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Stop When Reaching to Zero

Post 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).
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Stop When Reaching to Zero

Post 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.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Stop When Reaching to Zero

Post by tomfid »

daler6
Member
Posts: 21
Joined: Tue May 28, 2013 3:19 am
Vensim version: PLE

Re: Stop When Reaching to Zero

Post by daler6 »

Thanks for the advice. I guess it is better to have TIME STEP as an input to the flow on the diagram.
Post Reply