Determining if a graph is a subgraph of another graph

153 views
Skip to first unread message

Kamran Soomro

unread,
Feb 24, 2013, 6:04:06 AM2/24/13
to pygraphvi...@googlegroups.com
Hi,

I want to determine if a particular graph is a subgraph of another graph using networkx. How can I achieve this? Please note I am NOT looking to determine isomorphic subgraphs. I want the answer to be true if and only if the smaller graph is an actual subgraph. E.g.

G1 = A -> B -> C
G2 = B -> C

(Result should be true)

G1 = A -> B -> C
G2 = C -> D

(Result should be false)

Thanks.

Daniel Schult

unread,
Feb 24, 2013, 8:47:50 AM2/24/13
to pygraphvi...@googlegroups.com
Can you first check that each node in the subgraph is in the graph and then check that each edge of the subgraph is in the graph?   [using "n in G" and G.has_edge(n1,n2)]

Kamran Soomro

unread,
Feb 24, 2013, 8:57:55 AM2/24/13
to pygraphvi...@googlegroups.com
Hi Daniel,

I figured it out. The node_match function is what I needed to achieve what I wanted to do.

–Kamran
> --
> You received this message because you are subscribed to the Google Groups "pygraphviz-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pygraphviz-disc...@googlegroups.com (mailto:pygraphviz-disc...@googlegroups.com).
> To post to this group, send email to pygraphvi...@googlegroups.com (mailto:pygraphvi...@googlegroups.com).
> Visit this group at http://groups.google.com/group/pygraphviz-discuss?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



Reply all
Reply to author
Forward
0 new messages