Page 1 of 1

Alternative construct(s) to IF THEN ELSE () function

Posted: Thu Apr 22, 2010 8:21 am
by stumu
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

Posted: Thu Apr 22, 2010 9:23 am
by bob@vensim.com
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

Posted: Thu Apr 22, 2010 9:58 am
by LAUJJL
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

Posted: Thu Apr 22, 2010 2:42 pm
by tomfid
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