unfold_tree

Contents

unfold_tree#

graph_tool.structure.unfold_tree(g, roots)[git][source]#

Unfold a graph into a forest by breadth-first search.

Parameters:
gGraph

Graph to be used.

rootsiterable of int or Vertex

Roots of the searches.

Returns:
tGraph

The forest, with the directedness of g.

origVertexPropertyMap

The vertex of g corresponding to every vertex of t.

See also

dag_to_branching

Branching of the paths of a directed acyclic graph

graph_tool.search.bfs_search

Breadth-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 g keep 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]