Created on 25 mei 2011
Code author: jhkwakkel <j.h.kwakkel (at) tudelft (dot) nl>
convenience functions and classes to be used in combination with Vensim. This module contains frequently used functions with error checking. For more fine grained control, the vensimDLLwrapper can also be used directly.
this allows you to turn off the work in progress dialog that Vensim displays during simulation and other activities, and also prevent the appearance of yes or no dialogs.
defaults to 2, suppressing all windows, for more fine grained control, use vensimDLLwrapper directly .
load the model
Parameters: | file – the location of the .vpm file to be loaded. |
---|---|
Exception : | raises a VensimError if the model cannot be loaded. |
read a .cin file
Parameters: | file – location of the .cin file. |
---|---|
Exception : | raises a VensimWarning if the cin file cannot be read. |
set the value of a variable to value
current implementation only works for lookups and normal values. In case of a list, a lookup is assumed, else a normal value is assumed. See the DSS reference supplement, p. 58 for details.
Parameters: |
|
---|
Convenient function to run a model and store the results of the run in the specified .vdf file. The specified output file will be overwritten by default
Parameters: | file – the location of the outputfile |
---|---|
Exception : | raises a VensimError if running the model failed in some way. |
Retrieves data from simulation runs or imported data sets.
Parameters: |
|
---|---|
Returns: | an array with the values for varname over the simulation |
This is a convenience extension of ModelStructureInterface that can be used as a base class for performing EMA on Vensim models. This class will handle starting Vensim, loading a model, setting parameters on the model, running the model, and retrieving the results. To this end it implements:
For the simplest case, it is sufficient to only specify _init__ in more detail. That is, specify the uncertainties and the outcomes. For more elaborate cases, for example when using different policies, it might be necessary to overwrite or extent model_init, while for dealing with lookups etc. it might be necessary to also extent run_model. The examples folder contains examples of each of these extensions.
Note
This class relies on the Vensim DLL, thus a complete installation of Vensim DSS is needed.
attribute that can be set when one wants to load a cin file
The path to the vensim model to be loaded.
note: The model file should be a .vpm file
Init of the model, The provided implementation here assumes that self.modelFile is set correctly. In case of using different vensim models for different policies, it is recomended to extent this method, extract the model file from the policy dict, set self.modelFile to this file and then call this implementation through calling super.
Parameters: |
|
---|
Method for reseting the model to its initial state before runModel was called
default name of the results file (default: ‘Current.vdf’)
Method for running an instantiated model structure. the provided implementation assumes that the keys in the case match the variable names in the Vensim model.
If lookups are to be set specify their transformation from uncertainties to lookup values in the extension of this method, then call this one using super with the updated case dict.
if you want to use cinFiles, set the cinFile, or cinFiles in the extension of this method to self.cinFile.
Parameters: | case – the case to run |
---|
Note
setting parameters should always be done via run_model. The model is reset to its initial values automatically after each run.
attribute used for getting a slice of the results array instead of the full array. This can cut down the amount of data saved. Alternatively, one can specify in Vensim the time steps for saving results