Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: Test
Views: 44
def graph_string(g, w = None): g.relabel() n = g.num_verts() m = g.num_edges() s = "{0} {1}\n".format(n, m) for x,y in g.edges(labels = False): s += "{0} {1}".format(x, y) if w: s += " {0}".format(w[(x, y)]) s += "\n" return s
w=dict([(e, randint(1,10)) for e in g.edges(labels = False)])
w
{(0, 1): 9, (1, 2): 10, (6, 9): 10, (4, 9): 9, (6, 8): 1, (5, 7): 3, (2, 7): 6, (1, 6): 5, (3, 8): 4, (0, 5): 6, (0, 4): 5, (2, 3): 8, (3, 4): 5, (5, 8): 4, (7, 9): 2}
print graph_string(g, w)
10 15 0 1 9 0 4 5 0 5 6 1 2 10 1 6 5 2 3 8 2 7 6 3 4 5 3 8 4 4 9 9 5 7 3 5 8 4 6 8 1 6 9 10 7 9 2