Coupling R with VENSIM

Use this forum to post Vensim related questions.
Post Reply
rodrigo?solis
Member
Posts: 22
Joined: Mon Jan 21, 2019 11:41 pm
Vensim version: DSS

Coupling R with VENSIM

Post by rodrigo?solis »

Hi, I'm trying to find a way of coupling R with VENSIM so I can run a Bayes Sampler in R, run a simulation in VENSIM, and return the Payoff to R for the next round of Bayes Sampling.

In theory, I could generate a CIN file from R--> run VENSIM with that CIN file generated --> export results from simulation and feedback into R.

However, I am not sure of the exact lines of code (in both R and VENSIM) to make this run.

Any ideas?

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

Re: Coupling R with VENSIM

Post by Administrator »

I've never used R. Is it capable of loading a dll and calling functions in it? That would be the easiest way.
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
rodrigo?solis
Member
Posts: 22
Joined: Mon Jan 21, 2019 11:41 pm
Vensim version: DSS

Re: Coupling R with VENSIM

Post by rodrigo?solis »

Yes, R has the dyn.load ( ) function in R can Load or unload DLLs.

So, would I have to convert my Vensim.mdl into a DLL and then directly running it from VENSIM?

Sorry for the naive questions, I've never used the DLL functionality in Vensim and I am not familiarized at all on how all that works
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Coupling R with VENSIM

Post by Administrator »

There are examples with Vensim that show how to use the DLL in Excel, C/C++, C# etc. R is just another language, if it allows DLLs to be loaded, you should be able to use the code in the samples that ship with Vensim to duplicate it in R.

If you can write the R code to the point where you want to pass some values to the model, I can take a look next week to see if I can figure out the actual interface between R and the Vensim DLL.
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
rodrigo?solis
Member
Posts: 22
Joined: Mon Jan 21, 2019 11:41 pm
Vensim version: DSS

Re: Coupling R with VENSIM

Post by rodrigo?solis »

Sounds good. I'll get to work on that and report back on Monday. Thanks!
rodrigo?solis
Member
Posts: 22
Joined: Mon Jan 21, 2019 11:41 pm
Vensim version: DSS

Re: Coupling R with VENSIM

Post by rodrigo?solis »

Hi Tom,

I explored a lot of avenues on how to dynamically coupling R with VENSIM, but I couldn't find the way. I am sure there's a way, but maybe my limited programming knowledge is not helping.

A good thing is that I noticed that I can do exactly what I wanted to do from within VENSIM without the need of R. I wanted to obtain posterior distributions on a number of uncertain parameters that I have, and then, using those posteriors for sensitivity analysis of my system.

However, now that I found that VENSIM has that option, I am a bit confused on how to use it. I will stop my message here and open a new topic in the forum with my questions in that regard.

Thanks
Post Reply