Difference integration

Use this forum to post Vensim related questions.
Post Reply
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Difference integration

Post by Phill »

I'm trying to understand why there is a difference in Levels using difference integration in 'Simulate' and 'Game' modes.
I have these two variables set as a rate and a level,
image_2021-08-17_095606.png
image_2021-08-17_095606.png (3.39 KiB) Viewed 2979 times
If I run the model with the 'Simulate' command, I get these results,
Simulate.PNG
Simulate.PNG (17 KiB) Viewed 2979 times
And if I run the same decisions in 'Game' mode, I get these results,
Game.PNG
Game.PNG (17.08 KiB) Viewed 2979 times
You can see that, in Game mode, the level results are displaced by one week (the same as using Euler integration)

But then I made the simplest model I could to test this, which has exactly the same model settings as my full model, and this doesn't happen. In this simple test model, the outputs are the same in Simulate and Game modes.

What could cause the outputs to differ in the main model simply when the mode is changed from 'Simulate' to 'Game' but not in the simple test model?

Phill
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Difference integration

Post by Administrator »

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
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

I ran my very basic test model in Game mode, with the same model settings, using difference integration and the results show the rate inputs and level totals in the same time period,
image_2021-08-17_101147.png
image_2021-08-17_101147.png (15.38 KiB) Viewed 2975 times
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

Yes, I had read the documentation. There are two things I don't understand though.
1. Why are the results different in Simulate and Game modes, even though nothing else has changed.
2. Why doesn't my basic test model show the same displacement between the rate and level results, even though it uses the same model settings and rate/level structure?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Difference integration

Post by Administrator »

Game mode is different to normal simulations as the rates/levels are calculated twice at points where decisions are made (once when you stop the simulation, then again when you re-start which overwrites the end of previous turn results).
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
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

OK, thank you for your help, I did not understand that difference between Simulate and Game modes. I've set a second rate variable with a DELAY FIXED of one time step and that gives me outputs I can display that are in line with the level outputs per time step.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Difference integration

Post by Administrator »

Games are different. If you run up to say time=5, the results are stored. Make a change, and this will now potentially change the rates that the change influences (which are then stored at time=5).

Hope that makes sense.
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
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

Yes, that makes sense and helps a lot, thank you.
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

I'm sorry to go back to this again, but using the DELAY function is throwing out my results at the end of the simulation, so it isn't a good solution.
I'm using the Vensim Linux DLL with a javascript interface to present a model of ticket sales for a event, influenced by price, price sensitivity and fluctuating demand as time passes and weather forecasts and other variables change. The user inputs price changes over time, so the model needs to run in GAME mode. My problem is, as I described before, the level values showing the cumulative ticket sales are out of step with the rate values showing ticket sales weekly. here, for example, is my output screen of values for week 3,
image_2021-08-17_123004.png
image_2021-08-17_123004.png (19.43 KiB) Viewed 2967 times
The left-hand table shows this week's sales, from the rate variables, and the right-hand columns show the cumulative sales, but are one time step behind.
Is it possible to use a command like 'vensim_get_value' in the interface to extract the updated value of the level? From the documentation here, https://www.vensim.com/documentation/26215.html it doesn't seem likely, but I'm not completely clear.
Phill
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Difference integration

Post by Administrator »

An accumulation is always delayed by a time step in Vensim. For example, today I sell x tickets, the cumulative sales will not update until the end of that time period (which will be tomorrow).

If you want to incorporate the sales at time = x into a cumulative figure, you will need to add on the rate multiplied by the time step to the actual accumulation, and report that instead.

Does this make sense?
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
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

Do you mean in the model, or in the interface? Adding the rate to the accumulation in the interface was our fall-back solution, but I thought I ought to be able to this in the model itself.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Difference integration

Post by Administrator »

Yes, you can do it in the model. It's better to do it in the model so you can check the units are correct.

Use something like
accumulation for reporting = accumulation + sum of rates in and out of accumulation * time step
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
Phill
Senior Member
Posts: 156
Joined: Wed Jun 04, 2014 2:18 pm
Vensim version: DSS

Re: Difference integration

Post by Phill »

Well, that works and solves the problem, thank you. And that welcome message, 'Units are O.K.' appears!!
Post Reply