Bach
Bach

Reputation: 6227

Check whether a networkx graph is a subgraph of another one

I have a networkx graph G, and I wish to check whether another networkx graph, H, can be embedded in it. Simple examples include:

etc.

I know the problem is in general NP-complete, but I would like to see if something a little bit better than naive exists, or if you have recommendations about how to write such a method.

Upvotes: 5

Views: 3649

Answers (1)

Hooked
Hooked

Reputation: 88248

I've been doing some extensive work with graphs in python and I'd recommend not using networkx for larger problems. Since the library is pure python it is perfect for smaller graphs and portability, but for larger subgraph isomorphisms I've found that graph-tool works very well.

The function call you are looking for in graph-tool is under the topology section:

graph_tool.topology.subgraph_isomorphism

Upvotes: 5

Related Questions