Example #1
0
 def save(self, filename):
     with open(filename, 'w') as f:
         f.write('p edges {} {}\n'.format(size(self.vertices), len(list(self.edges))))
         f.writelines(
             'n {}\n'.format(index(v)) for v in self
         )
         f.writelines(
             'e {} {}\n'.format(index(v), index(w)) for v, w in self.edges
         )
Example #2
0
def plot(graph, engine='dot', filename='output/test'):
    """Possible engines: dot, neato, fdp, sfdp, twopi, circo"""
    g = Graph(format='png', engine=engine)
    for v in graph:
        g.node(str(index(v)))

    for v, w in graph.edges:
        g.edge(str(index(v)), str(index(w)))

    g.render(filename)
Example #3
0
 def vertex_to_string(v):
     return (vertex_names[v] if v in vertex_names else '') + ' ({})'.format(str(index(v)))