• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How to test if one graph is a subgraph of another in Networkx?

Resolved: How to test if one graph is a subgraph of another in Networkx?

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I am new to building directed graphs with networkx and I’m trying to work out how to compare two graphs. More specifically, how to tell if a smaller graph is a subgraph (unsure of the exact terminology) of a larger graph
As an example, assume I have the following directed graph: Graph A
I would like to be able to check whether a series of smaller graphs are sub-graphs of this initial graph. Returning a True value if they are (graph B), and False if they are not (graph C):
Graph B Graph B = Sub-graph of Graph A
Graph C Graph C != Sub-graph of Graph A
Example Code
I’ve had a look through the documentation and cannot seem to find what I need. An alternative I have been considering is to represent the nodes as a sequence of strings, and then searching for each substring in the main graphs string sequence – however, I can’t imagine this is the most effecient/effective/stable way to solve the problem.

Answer:

You are looking for a subgraph isomorphisms.
Note that the operation can be slow for large graphs, as the problem is NP-complete.

If you have better answer, please add a comment about this, thank you!

directed-graph networkx python
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Resolved: CMake path for python3 libraries doesn’t change (windows 10)

24/03/2023

Resolved: GLMM with quasi-Poisson distribution

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.