networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
is_isomorphic(G1, G2, node_match=None, edge_match=None)

Notes

Uses the vf2 algorithm .

Parameters

G1, G2: graphs :

The two graphs G1 and G2 must be the same type.

node_match : callable

A function that returns True if node n1 in G1 and n2 in G2 should be considered equal during the isomorphism test. If node_match is not specified then node attributes are not considered.

The function will be called like

node_match(G1.nodes[n1], G2.nodes[n2]).

That is, the function will receive the node attribute dictionaries for n1 and n2 as inputs.

edge_match : callable

A function that returns True if the edge attribute dictionary for the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be considered equal during the isomorphism test. If edge_match is not specified then edge attributes are not considered.

The function will be called like

edge_match(G1[u1][v1], G2[u2][v2]).

That is, the function will receive the edge attribute dictionaries of the edges under consideration.

Returns True if the graphs G1 and G2 are isomorphic and False otherwise.

See Also

categorical_edge_match
categorical_multiedge_match
categorical_node_match
numerical_edge_match
numerical_multiedge_match
numerical_node_match

Examples

>>> import networkx.algorithms.isomorphism as iso

For digraphs G1 and G2, using 'weight' edge attribute (default: 1)

>>> G1 = nx.DiGraph()
... G2 = nx.DiGraph()
... nx.add_path(G1, [1, 2, 3, 4], weight=1)
... nx.add_path(G2, [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")
... nx.add_path(G1, [1, 2, 3, 4], weight=3, linewidth=2.5)
... nx.add_path(G2, [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)
1
>>> G2.add_edge(10, 20)
1
>>> 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
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.isomorphism.isomorph.is_isomorphic networkx.algorithms.minors.contraction.contracted_nodes networkx.algorithms.minors.contraction.contracted_edge

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/isomorphism/isomorph.py#127
type: <class 'function'>
Commit: