dag_to_branching

dag_to_branching#

graph_tool.structure.dag_to_branching(g)[git][source]#

Return the branching of the paths from the sources of a directed acyclic graph.

Parameters:
gGraph

Directed acyclic graph.

Returns:
bGraph

The branching, a directed forest.

sourceVertexPropertyMap

Vertex property map of b with the vertex of g that corresponds to every vertex.

See also

unfold_tree

Unfolding of a graph into a forest

topological_sort

Topological ordering of a directed acyclic graph

Notes

The branching has a vertex for every distinct path (as a sequence of vertices, so that parallel edges are merged) that starts at a source of g (a vertex without in-edges), which corresponds to the last vertex of the path, and the vertex of every path is the parent of those of its extensions by one vertex. Hence, the root-to-leaf paths of the branching correspond one-to-one to the root-to-leaf paths of g. The vertices are numbered in depth-first order, from the sources in increasing order and with the out-neighbors in increasing order. The number of paths, and hence the time, can be exponential in the size of the graph.

Examples

>>> g = gt.Graph([(0, 1), (0, 2), (1, 3), (2, 3)])
>>> b, source = gt.dag_to_branching(g)
>>> print(b.get_edges().tolist(), source.a)
[[0, 1], [0, 3], [1, 2], [3, 4]] [0 1 3 2 3]