Graphic Equal Graphics in NetworkX

What is the most efficient way to check if two NetworkX graphs are identical (i.e. the same set of nodes, the same node attributes on each node, the same set of edges and the same edge attributes on each edge)? Suppose we know that two graphs are of the same class.

Thanks for your kind reply.

+6
source share
1 answer

NetworkX has is_isomorphic () function

https://networkx.imtqy.com/documentation/stable/reference/algorithms/generated/networkx.algorithms.isomorphism.is_isomorphic.html#networkx.algorithms.isomorphism.is_isomorphic

Here is an example from this page:

>>> import networkx.algorithms.isomorphism as iso >>> 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 
+11
source

Source: https://habr.com/ru/post/1489292/


All Articles