Node induced subgraph matching with networkx

40 views Asked by At

I'd like to perform node-induced subgraph matching, which do not need to be fully connected, including node and edge attribute matching with networkx (see this image). Let's say I have a large graph G1 and a subgraph G2, where I would like to see whether G2 matches a subgraph of G1. Both graphs are undirected.

Using:

GM = networkx.algorithms.isomorphism.GraphMatcher(G1, G2, edge_match = edge_match_func, node_match = node_match_func)

and applying

GM.subgraph_is_monomorphic()

Does not seem to work for my case.
Does anyone know how one can solve this? Or potentially hints to algorithms solving this?

1

There are 1 answers

0
strukturen On

I found one solution:

  1. Either use the line_graph function from networkx if you don't have node and edge features and otherwise create a line graph of your original graph including the assignment of node features to the newly created edges and edge feature to the new nodes.
  2. Now one can apply graph isomorphism from networkx and it worked for my case.