unfold_tree#
- graph_tool.structure.unfold_tree(g, roots)[git][source]#
Unfold a graph into a forest by breadth-first search.
- Parameters:
- Returns:
- t
Graph The forest, with the directedness of
g.- orig
VertexPropertyMap The vertex of
gcorresponding to every vertex oft.
- t
See also
dag_to_branchingBranching of the paths of a directed acyclic graph
graph_tool.search.bfs_searchBreadth-first search
Notes
A breadth-first search is run from every root (not reached before); each edge is traversed once (along the out-edges, for directed graphs), and if it leads to a vertex already reached, a new copy of that vertex is created as its endpoint, so that every edge reachable from the roots appears once in the forest. The vertices of
gkeep their indices, and the copies come after them. The time is \(O(V + E)\).Examples
>>> g = gt.circular_graph(4) >>> t, orig = gt.unfold_tree(g, [0]) >>> print(t.num_vertices(), t.num_edges(), orig.a) 5 4 [0 1 2 3 2]