def get_initial_lookup(self, name):
        a = vensimDLLwrapper.get_varattrib(name, 3)[0]
        elements = a.split("],", 1)
        b = elements[1][0:-1]

        list = []
        list2 = []
        number = []
        for c in b:
            if (c != "(") and (c != ")"):
                list.append(c)

        list.append(",")
        for c in list:
            if c != ",":
                number.append(c)
            else:
                list2.append(float("".join(number)))
                number[:] = []
        x = []
        y = []
        xT = True
        for i in list2:
            if xT:
                x.append(i)
                xT = False
            else:
                y.append(i)
                xT = True
        return (x, y)
 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]
                 equation = equation.lstrip(varName)
                 equation = equation.replace(r'\\n','')
                 equation = equation.replace(r'\\t','')
                 equation = equation.replace(r'\n','')
                 equation = equation.replace(r'\t','')
                 equation = equation.replace(r'  ','')
示例#3
0
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='')
nx.draw_networkx(graph, pos=pos)
plt.show()
示例#4
0
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='')
#nx.draw_networkx(graph, pos=pos)
#plt.show()