2015-04-17 33 views
0

爲什麼networkx認爲下面的兩個圖不是同構的?networkx子圖同構的斷開圖

from networkx import nx 
g1 = nx.empty_graph(2) #just two unconnected nodes 
g2 = nx.complete_graph(3) 
GM = nx.algorithms.isomorphism.GraphMatcher(g2,g1) 
print(str(GM.subgraph_is_isomorphic())) 

回答

0

被匹配的子圖是一個節點引起的子圖,它也包括匹配邊緣。

所以

from networkx import nx 
g1 = nx.empty_graph(2) #just two unconnected nodes                      
g2 = nx.complete_graph(3) 
GM = nx.algorithms.isomorphism.GraphMatcher(g2,g1) 
print(GM.subgraph_is_isomorphic()) # False 
g3 = g2.subgraph(g1) 
GM = nx.algorithms.isomorphism.GraphMatcher(g2,g3) 
print(GM.subgraph_is_isomorphic()) # True, includes edge (0,1) 
+0

並沒有真正解決我的問題。我問這個問題的原因:例子:我有一個由兩個不連通的K4組成的圖G1,我想檢查另一個圖是否包含這個子圖,即包含兩個單獨的(頂點不相交的)K4。這可能與networkx? – user116732

+0

是否可以完全刪除第一個匹配的子圖(包括節點),然後再與剩餘的圖匹配? – Aric