Ask Your Question
0

Code for deleting the edges of a subgraph

asked 2022-09-27 20:55:16 +0100

Magus gravatar image

updated 2022-09-27 22:11:15 +0100

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.

edit retag flag offensive close merge delete

Comments

Is this a homework assignment?

Max Alekseyev gravatar imageMax Alekseyev ( 2022-09-27 22:02:40 +0100 )edit

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 ( 2022-09-27 23:05:18 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-27 22:03:32 +0100

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)]
edit flag offensive delete link more

Comments

Thank you so much!

Magus gravatar imageMagus ( 2022-09-27 22:46:44 +0100 )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

Stats

Asked: 2022-09-27 20:55:16 +0100

Seen: 173 times

Last updated: Sep 27 '22