I have two graphs as follows
import networkx as nx
G1, G2 = nx.DiGraph(), nx.DiGraph()
G1.add_edges_from([("s1", "s2"), ("s2", "s3"), ("s3", "s4")]) # G1: 1->2->3->4
G2.add_edges_from([("s1", "s2"), ("s2", "s3"), ("s3", "s7")]) # G2: 1->2->3->7
nx.is_isomorphic(G1, G2)
By definition, we know the above two graphs are isomorphic, so is_isomorphic
returns True.
However, I wish to check structure equality between two graphs, meaning nodes and edges are the same (but weights allow difference). Since G1
and G2
have different last node, I am looking for the is_isomorphic
function returning False.
Q: Is it possible using is_isomorphic
to identify the non-equality?
P.S.
I tried to use iso.categorical_node_match
or iso.numerical_node_match
or iso.numerical_edge_match
as plug-in parameter in is_isomorphic
:
But I am still not sure how to call these iso
function correctly in node_match or edge_match.