Networkx:子图同构不能正常工作

时间:2018-07-17 01:31:17

标签: python graph networkx

我是图形理论和networkx的初学者。我有一个问题,为什么networkx有时对子图同构测试返回True,而对于子图同构测试有时返回False。

我有这个障碍集,我试图将一组图与以下内容进行比较:

os = []
subgraph1 = nx.Graph()
subgraph1.add_edges_from([(1, 1), (2, 2), (3, 3)])
os.append(subgraph1)
subgraph2 = nx.Graph()
subgraph2.add_edges_from([(1, 1), (2, 3), (4, 5)])
os.append(subgraph2)
subgraph3 = nx.Graph()
subgraph3.add_edges_from([(1, 1), (2, 2), (3, 4)])
os.append(subgraph3)
subgraph4 = nx.Graph()
subgraph4.add_edges_from([(1, 2), (3, 4), (5, 6)])
os.append(subgraph4)
subgraph5 = nx.Graph()
subgraph5.add_edges_from([(1, 1), (2, 3), (3, 4), (2, 4)])
os.append(subgraph5)
subgraph6 = nx.Graph()
subgraph6.add_edges_from([(1, 2), (3, 4), (4, 5), (5, 3)])
os.append(subgraph6)
subgraph7 = nx.Graph()
subgraph7.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5), (5, 1)])
os.append(subgraph7)
subgraph8 = nx.Graph()
subgraph8.add_edges_from([(1, 2), (1, 3), (1, 4), (4, 2), (3, 2), (3, 4)])
os.append(subgraph8)

当我运行此算法时,它说test中的特定示例不是同构的,应该同时击中subgraph2subgraph4

test = nx.Graph()
test.add_edge(4,3)
test.add_edge(4,5)
test.add_edge(4,9)
test.add_edge(3,7)
test.add_edge(3,0)
test.add_edge(7,9)
test.add_edge(0,0)

which = 1
for x in OS_V2:
    GM = isomorphism.GraphMatcher(test, x)
    # returns true if a subgraph of G is
    # isomorphic to x
    if GM.subgraph_is_isomorphic():
        print(which, GM.mapping)
    else:
        print("no match")
    which += 1

我不明白为什么要这么做。而且,它可以说得很好:

1 1
1 2
2 3
2 4
3 6
6 5
7 7
2 {7: 1, 2: 2, 4: 3, 6: 4, 5: 5}

5 3
3 6
4 7
4 8
7 7
8 9
2 {7: 1, 5: 2, 3: 3, 8: 4, 9: 5}

另一个例子,当它是(4,5),(4,3),(4,2),(5,1),(2,2)时,它不是同构的。 (也有subgraph2

在有关子图同构的文档中,它提到了节点诱导与边缘诱导。但是我找不到有关边缘诱导图的文档。另外,我还尝试使用itertools.combinations(...)遍历所有子图,并尝试根据连通性检查同构,但是这也不起作用。我在掩饰/没有看到明显错的地方是什么?

0 个答案:

没有答案