生成两个同构图之间的映射

Generate mapping between two isomorphic graphs

两个图 G1 和 G2 是同构的(is_isomorphic(G1, G2) => True)但在每个节点上具有不同的属性。如何获取图 G1 上节点 Y 的属性 X 值与 "structurally-equivalent" 节点 Y' 的属性 X 值之间的映射或字典。

最好的, 埃里克

使用 VF2 同构算法的高级接口。 https://networkx.readthedocs.io/en/stable/reference/algorithms.isomorphism.vf2.html

它会给你匹配的。

>>> 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}