NetworkX: subgraph isomorphism using edge and node attributes

Suppose I have 2 graphs A and B, and I want to know if A is a subgraph of B. Nodes contain attributes such as "size" and "material".

When I run:

GM = networkx.algorithms.isomorphism.GraphMatcher(B,A)
print networkx.algorithms.isomorphism.subgraph_is_isomorphic()

This only matches the graph along the edges and not along the edges and attribute.

Any clue on how to check attributes?

In addition, let B contain 2 connected graphs A.

When I run:

GM.mapping

This only outputs 1 from subgraphs A. Any idea on how to output each subgraph?

+5
source share
2 answers

I solved this using:

print GM = iso.GraphMatcher(B,A,node_match=iso.categorical_node_match(['material', 'size'],['metal',1]))

What I did not know before ['metal',1]is what is standard, not hard.

+7
source

You can iterate over all possible subgraphs as follows

GM = networkx.algorithms.isomorphism.GraphMatcher(B,A)
for subgraph in GM.subgraph_isomorphisms_iter():
    print subgraph

, B A.

. .

+2

All Articles