Problem getting 0 if value is below 0

Use this forum to post Vensim related questions.
Post Reply
Julian.92
Junior Member
Posts: 5
Joined: Wed May 29, 2019 2:32 pm
Vensim version: PRO

Problem getting 0 if value is below 0

Post by Julian.92 »

Hi everyone,
I want to build a calculator for bus fleets and how they change over the years. For now, I have three different bus types (diesel, battery, hybrid) and a starting fleet. In the Model I gave the bus types numbers from 1 to 3, which simultaneously is a hierarchy. Based on this hierarchy, the busses should decrease/ increase as follows:
Type “1” decreases, type “2” shall increase for decrease of type “1”. When the value for type “1” is zero (no more busses of type “1” left), type “2” shall decrease and type “3” shall increase for decrease of type “2”.
Each bus type has its own yearly based decrease rate.

The problem now is, that if the decrease rate of a certain type isn’t a multiple of the starting amount of that bus type, the number of busses won’t drop exactly at 0.

For example:
Diesel busses at beginning = 30
Yearly decrease rate = 7
Result: Year 0 = 30 busses; Year 1 = 23 busses; Year 2 = 16 busses; Year 3 = 9 busses; Year 4 = 2 busses; Year 5 = -5 busses

I tried everything, but I just don’t find a way to tell Vensim to output 0 (busses), if the value is below 0 and/ or the decrease rate is higher than the busses still left.

I hope I could make my problem clear. The .mdl file is also attached.

Thanks for your help in advance!
Julian
Attachments
Bus Fleet.mdl
(5 KiB) Downloaded 150 times
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Problem getting 0 if value is below 0

Post by tomfid »

I think you have way too much discrete logic packed into the stock equation. The INTEG should ONLY handle accumulation, i.e. INTEG( inflows-outflows, init val).

This is complex enough that I would tend to avoid arrays. Instead, copy-paste to make 3 fleet structures, and lay out all the logic explicitly in the flows.

Units checking is also essential in cases like this. For example:

Fleet[1] = INTEG( IF THEN ELSE(Fleet["1"] > 0, (Old["1"] - New["1"])/2, IF THEN ELSE(Fleet["1"] <= 0, 0, 0)), Starting Fleet["1"] )

is dimensionally inconsistent. The left side has units of bus, while the right side is bus*year, unless the /2 is interpreted as an implicit time constant with units of year.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Problem getting 0 if value is below 0

Post by tomfid »

Also, part of the problem is flow-flow connections. Every physical stock needs first-order negative feedback on the outflow in order to pass the reality check "nothing in stock -> no outflow."
fonfbout.png
fonfbout.png (4.53 KiB) Viewed 3053 times
The practical implication is that there must be a causal arrow from the stock to its outflow, and the equation for the outflow must be such that it is 0 when the stock is 0.
Julian.92
Junior Member
Posts: 5
Joined: Wed May 29, 2019 2:32 pm
Vensim version: PRO

Re: Problem getting 0 if value is below 0

Post by Julian.92 »

Thank you so much for your prompt answer(s).
Since there will be about 10 bus types in the end (I just had 3 in this model to keep it more simple in the beginning) everything should be in 1 fleet structure.
Also the Model will not only consist of this fleet "calculator", but will be expanded with costs and emissions for all of the different types. It will be a quite complex model in the end, which is why I think it would be easier to handle if everything was in 1 fleet structure.

The units were crap, since I restructered the model from time to time, sorry for that, but the graph shows the results it's supposed to show, so it's not about the units.

The "/2" was necessary, because otherwise Old["1"] - New["1"] would be (-7) - 7 = -14. So divided by 2 it'll get you the -7 busses you want to decrease.

I allready had all the calculations layed out in the flows, but came to the exact same results, which are actually correct, I just have to get Vensim to output a 0 instead of negative values.

I think I understand what you want to tell me with "the equation for the outflow must be such that it is 0 when the stock is 0.", but I just can't get a clear thought right now, since I'm stuck on this problem the whole day.
So here's the other .mdl file, with all the calculations layed out on the flows, as well as a causal arrow I already had made, but like I mentioned before, the problem is still the same here.
I would be more than happy if you could help me once more and take a look at this file and the equation for the outflow, on which I think I'm stuck mainly.
Attachments
Bus Fleet 2.mdl
(4.43 KiB) Downloaded 138 times
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Problem getting 0 if value is below 0

Post by Administrator »

The "/2" was necessary, because otherwise Old["1"] - New["1"] would be (-7) - 7 = -14. So divided by 2 it'll get you the -7 busses you want to decrease.
You really do not want to divide here by 2. The stock should only have inflows and outflows, what you've got half of the inflows/outflows. If you need to divide by 2 somewhere, do not do it in the stock, do it in the rate and make sure the 2 is a constant (make it a parameter).

I've attached a modified version of your model. I've simplified the outflow "old", I couldn't follow the logic in the equation for hierarchy 2 and 3. Hopefully this helps a little.
Bus Fleet 2 modified.mdl
(6.09 KiB) Downloaded 148 times
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: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Problem getting 0 if value is below 0

Post by tomfid »

This is a more "classic sd" way to do it, with continuous busses:
Bus Fleet 2f.mdl
(8.55 KiB) Downloaded 186 times
Julian.92
Junior Member
Posts: 5
Joined: Wed May 29, 2019 2:32 pm
Vensim version: PRO

Re: Problem getting 0 if value is below 0

Post by Julian.92 »

Thanks a lot for your help!
Your model doesn't exactly simulate what I want/ need, but you couldn't know all the details of course. However, your model(s) gave me some points to think about and I managed to correct my model. Everything works now as it should, allthough the model might not be the built in the most SD way possible, but I will have a look on this once more, later in the project.

Thanks again for your time and help! :)
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Problem getting 0 if value is below 0

Post by tomfid »

Great!
Post Reply