首页 > 解决方案 > 断开连接图的巨型组件本身断开连接的警告消息

问题描述

我在这里有点困惑,我使用以下代码提取了断开连接图的巨大组件。

function(graph) {
  cl <- clusters(graph)
  induced.subgraph(graph, which(cl$membership == which.max(cl$csize)))
}

但是在 RStudio 中运行这样的代码会给我频繁的错误,例如

is_connected(ngo.giant)
[1] TRUE
centr_clo(ngo.giant)$centralization
[1] 0.003214897
Warning message:
In centr_clo(ngo.giant) :
  At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs
temp<-centr_eigen(ngo.giant,directed=T)
Warning message:
In centr_eigen(ngo.giant, directed = T) :
  At centrality.c:344 :graph is directed and acyclic; eigenvector centralities will be zeros

发生这种情况有原因吗?抱歉,如果此代码太模糊

标签: rcompiler-errors

解决方案


我刚刚收到该警告,我注意到这是由于我的图表是定向的,因此某些路径只能沿一个方向行走,而某些节点与另一个节点“断开”。

test <- data.frame(source=c('a', 'a'), target=c('b', 'c'), stringsAsFactors=FALSE)
g <- igraph::graph_from_data_frame(test, directed=TRUE)
igraph::closeness(g)

        a         b         c 
0.5000000 0.1666667 0.1666667 
Warning message:
In igraph::closeness(g) :
  At centrality.c:2784 :closeness centrality is not well-defined for disconnected graphs

同样,如果您使用 in 中的参数mehtod='all'closeness您的图将被视为无向图。


推荐阅读