무작위 방향 가중치 그래프 gg
가 있으며 다음 구조가 있습니다.
gg <-
structure(list(10, TRUE, c(0, 0, 1, 2, 2, 5, 5, 6, 6, 6, 6, 9,
9, 9, 9, 9), c(6, 9, 3, 0, 5, 3, 7, 1, 3, 5, 8, 2, 4, 6, 7, 8
), c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), c(3,
7, 11, 2, 5, 8, 12, 4, 9, 0, 13, 6, 14, 10, 15, 1), c(0, 2, 3,
5, 5, 5, 7, 11, 11, 11, 16), c(0, 1, 2, 3, 6, 7, 9, 11, 13, 15,
16), list(c(1, 0, 1), structure(list(), .Names = character(0)),
structure(list(name = c("C", "D", "I", "J", "K", "N", "O",
"Q", "S", "T"), color = c("yellow", "red", "red", "red",
"red", "red", "green", "red", "red", "green")), .Names = c("name",
"color")), structure(list(weight = c(0.5, 0.5, 1, 0.333333333333333,
0.333333333333333, 0.333333333333333, 0.333333333333333,
0.25, 0.25, 0.25, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2)), .Names = "weight")),
<environment>), class = "igraph")
루트 (노란색 노드)에서 잎 (빨간색 노드)까지의 모든 걷기를 찾아야합니다. (a) 가장자리 방향과 (b) 거리로 정의되는 잎은 뿌리에서 잎까지 두 개의 가장자리 여야합니다.
제 경우에는 뿌리는 C
이고 잎은 D, J, N, S, I, K, Q
. 나는 (a) 조건만을 정의하려고했습니다.
root <- "C"
leaves = which(degree(gg, v = V(gg), mode = "out")==0, useNames = T)
leaves
# J K Q S
# 4 5 8 9
plot(gg, layout = layout.reingold.tilford(gg, root=root),
edge.arrow.size=0.2, edge.curved=T,
edge.label = round(E(gg)$weight,2))
질문 . (b) 조건을 정의하고 잎 세트 D, N, I, K
노드에 추가하는 방법은 무엇입니까?
여기에 한 가지 방법이 있습니다. shortest_paths
루트 노드에서 정확히 두 가장자리 인 모든 정점을 가져 오는 데 사용 합니다.
two.edges.from.root = unlist(sapply(shortest_paths(gg,
from = as.numeric(V(gg)["C"]),
mode = "out")$vpath,
function(x) { if(length(x) == 3) { x[3] } }))
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다