Using igraph/R to get the top 10 shortest path -
i'm using igraph package in r , i'm looking way subgraph max top 10 shortest path previous graph.
anyone have suggestions?
first create graph:
set.seed(1) require(igraph) g <- erdos.renyi.game(100,.2) then extract shortest paths , calculate length:
plist <- do.call(c, lapply(v(g), function(v) get.shortest.paths(g,v,v(g), output='epath')$epath)) now figure out paths top ten:
psize <- data.frame(i = 1:length(plist), plength = sapply(plist,length)) top10 <- head(psize[order(-psize$plength),],10) now figure out edges involves:
elist <- unlist(plist[top10$i]) and finally, subgraph contains these vertices:
finalg <- subgraph.edges(g, elist) the before , after plots:


Comments
Post a Comment