为什么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 :(得分: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)