Hello again. I am trying to prevent my models stocks, slows and auxilaries from going negative at certain points in the
simulation. I have tried setting up functions, however setting up functions for each item would make the system fairly
complex and I am not sure where I could run these functions from.
Does anyone have any ideas?
Thanks a lot,
Andrew
Andrew Hart — 04.02.08
Hi.
This is probably fairly obvious to you guys, but you can use a function to solve this problem. My initial concern was
that I would be using a seperate function for each object that I wanted to limit. I was also afraid of ending up with a
giant list of if statements or a loop that required seperate parameters for each object. In other words, it would be a
complete mess.
However, if you set up a general formula inside the function and then pass in values of each the variables for each
object, the one function is enough and it is also turns out to be quite compact.
Thanks,
Andrew
Andrei — 18.02.08
Thanks for those posts, Andrew.
For future development of AnyLogic it would be useful to know if "preventing SD variables from going
negative" is so frequently needed functionality that it deserves to be implemented at the core language level. Any
thoughts / comments / desirable behavior descriptions are welcome!
Thanks
Andrew Hart — 25.02.08
Hi Andrei,
I think the problem occurs commonly enough that it warrants implementation because there are a number of instances in
which having negative values are actually impossible (the current number of cars in a parking lot etc). The
implementation could simply be a checkbox in the general properties of the object. That's my opinion anyways.
Thanks,
Andrew
Sergey Suslov — 27.02.08
Hi Andrew and Andrei,
I know the workaround which seem to be good. You may use the conditional expression as the equation for the stock.
Let's say you have a stock named 'PotentialAdopters' which decreases with 'AdoptionRate' but not supposed to be less
than one person. You may use the following equation:
PotentialAdopters > = 1 ? AdoptionRate : 0
Any feedback on my idea is much appreciated.
Regards,
Sergey Suslov
Andrew Hart — 27.02.08
Hi Sergey,
I see no problem with your solution. In fact, it seems a lot simpler than mine. The only issue with your's is that if
you had a large number of stocks then you would have to add in a condition like that for every stock. Then again, you'd
have to call the function every time if you went with my solution.
I am not sure if this completely removes the need for built in support. I personally would think it would simplify
things that much more. This is a nice, simple solution though.
-Andrew
Rolf — 28.07.08
Hi
I'm currently assessing systems dynamics simulators and while creating some models of my own I stumbled upon this
problem.
I believe that the possibility to have max and min constraints on Levels/Stocks would be really beneficial and it would
simplify modelling. As it is now I ended up using Sergeys workaround and using that I noticed some side effects.
1) If I set the conditional on the Stock then the flow gets redraw as a normal causality arrow
2) If I set the conditional on the Flow then the flow arrow is kept but I will get division by zero errors in my
diagrams that I have inserted depending on the stock and flow rates.
My conditional statement is shown below:
WorkToDo >= 0.001 ?(ProductivityIndex*ActualProjectWorkHours*NumberOfPersonnel)/AverageHoursPerFunctionPoint : 0
Originally i had the following which meant that i still had 0.564 function points worth of work in the stock.
WorkToDo >= 1 ?(ProductivityIndex*ActualProjectWorkHours*NumberOfPersonnel)/AverageHoursPerFunctionPoint : 0
Of course I could have inserted some code to handle this but. I would rather that this were handled on the modelling
level without any sideeffects.
Best regards
/Rolf
Jose — 30.07.08
Hi,
If f is a flow and x is an stock, such that d(x)/dt=f , does "prevent stocks from going negative"
means that f changes at some times when x switches from positive to negative? If so is it then
you are in presence of a "differential equation with discontinuous right hand side", or
"hybrid system" if you prefer. You should model it on SD+DE, not only on SD, I think.
Regards,
Jose