How can I turn an MDL or a VPMX file into a C/C++ file
How can I turn an MDL or a VPMX file into a C/C++ file
I have been given an .mdl file and a .vpmx file, and I have to turn one of them into a C/C++ equivalent file. Which is the best way to do that? Is it using sdverywhere or is there a better way? Because sdeverywhere gives me some errors...
-
- Super Administrator
- Posts: 4829
- Joined: Wed Mar 05, 2003 3:10 am
Re: How can I turn an MDL or a VPMX file into a C/C++ file
I'm assuming you want to put your model on the web? As an academic PLE user, Forio is an option as well as SD everywhere. PLE is mainly for learning how to build Vensim models, it's not really designed to be capable of publishing to the web.
Vensim DSS does have the capability to compile to web assembly directly.
Vensim DSS does have the capability to compile to web assembly directly.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: How can I turn an MDL or a VPMX file into a C/C++ file
Yes we want to make a web application, more specifically a videogame, but we want to only use free software, that is why Forio and Vensim DSS are not viable options.
So the idea is to convert the model into C/C++ and insert it into Unreal Engine that is based on C++ and is good for videogames.
So far I have tried to use sdeverywhere but I have had 2 major problems.
FIRST PROBLEM
I tried to create the C++ code by using the following command
sde build mymodel.mdl
but I got the following errors:
I worked around this problem by implementing the functions _RANDOM_NORMAL, _GET_TIME_VALUE and _RANDOM_UNIFORM by myself.
SECOND PROBLEM
The second problem is that I don't know how to call the functions that have been generated by sde.
After implementing the missing functions I got a code which compiled correctly. So I took a look at the C/C++ file representing my model and I found the following auto generated functions: initConstants, initLevels, evalLevels, evalAux and other functions that are called by these ones.
I noticed the the variables that I am interested in are calculated in the evalLevels and evalAux functions. Therefore I organized my code in the following manner:
The results that I got are not exactly as expected therefore there must be some problems in this sequence of calls...
So the idea is to convert the model into C/C++ and insert it into Unreal Engine that is based on C++ and is good for videogames.
So far I have tried to use sdeverywhere but I have had 2 major problems.
FIRST PROBLEM
I tried to create the C++ code by using the following command
sde build mymodel.mdl
but I got the following errors:
Code: Select all
mymodel.c:266:16: warning: implicit declaration of function '_RANDOM_NORMAL' is invalid in C99 [-Wimplicit-function-declaration]
_pinknoise = _RANDOM_NORMAL(-1000000.0, 1000000.0, _noisemean, _noisestddev, _noiseseed);
^
mymodel.c:268:17: warning: implicit declaration of function '_GET_TIME_VALUE' is invalid in C99 [-Wimplicit-function-declaration]
_noiseseedt = _GET_TIME_VALUE(2.0, 0.0, 10.0);
^
mymodel.c:270:10: warning: implicit declaration of function '_RANDOM_UNIFORM' is invalid in C99 [-Wimplicit-function-declaration]
_ri1 = _RANDOM_UNIFORM(0.0, 1.0, _noiseseedt);
^
mymodel.c:409:114: warning: implicit declaration of function '_RANDOM_NORMAL' is invalid in C99 [-Wimplicit-function-declaration]
_random_number_generator = (pow(((2.0 - (_time_step / _noisecrrtime)) / (_time_step / _noisecrrtime)), 0.5)) * _RANDOM_NORMAL(-1000000.0, 1000000.0, _noisemean, _noisestddev, _noiseseed);
I worked around this problem by implementing the functions _RANDOM_NORMAL, _GET_TIME_VALUE and _RANDOM_UNIFORM by myself.
SECOND PROBLEM
The second problem is that I don't know how to call the functions that have been generated by sde.
After implementing the missing functions I got a code which compiled correctly. So I took a look at the C/C++ file representing my model and I found the following auto generated functions: initConstants, initLevels, evalLevels, evalAux and other functions that are called by these ones.
I noticed the the variables that I am interested in are calculated in the evalLevels and evalAux functions. Therefore I organized my code in the following manner:
Code: Select all
//I start out by calling the functions with a name starting with "init..."
//because usually they are the first to be called
initConstants();
initLevels();
//In the following line I set my inputs using a function (setF) that I have defined and implemented
setF(f1, f2, f3);
//Then I try to go on with the simulation by incrementing the auto generated _time variable defined in model.cpp
for (int month = initial_month; month < initial_month + 12; month++) {
//The setTime function, that I have defined and implemented, modifies the _time variable
setTime(month);
evalLevels();//Here I calculate the levels
}
evalAux();//Here I calculate the auxiliaries
//In the following line I get the results by calling a function that I have defined and implemented (getOutputStructure)
//which returns only the variables that I am interested in
Output output = getOutputStructure();
Re: How can I turn an MDL or a VPMX file into a C/C++ file
The Vensim DSS publication to webassembly doesn't require any software after the initial publication. Your application runs in the client browser as pure html/javascript/wasm.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: How can I turn an MDL or a VPMX file into a C/C++ file
Tomfid I can't use Vensim DSS because I can only use free software
-
- Super Administrator
- Posts: 4829
- Joined: Wed Mar 05, 2003 3:10 am
Re: How can I turn an MDL or a VPMX file into a C/C++ file
SDE is your only option then. You'll need to contact the SDE folks for help with that.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
-
- Super Administrator
- Posts: 4829
- Joined: Wed Mar 05, 2003 3:10 am
Re: How can I turn an MDL or a VPMX file into a C/C++ file
One note. Vensim PLE is only free for academic use. If you use it for any other reason, you need to purchase a licence.
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559