r - strange result with shortest.path in igraph -
i have small connected network obtained with:
m<-induced.subgraph(g, v(g)[village=="sar"])
here's summary, 6 nodes , 30 links, connected directed network:
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)
when run this, got surprising result:
>shortest.paths(m) b c d e f 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
the network directed, 6 nodes , 30 links every node linked else: shouldn't shortest paths values 1? comments.
the reason links weighted, , no matter if shortest.paths(g) set default weights=null, have:
> e(g)$weight<-1 > shortest.paths(g, v(g)[village=="rudakali"], to=v(g)[village=="rudakali"],weights=null) b c d e f 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) b c d e f 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
edit after gabor comment: rid of edge weights, correct code be, in case:
shortest.paths(g, v(g)[village=="rudakali"], to=v(g)[village=="rudakali"],weights=na)
Comments
Post a Comment