First time here? Check out the FAQ!

Ask Your Question
0

Code for deleting the edges of a subgraph

asked 2 years ago

Magus gravatar image

updated 2 years ago

Hi all,

I have as inputs a simple graph G and a subgraph H. I want as output the graph G-H, defined as the graph obtained from G by removing the edges of H (without removing any vertices).

H is given like this: H=G.random_subgraph(.25)

Is there a command like G.delete_edges(H) that returns the desired graph?

Thank you.

Preview: (hide)

Comments

Is this a homework assignment?

Max Alekseyev gravatar imageMax Alekseyev ( 2 years ago )

No, personal interest. I used sage for graph theory once years ago, now I'm starting to use it again, don't know much.

Magus gravatar imageMagus ( 2 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 2 years ago

rburing gravatar image
sage: G = Graph([(1,2),(2,3),(3,4),(4,5)])
sage: H = Graph([(1,2),(4,5)])
sage: G_minus_H = G.copy()
sage: G_minus_H.delete_edges(H.edges())
sage: G_minus_H.vertices()
[1, 2, 3, 4, 5]
sage: G_minus_H.edges(labels=False)
[(2, 3), (3, 4)]
Preview: (hide)
link

Comments

Thank you so much!

Magus gravatar imageMagus ( 2 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

Stats

Asked: 2 years ago

Seen: 244 times

Last updated: Sep 27 '22