Esempio n. 1
0
import matplotlib.pyplot as plt
import cPickle
from expWorkbench.vensimDLLwrapper import VensimWarning

try:
    from networkx import graphviz_layout
except ImportError:
    raise ImportError("This example needs Graphviz and either PyGraphviz or Pydot")


from expWorkbench import vensim
from expWorkbench import vensimDLLwrapper as venDLL

vensim.load_model(r'C:\workspace\EMA-workbench\src\sandbox\sils\MODEL.vpm')

vars = venDLL.get_varnames()

graph = nx.DiGraph()
graph.add_nodes_from(vars)

for var in vars:
    try:
        causes = venDLL.get_varattrib(var, attribute=4) #cause
        for cause in causes:
            graph.add_edge(cause, var)
    except VensimWarning:
        print var

cPickle.dump(graph, open("model of Oliva.cPickle",'wb'))

pos=nx.graphviz_layout(graph,prog='twopi',args='')
print 'CSV file: '+ vensimRootName + csvFileName
print 'Converting starts...'

load_model(vensimRootName + vensimFileName + vensimExtension)

with open (vensimRootName + csvFileName, 'wb') as f:
    writer = csv.writer(f)
    writer.writerow(firstLine)                                      # The first lines are written
    writer.writerow(secondLine)
    writer.writerow(thirdLine)
    writer.writerow(blank)
    writer.writerow(csvArray)
    for varType in varTypes:                                            # Now get the variables per type
        type = varTypeNames[varType]
        typeNr = varType
        varNames = get_varnames(0, varType)
        for varName in varNames:                                        # per name, look in to their attributes
            csvArray[0]=lineNumber                                      # setup the line which needs to go to the csv
            csvArray[1]=varName
            csvArray[5]=varTypeNames[varType]
            for attributeInterest in attributesInterest:                # put the attributes also in the line, in the right place
                attribute = get_varattrib(varName, attributeInterest)
                if attribute == []:
                    attribute = [blank]
                if attributeInterest == 1:                              # Unit
                    Unit = attribute[0]
                    csvArray[3] = Unit
                elif attributeInterest == 2:                            # Comment
                    csvArray[4] = attribute[0]
                elif attributeInterest == 3:                            # Equation
                    equation = attribute[0]
Esempio n. 3
0
import cPickle
from expWorkbench.vensimDLLwrapper import VensimWarning

try:
    from networkx import graphviz_layout
except ImportError:
    raise ImportError(
        "This example needs Graphviz and either PyGraphviz or Pydot")

from expWorkbench import vensim
from expWorkbench import vensimDLLwrapper as venDLL

vensim.load_model(r'D:\epruyt\Desktop\Ageing2.vpm')
#C:\workspace\EMA-workbench\src\sandbox\sils\MODEL.vpm

vars = venDLL.get_varnames()

graph = nx.DiGraph()
graph.add_nodes_from(vars)

for var in vars:
    try:
        causes = venDLL.get_varattrib(var, attribute=4)  #cause
        for cause in causes:
            graph.add_edge(cause, var)
    except VensimWarning:
        print var

cPickle.dump(graph, open("Ageing2.cPickle", 'wb'))
print('done')
#pos=nx.graphviz_layout(graph,prog='twopi',args='')