Reputation: 37
Two graphs G1 and G2 are isomorphic (is_isomorphic(G1, G2) => True) but have different attributes on each node. How can I obtain a mapping or dictionary between the value of attribute X from node Y on graph G1 and the value of attribute X from the "structurally-equivalent" node Y'.
Best, Eric
Upvotes: 2
Views: 818
Reputation: 25289
Use the advanced interface to the VF2 isomorphism algorithm. https://networkx.readthedocs.io/en/stable/reference/algorithms.isomorphism.vf2.html
It will give you the matching.
>>> from networkx.algorithms import isomorphism
>>> G1 = nx.path_graph(4)
>>> G2 = nx.path_graph(4)
>>> GM = isomorphism.GraphMatcher(G1,G2)
>>> GM.is_isomorphic()
True
GM.mapping stores the isomorphism mapping from G1 to G2.
>>> GM.mapping
{0: 0, 1: 1, 2: 2, 3: 3}
Upvotes: 2