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

Use this forum to post Vensim related questions.
Post Reply
stumu
Junior Member
Posts: 6
Joined: Tue May 12, 2009 12:12 pm

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

Post 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
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post 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
LAUJJL
Senior Member
Posts: 1477
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

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

Post 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
Post Reply