ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 27 Sep 2022 23:05:18 +0200Code for deleting the edges of a subgraphhttps://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/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.Tue, 27 Sep 2022 20:55:16 +0200https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/Comment by Magus for <p>Hi all,</p>
<p>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).</p>
<p>H is given like this:
H=G.random_subgraph(.25)</p>
<p>Is there a command like G.delete_edges(H) that returns the desired graph?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64212#post-id-64212No, personal interest. I used sage for graph theory once years ago, now I'm starting to use it again, don't know much.Tue, 27 Sep 2022 23:05:18 +0200https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64212#post-id-64212Comment by Max Alekseyev for <p>Hi all,</p>
<p>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).</p>
<p>H is given like this:
H=G.random_subgraph(.25)</p>
<p>Is there a command like G.delete_edges(H) that returns the desired graph?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64208#post-id-64208Is this a homework assignment?Tue, 27 Sep 2022 22:02:40 +0200https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64208#post-id-64208Answer by rburing for <p>Hi all,</p>
<p>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).</p>
<p>H is given like this:
H=G.random_subgraph(.25)</p>
<p>Is there a command like G.delete_edges(H) that returns the desired graph?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?answer=64209#post-id-64209 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)]Tue, 27 Sep 2022 22:03:32 +0200https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?answer=64209#post-id-64209Comment by Magus for <pre><code>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)]
</code></pre>
https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64211#post-id-64211Thank you so much!Tue, 27 Sep 2022 22:46:44 +0200https://ask.sagemath.org/question/64205/code-for-deleting-the-edges-of-a-subgraph/?comment=64211#post-id-64211