최단경로와 도달 가능성 :: R을 이용한 사회 연결망 분석 - mindscale
Skip to content

최단경로와 도달 가능성

reachability (도달가능성)

함수 정의

reachability <- function(g, m) {
  reach_mat = matrix(nrow = vcount(g), 
                    ncol = vcount(g))
  for (i in 1:vcount(g)) {
    reach_mat[i,] = 0
    this_node_reach <- subcomponent(g, i, mode = m)

    for (j in 1:(length(this_node_reach))) {
      alter = this_node_reach[j]
      reach_mat[i, alter] = 1
    }
  }
  return(reach_mat)
}

계산

reach_full_in <- reachability(krack_full, 'in')
reach_full_out <- reachability(krack_full, 'out')

shortest path (최단거리)

sp_full_in <- shortest.paths(krack_full, mode='in')
sp_full_out <- shortest.paths(krack_full, mode='out')

diameter (직경)

max(sp_full_in)