我有一个小型的完全连接网络:
m<-induced.subgraph(g, V(g)[village=="sar"])
这是一个摘要,6个节点和30个链接,一个完全连接的定向网络:
IGRAPH DNWB 6 30 --
attr: id (v/n), name (v/c), village (v/c), religion (v/c), adoption.lag
(v/n), type (v/c), shape (v/c), size (v/n), color (v/c), dist (v/n),
dist.sar (v/n), weight (e/n)
当我跑步时,我得到了一个令人惊讶的结果:
>shortest.paths(m)
A B C D E F
A 0 3 3 3 3 3
B 3 0 3 3 3 3
C 3 3 0 3 3 3
D 3 3 3 0 3 3
E 3 3 3 3 0 3
F 3 3 3 3 3 0
指向网络,有6个节点和30个链接,因此每个节点都链接到其他所有人:不应该将最短路径值设为1?感谢您的评论。
答案 0 :(得分:0)
原因是链接是加权的,无论shortest.paths(g)默认设置为weights = NULL,我都有:
> E(g)$weight<-1
> shortest.paths(g, V(g)[village=="rudakali"], to=V(g)[village=="rudakali"],weights=NULL)
A B C D E F
A 0 1 1 1 1 1
B 1 0 1 1 1 1
C 1 1 0 1 1 1
D 1 1 1 0 1 1
E 1 1 1 1 0 1
F 1 1 1 1 1 0
> E(g)$weight<-10
> shortest.paths(g, V(g)[village=="rudakali"], to=V(g)[village=="rudakali"],weights=NULL)
A B C D E F
A 0 10 10 10 10 10
B 10 0 10 10 10 10
C 10 10 0 10 10 10
D 10 10 10 0 10 10
E 10 10 10 10 0 10
F 10 10 10 10 10 0
Gabor评论后编辑:要摆脱边缘权重,在我的情况下,正确的代码将是:
shortest.paths(g, V(g)[village=="rudakali"], to=V(g)[village=="rudakali"],weights=NA)