Page 1 of 1

Coupling R with VENSIM

Posted: Fri Mar 20, 2020 5:30 pm
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

Re: Coupling R with VENSIM

Posted: Fri Mar 20, 2020 5:59 pm
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.

Re: Coupling R with VENSIM

Posted: Fri Mar 20, 2020 6:23 pm
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

Re: Coupling R with VENSIM

Posted: Fri Mar 20, 2020 6:34 pm
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.

Re: Coupling R with VENSIM

Posted: Fri Mar 20, 2020 6:43 pm
by rodrigo?solis
Sounds good. I'll get to work on that and report back on Monday. Thanks!

Re: Coupling R with VENSIM

Posted: Thu Mar 26, 2020 6:30 pm
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