Ask Your Question
0

Graph matrix into network flow

asked 2012-08-06 03:19:34 -0500

brenogil gravatar image

Hello,

I have this marix:

M=matrix(ZZ,6,9,[[1,1,1,0,0,0,0,0,0],[0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,1,1,1],[-1,0,0,-1,0,0,-1,0,0],[0,-1,0,0,-1,0,0,-1,0],[0,0,-1,0,0,-1,0,0,-1]])

and I am looking to get something like this:

image description

How can I do it?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2012-08-06 05:04:09 -0500

fidbc gravatar image

Hi,

If you just want the digraph, without the weights you can use

sage: D=DiGraph(M,format='incidence_matrix')

If you want to incorporate weights, you can try something like

sage: A=Matrix(ZZ,[[0,0,0,1,2,3],[0,0,0,4,5,6],[0,0,0,7,8,9],[0,0,0,0,0,0],[0,0,0,0,0,0],[0,0,0,0,0,0]])
sage: D=DiGraph(A,format='weighted_adjacency_matrix')
edit flag offensive delete link more

Comments

Thank you! I do no know if I am missing some package or something but I cannot make the graph 'behave' like the picture above.

brenogil gravatar imagebrenogil ( 2012-08-06 20:13:29 -0500 )edit
1

If you want the vertex labels to appear as in your picture you might want to consider using the `relabel` method. For the edge labels to appear in the plot you can send an `edge_labels=True` argument to the `plot` method.

fidbc gravatar imagefidbc ( 2012-08-07 02:57:17 -0500 )edit

Thanks for the hand! I'll pay you a beer whenever I am in Canada!

brenogil gravatar imagebrenogil ( 2012-08-07 21:06:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-08-06 03:19:34 -0500

Seen: 302 times

Last updated: Aug 06 '12