1

I was wondering what the best way to compute the transitive closure of an undirected graph in the python library graph_tool is.

My solution so far is to create a directed graph from the original one and use the transitive_closure method on that:

    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)

Surely there must be a better and more efficient way to do this?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
  • What do you mean by the transitive closure of a undirected graph? If there are no directions a closure would be replacing every connected component by a complete graph in my view. – blacktemplar May 17 '17 at 11:45
  • Well, yes. I want to compute the graph that has an (undirected) edge (a,b) iff a and b are in the same connected component of the original graph (or in other words, if there is a path between a and b). – J. Gambolputty May 17 '17 at 11:52

0 Answers0