library(igraph)
## create some DAG.
g <- graph_from_literal(a -+ b:c:d:e, b -+ d, c -+ d:e, d -+ e)
g <- set_edge_attr(g, name="weight", value=-1) # longest path = shortest negative.
dist <- (-distances(g, v=(V(g)), mode="out")) # matrix of VxV distances of shortest paths.
layers <- apply(dist, 1, max) # maximum distance from bottom to top (max per row).
layers <- max(layers) - layers # minimal distance from top to bottom.
plot(g, layout=layout_with_sugiyama(g, layers=layers)) # show the graph by level.
d = 1 # certain depth d.
layers[which(layers==d)]
## b c
## 1 1
1条答案
按热度按时间kcugc4gi1#
假设:
字符串
更详细的答案,请参阅:igraph:树图,其中终端(而不是根)节点在同一级别?