Page 1 of 1

Passing data between models

Posted: Fri Jul 19, 2019 2:49 pm
by Phill
Hello,
I'd appreciate some advice on how best to pass data between Vensim models.

I have one model of a production process that ends with quantities of items in stock, their cost prices and so on. A second model will take the closing stock and price values from the first as its parameters for a sales drive. If I have both models in a common directory, can I write the closing values from the first model and use the 'GET DATA' function in the second to recover them? And can I set this to run automatically, so that the first model writes the data file when it reaches the end of the run?

Best wishes,
Phill

Re: Passing data between models

Posted: Fri Jul 19, 2019 5:44 pm
by tomfid
Call this model A -> model B

If you create a data variable in model B with a name matching the output variable from model A, you can just load the run from A as an input dataset for B (see advanced tab of the sim control dialog). That way the var gets read extremely fast.

You can use GET DATA for more exotic purposes but it's slower and more work.

Re: Passing data between models

Posted: Mon Jul 22, 2019 2:57 pm
by Phill
Thank you for the advice, Tom. The two models will be running in classrooms and I really don't want the lecturers to have to perform any data management when switching from the first model to the second. Both models will run on a website, using the Vensim DLL on a server, so I think I can use the DLL to pass the output variables from model 1 as input variables for model two without the lecturers having to save and upload anything.

Re: Passing data between models

Posted: Thu Jul 25, 2019 12:48 pm
by tomfid
I'm not sure your users would need to do anything.

When you run model A, the generation of a dataset is automatic.

Similarly, when you run model B, it'll read the dataset specified on the Advanced tab without any intervention.

Two things could go wrong I guess:
- a file collision if there's a concurrent A write while B attempts to read
- if the user of A changes the run name

You could probably solve the second with a Pre/Post script.

Re: Passing data between models

Posted: Mon Jul 29, 2019 9:22 am
by Phill
Thanks again for the advice. I can probably handle those potential problems in the web interface, by not allowing model B to run until model A is finished and, as you suggest, by using pre and post scripts.