unfold.tree              package:igraph              R Documentation

_C_o_n_v_e_r_t _a _g_e_n_e_r_a_l _g_r_a_p_h _i_n_t_o _a _f_o_r_e_s_t

_D_e_s_c_r_i_p_t_i_o_n:

     Perform a breadth-first search on a graph and convert it into a
     tree or forest by replicating vertices that were found more than
     once.

_U_s_a_g_e:

     unfold.tree(graph, mode = c("all", "out", "in", "total"), roots) 

_A_r_g_u_m_e_n_t_s:

   graph: The input graph, it can be either directed or undirected.

    mode: Character string, defined the types of the paths used for the
          breadth-first search. "out" follows the outgoing, "in" the
          incoming edges, "all" and "total" both of them. This argument
          is ignored for undirected graphs.

   roots: A vector giving the vertices from which the breadth-first
          search is performed. Typically it contains one vertex per
          component.

_D_e_t_a_i_l_s:

     A forest is a graph, whose components are trees.

     The 'roots' vector can be calculated by simply doing a topological
     sort in all components of the graph, see the examples below.

_V_a_l_u_e:

     A list with two components: 

    tree: The result, an 'igraph' object, a tree or a forest.

vertex_index: A numeric vector, it gives a mapping from the vertices of
          the new graph to the vertices of the old graph.

_A_u_t_h_o_r(_s):

     Gabor Csardi csardi.gabor@gmail.com

_E_x_a_m_p_l_e_s:

     g <- graph.tree(10) 
     V(g)$id <- seq_len(vcount(g))-1
     roots <- sapply(decompose.graph(g), function(x) {
                 V(x)$id[ topological.sort(x)[1]+1 ] })
     tree <- unfold.tree(g, roots=roots)

