Returns True if the graphs G1 and G2 are isomorphic and False otherwise.
Parameters : | G1, G2: graphs :
node_match : callable
edge_match : callable
|
---|
See also
numerical_node_match, numerical_edge_match, numerical_multiedge_match, categorical_node_match, categorical_edge_match, categorical_multiedge_match
Notes
Uses the vf2 algorithm [R185].
References
[R185] | (1, 2) L. P. Cordella, P. Foggia, C. Sansone, M. Vento, “An Improved Algorithm for Matching Large Graphs”, 3rd IAPR-TC15 Workshop on Graph-based Representations in Pattern Recognition, Cuen, pp. 149-159, 2001. http://amalfi.dis.unina.it/graph/db/papers/vf-algorithm.pdf |
Examples
>>> import networkx.algorithms.isomorphism as iso
For digraphs G1 and G2, using ‘weight’ edge attribute (default: 1)
>>> G1 = nx.DiGraph()
>>> G2 = nx.DiGraph()
>>> G1.add_path([1,2,3,4],weight=1)
>>> G2.add_path([10,20,30,40],weight=2)
>>> em = iso.numerical_edge_match('weight', 1)
>>> nx.is_isomorphic(G1, G2) # no weights considered
True
>>> nx.is_isomorphic(G1, G2, edge_match=em) # match weights
False
For multidigraphs G1 and G2, using ‘fill’ node attribute (default: ‘’)
>>> G1 = nx.MultiDiGraph()
>>> G2 = nx.MultiDiGraph()
>>> G1.add_nodes_from([1,2,3],fill='red')
>>> G2.add_nodes_from([10,20,30,40],fill='red')
>>> G1.add_path([1,2,3,4],weight=3, linewidth=2.5)
>>> G2.add_path([10,20,30,40],weight=3)
>>> nm = iso.categorical_node_match('fill', 'red')
>>> nx.is_isomorphic(G1, G2, node_match=nm)
True
For multidigraphs G1 and G2, using ‘weight’ edge attribute (default: 7)
>>> G1.add_edge(1,2, weight=7)
>>> G2.add_edge(10,20)
>>> em = iso.numerical_multiedge_match('weight', 7, rtol=1e-6)
>>> nx.is_isomorphic(G1, G2, edge_match=em)
True
For multigraphs G1 and G2, using ‘weight’ and ‘linewidth’ edge attributes with default values 7 and 2.5. Also using ‘fill’ node attribute with default value ‘red’.
>>> em = iso.numerical_multiedge_match(['weight', 'linewidth'], [7, 2.5])
>>> nm = iso.categorical_node_match('fill', 'red')
>>> nx.is_isomorphic(G1, G2, edge_match=em, node_match=nm)
True