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:
- g
Graph Directed acyclic graph.
- g
- Returns:
- b
Graph The branching, a directed forest.
- source
VertexPropertyMap Vertex property map of
bwith the vertex ofgthat corresponds to every vertex.
- b
See also
unfold_treeUnfolding of a graph into a forest
topological_sortTopological 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 ofg. 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]