Ask Your Question
2

how do I set label of multiedges graph

asked 10 years ago

vdelecroix gravatar image

updated 10 years ago

Hello,

Let me consider a graph that I often need to use: the graph with one vertex and three loops.

sage: G = DiGraph([(0,0,'a'), (0,0,'b'), (0,0,'c')])

Is there a way to change the labels after the creation? Because

sage: G.set_edge_label(0,0,'d')
Traceback (most recent call last):
...
RuntimeError: Cannot set edge label, since there are multiple edges from 0 to 0.

Vincent

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 10 years ago

tmonteil gravatar image

Of course you would have to specify which label will be replaced by 'd'. I did not found such a method in Sage (and unfortunately the .set_edge_label() method does not offer the possibility to specify which edge you would like to relabel), but you can always fallback to:

sage: G.edges()
[(0, 0, 'a'), (0, 0, 'b'), (0, 0, 'c')]
sage: G.delete_edge((0,0,'b'))
sage: G.add_edge((0,0,'d'))
sage: G.edges()
[(0, 0, 'a'), (0, 0, 'c'), (0, 0, 'd')]
Preview: (hide)
link

Comments

Ptin mais vous vous creez du Karma entre vous maintenant ? :-PPP

Nathann gravatar imageNathann ( 10 years ago )

@Nathann J'espere que tu as vote pour nous :-D

vdelecroix gravatar imagevdelecroix ( 10 years ago )

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: 10 years ago

Seen: 1,501 times

Last updated: Jan 31 '15