Vensim¨ model to Mathematica¨ notebook Utility

v1.0 June 18, 2015.

Rogelio Oliva

roliva@tamu.edu

Mays Business School

 

 

Purpose

This utility creates, from a Vensim model (*.mdl format), a model description suitable for the Mathematica routines to perform the Loop Eigenvalue Elasticity Analysis (LEEA) as described in Kampmann and Oliva (2006) and the Dynamic Decomposition Weight Analysis (DDWA) as described in Saleh et al (2010). The LEEA toolset is available here and the DDWA toolset is available here.

 

Input file:

- Vensim *.mdl format file

Output file:

- Mathematica *.nb file with 10 subsections

- The fist subsection reports the source of the file

- The following eight subsections describe the model

  a list of level variables

  a list of initial conditions for level variables

  a list of auxiliary variables

  a list of model parameters

  a list of table functions

  a list of data variables, i.e., variables with no equation

  a list of simulation parameters

  a list of summary variables needed by Kampmann's module

- The last subsection reports the model equations that could not be processes.

- Each element of the level and auxiliary variable lists is itself a list with the {lhs,rhs} format. The rest of the lists contain assignations var->value.

- Note that the first six model subsections are within the "ModelVariable'" context. This is to eliminate potential conflict between the model variables and variables used in the LEEA and DDWA utilities

Limitations:

- The utility has the following limitations:

-     spaces or underscores are removed from variable names to be consistent with Mathematica's notation.

-     special characters in variable names, i.e., names that in Vensim require quotes are not supported.

-     special functions (e.g., max(x), min(x), exp(x), log(x)) are not supported; please replace manually with MathematicaÕs notation (e.g., Max[x], Min[x], Exp[x], Log[x]).

-     dynamic functions (e.g. SMOOTH, DELAY) are not supported; please replace with explicit stock (INTEG) formulations.

-     IF THEN ELSE statements are not supported.

-     table functions are recognized only if they follow the format used for the graphical representation in Vensim name([x,x]-[y,y],(x1,y1),..).

-     macros are not supported.

-     arrays are not supported.

- Note that the LEEA and DDWA utilities have more stringent limitations—e.g., processing table functions—please be aware of these limitations when preparing the Mathematica Notebooks.

 

 

Usage

The core functionality of the utility is in a Perl script named mdl2nb.pl and can be downloaded here. The script is downloaded as a *.zip file, so you will have to uncompress it before runing it.

 

To run the script, Perl needs to be installed in your computer. Perl is Open Source Software available for Unix, Linux, Windows and Macintosh computers. Perl is pre-installed in most Unix, Linux and the Macintosh OSX environments (see http://learn.perl.org/installing/ for directions on how to install Perl in your computer and http://learn.perl.org/first_steps/ for instructions on how to run a script).

 

If the Perl script and the *.mdl file are in the same directory, and the command prompt is pointing to that directory, then the following command from the Unix prompt (Terminal prompt in Mac OSX, Command prompt in Windows) will pipe the *.mdl file to the Perl script:

 

% perl mdl2nb.pl my_model.mdl

 

Note that is it not necessary for the script and the *.mdl file to be in the same directory as the two inputs to Perl can be specified independently. For example:

 

% perl /Users/Shared/bin/mdl2nb.pl /Users/roliva/xref/my_model.mdl

 

Where "~/mdl2nb.pl" and "~/my_model.mdl" stand for the full path to the Perl script and the *.mdl file to be processed.

 

Output

The output file will be placed in the same directory as the input file and will have the same name as the input file but with the standard Mathematica notebook termination (*.nb). Note that the output file is also a text file and can be reviewed and edited with a word processor.

 

After placing the *.nb file in a directory visible to Mathematica, all you need to do to load the model information into Mathematica is to open the notebook from within Mathematica and evaluate it [Evaluation>Evaluate Notebook].

 

 

History

v0.1 03/2005.  Core functionality

v0.2 03/2005.   Fixed bug in s/// to id INTEG equations

v0.3 03/2005.   Simplified output eliminating text not needed by Methematica

           Introduced "source" cell and $version reporting

v0.4 03/2005.   Changed parsing strategy for more robust handling of spaces

           Streamlined code -- removed unnecessary subroutines to handle spaces

           Modified output to match CEK template

           Fixed bug to close lists properly when empty

           Updated embedded documentation

v0.5 05/2005.   Implemented functionality over Internet

v1.0 06/2015.   Reverted functionality to work as Perl script

           Implemented Mathematica Context "ModelVariables`" to avoid variable conflicts

           Extracted "empty" equations as data

 

© Rogelio Oliva, 2005, 2015.