示例#1
0
def writeNet_gml(net, outputFile):
    if not hasattr(outputFile, 'write'):
        raise ValueError("Parameter 'outputFile' must be a file object.")
    outputFile.write("graph [\n")
    if net.__class__ == pynet.SymmNet:
        outputFile.write("directed 0\n")
    else:
        outputFile.write("directed 1\n")

    nodeIndex = netext.Enumerator()
    for node in net:
        outputFile.write("node [\n")
        outputFile.write("id " + str(nodeIndex[node]) + "\n")
        outputFile.write("label " + str(node))
        outputFile.write("]\n")

    for edge in net.edges:
        outputFile.write("edge [\n")
        outputFile.write("source " + str(nodeIndex[edge[0]]) + "\n")
        outputFile.write("target " + str(nodeIndex[edge[1]]) + "\n")
        outputFile.write("value " + str(edge[2]) + "\n")
        outputFile.write("]\n")

    outputFile.write("]\n")
    outputFile.close()
示例#2
0
    def __init__(self, size=0, nodeNames=None):
        self.nodeIndex = netext.Enumerator()
        self.mappingOn = True

        if nodeNames != None:
            if size < len(nodeNames):
                size = len(nodeNames)
            for nodeName in nodeNames:
                self.nodeIndex[nodeName]

        self.ktree = KtreeInteger(size)