Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It's not completely clear to me what you mean by "indexing" a graph edge. If you want to give them labels, you can do that using set_edge_label:

sage: D = DiGraph({ 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] })
sage: D.edges()
[(0, 1, None),
 (0, 2, None),
 (0, 3, None),
 (1, 0, None),
 (1, 2, None),
 (2, 3, None),
 (3, 4, None),
 (4, 0, None),
 (4, 5, None),
 (5, 1, None)]
sage: for i, (u, v, l) in enumerate(D.edges()):                                                            
....:     D.set_edge_label(u, v, "edge # {}".format(i))
....:     
sage: D.edges()
[(0, 1, 'edge # 0'),
 (0, 2, 'edge # 1'),
 (0, 3, 'edge # 2'),
 (1, 0, 'edge # 3'),
 (1, 2, 'edge # 4'),
 (2, 3, 'edge # 5'),
 (3, 4, 'edge # 6'),
 (4, 0, 'edge # 7'),
 (4, 5, 'edge # 8'),
 (5, 1, 'edge # 9')]
sage: D.show(edge_labels=True)

produces

image description