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:

some initial random graph

the final subgraph top ten shortest paths only


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -