All paths in directed tree graph from root to leaves in igraph R

前端 未结 1 1525
余生分开走
余生分开走 2021-01-12 17:43

Given is a tree:

library(igraph)

# setup graph
g= graph.formula(A -+ B,
                 A -+ C,
                 B -+ C,
                 B -+ D,
                  


        
相关标签:
1条回答
  • 2021-01-12 18:45

    Based on Gabor's comment:

    all_simple_paths(g, from = root, to = leaves)
    

    yields:

    [[1]]
    + 3/5 vertices, named:
    [1] A B C
    
    [[2]]
    + 3/5 vertices, named:
    [1] A B D
    
    [[3]]
    + 3/5 vertices, named:
    [1] A B E
    
    [[4]]
    + 2/5 vertices, named:
    [1] A C
    
    0 讨论(0)
提交回复
热议问题