Skip to content

Adds an edge-induced subgraph method - #1740

Merged
dschult merged 2 commits into
networkx:masterfrom
jfinkels:edge-subgraph
Feb 7, 2016
Merged

dschult merged 2 commits into
networkx:masterfrom
jfinkels:edge-subgraph

Conversation

@jfinkels

Copy link
Copy Markdown
Contributor

Fixes issue #330.

@jfinkels

Copy link
Copy Markdown
Contributor Author

This new function can be used in pull request #1538, and can be used in the function _optimum_spanning_tree in algorithms.tree.mst.

@jfinkels

Copy link
Copy Markdown
Contributor Author

This can also be used in #1703, so that a copy of the graph will not be required.

This adds the ability to get an edge-induced subgraph for graphs,
digraphs, multigraphs, and multidigraphs.
@jfinkels

jfinkels commented Feb 4, 2016

Copy link
Copy Markdown
Contributor Author

I think this is an extremely useful function for implementing other algorithms, I'd like to push for its inclusion!

@dschult

dschult commented Feb 4, 2016

Copy link
Copy Markdown
Member

I am looking at this and thinking about the best implementation in terms of
views vs new graph structures, etc. This implementation looks pretty good
if we go the route of creating a shallow copy of the graph. I'm playing
with views generally. Aric has been a proponent for a long time of a
subgraph view as well.

Something like:

restrict_to_edges = lambda u,v: return u != v
G.edge_subgraph(restrict_to_edges)

And it should be lightweight (low ram) and fast. :}

On Thu, Feb 4, 2016 at 1:31 AM, jfinkels [email protected] wrote:

I think this is an extremely useful function for implementing other
algorithms, I'd like to push for its inclusion!

—
Reply to this email directly or view it on GitHub
#1740 (comment).

@dschult

dschult commented Feb 7, 2016

Copy link
Copy Markdown
Member

I was hoping to find a nice light-weight "view approach" to edge-subgraph. But this is a good implementation of creating a new shallow graph copy with only those edges. I'm going to merge and if/when we come up with a "view" version we can morph this at that time. Thanks @jfinkels

@dschult
dschult merged commit 99198f6 into networkx:master Feb 7, 2016
dschult added a commit that referenced this pull request Feb 7, 2016
branch 'edge-subgraph' from @jfinkels
@hagberg

hagberg commented Feb 7, 2016

Copy link
Copy Markdown
Member

How is this different from G = nx.Graph(subedges)?

@chebee7i

chebee7i commented Feb 8, 2016

Copy link
Copy Markdown
Member

Node information is preserved (if the node is the head or tail of one of the edges).

@dschult

dschult commented Feb 8, 2016

Copy link
Copy Markdown
Member

The edge data is "shallow copied" in that the subgraph uses the same datadict as the graph.
I guess this method violates the "one way to do it" principle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants