Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Following Ricardo's suggestion works:

sage: G=DiGraph(sparse=True, weighted=True)
sage: G.add_edges([(0, 1, i), (0,8,1),(1,2,1),(2,3,1),(3,4,1),(4,5,1),(4,6,1),(6,
....: 7,1),(6,8,1),(8,9,1)])
sage: G.add_edges([(u[1], u[0], -u[2]) for u in list(G.edges())])
sage: G.weighted_adjacency_matrix()
[ 0  I  0  0  0  0  0  0  1  0]
[-I  0  1  0  0  0  0  0  0  0]
[ 0 -1  0  1  0  0  0  0  0  0]
[ 0  0 -1  0  1  0  0  0  0  0]
[ 0  0  0 -1  0  1  1  0  0  0]
[ 0  0  0  0 -1  0  0  0  0  0]
[ 0  0  0  0 -1  0  0  1  1  0]
[ 0  0  0  0  0  0 -1  0  0  0]
[-1  0  0  0  0  0 -1  0  0  1]
[ 0  0  0  0  0  0  0  0 -1  0]

But, of course, G.adjacency_matrix() is still boolean:

sage: G.adjacency_matrix()
[0 1 0 0 0 0 0 0 1 0]
[1 0 1 0 0 0 0 0 0 0]
[0 1 0 1 0 0 0 0 0 0]
[0 0 1 0 1 0 0 0 0 0]
[0 0 0 1 0 1 1 0 0 0]
[0 0 0 0 1 0 0 0 0 0]
[0 0 0 0 1 0 0 1 1 0]
[0 0 0 0 0 0 1 0 0 0]
[1 0 0 0 0 0 1 0 0 1]
[0 0 0 0 0 0 0 0 1 0]

HTH,