1

我想知道在 python 库 graph_tool 中计算无向图的传递闭包的最佳方法是什么。

到目前为止,我的解决方案是从原始图创建一个有向图并在其上使用 transitive_closure 方法:

    import graph_tool as gt, graph_tool.topology as gtt

    symm = gt.Graph(g)
    symm.set_directed(True)
    symm.add_edge_list([(b, a) for (a, b) in g.edges()])

    tc = gtt.transitive_closure(symm)
    tc.set_directed(False)

当然必须有更好,更有效的方法来做到这一点?

4

0 回答 0