2017-04-15 97 views
0

兩個圖G1和G2是同構的(is_isomorphic(G1,G2)=> True),但在每個節點上具有不同的屬性。如何獲得圖G1上來自節點Y的屬性X的值與來自「結構等價」節點Y'的屬性X的值之間的映射或字典。生成兩個同構圖之間的映射

最佳, 埃裏克

+0

你可以使用'get_node_attributes'功能,並保持結果的元組。你有什麼嘗試?什麼不起作用? – chapelo

+0

感謝您的回覆。我不知道如何識別相應的節點對。如果我不知道彼此對應的節點,我不能使用get_node_attributes。 –

回答

0

使用高級界面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} 
+0

完美!這是我正在尋找的。謝謝回覆。 –

相關問題