networkx子图是断开连接图的同构

时间:2015-04-17 16:40:00

标签: graph-theory 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()))

1 个答案:

答案 0 :(得分:1)

匹配的子图是一个节点引起的子图,它还包括匹配边。

所以

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)
相关问题