Hi,
A number of experts warn against using the IF THEN ELSE function. I would like to know a better alternative construct to a situation like this one.
shortage = (desired quantity - available quantity)/desired quantity.
It is possible that with time (during a simulation), available quantity being a stock may accumulate to level where it is more than desired quantity, resulting into shortage being negative.
To avoid shortage being a negative value, I have used the IF statement as follows:
shortage = IF THEN ELSE(desired quantity>=available quantity, (desired quantity - available quantity)/desired quantity, 0)
What alternative construct(s) can be used to achieve the same results being achieved while using the IF THEN ELSE () function?
Thanks
Alternative construct(s) to IF THEN ELSE () function
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
There is nothing particularly dangerous about IF THEN ELSE. If you want to do a fractional shortage you might use
factional shortage = ZIDZ(MAX(0,desired quantity - available quantity),desired quantity)
if you are sure desired quantity will always be positive then just
factional shortage = MAX(0,desired quantity - available quantity) / desired quantity
factional shortage = ZIDZ(MAX(0,desired quantity - available quantity),desired quantity)
if you are sure desired quantity will always be positive then just
factional shortage = MAX(0,desired quantity - available quantity) / desired quantity
There was in the previous molecules version a molecule called If then else, that was transforming an if then else into something more continuous.
I noticed once that the name had changed in the new version. I cannot remember it. But studyiing the molecules may give you some ideas about making a non continuous variable continuous.
JJ
I noticed once that the name had changed in the new version. I cannot remember it. But studyiing the molecules may give you some ideas about making a non continuous variable continuous.
JJ
As Bob says, there's nothing inherently problematic about IF THEN ELSE. However, people do tend to overuse it, producing discrete decisions in situations where reality would make a gradual transition from one state to another.
Using your example, suppose that I wrote,
production rate = IF THEN ELSE( shortage > 0, 20, 10 )
That implies that the company does nothing about impending shortages until they occur, then panics and doubles production the moment they do - even if the shortage fraction is tiny (0.0001). That's the kind of logic that leads people to warn against IF THEN ELSE logic.
I think the molecule you mean is called "weighted average" though it's also referred to as "soft if then." It's still in the molecules.
Tom
Using your example, suppose that I wrote,
production rate = IF THEN ELSE( shortage > 0, 20, 10 )
That implies that the company does nothing about impending shortages until they occur, then panics and doubles production the moment they do - even if the shortage fraction is tiny (0.0001). That's the kind of logic that leads people to warn against IF THEN ELSE logic.
I think the molecule you mean is called "weighted average" though it's also referred to as "soft if then." It's still in the molecules.
Tom
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/