r - Given a vertex v1, how can I get the vertex v2 whose edge (v1,v2) has the maximum weight? -


given vertex v1, how can vertex v2 edge (v1,v2) has maximum weight?

my approach problem one:

library(igraph) maxedge = max(e(g)[from(id)]$weight which(e(g)$weight==maxedge)) 

but don't know how vertex id. ideas?

minimal example data

library(igraph)  g1 <- graph.full(5) v(g1)$name <- 1:5     g2 <- graph.full(5) v(g2)$name <- 6:10 g3 <- graph.ring(5) v(g3)$name <- 11:15 g <- g1 + g2 + g3 + edge('1', '6') + edge('1', '11') v(g)$name <- letters[1:vcount(g)] # random data set.seed(ecount(g)) e(g)$weight <- runif(ecount(g))  maxedge = max(e(g)[from(1)]$weight) idedge = which(e(g)$weight==maxedge) 

my approach edge id (idedge). however, want vertex id!

for instance:

v(g) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o"  e(g)[from("a")] -> $weight [1]  b -- -> 0.97175023 [2]  c -- -> 0.08375751 [3]  d -- -> 0.87386992 [4]  e -- -> 0.32923136 [26] f -- -> 0.10740653 [27] k -- -> 0.56277556 

considering example above, need function must return "b" or "2".

once have id of edge has maximal weight, can use get.edge(graph, edge.id) vertex ids of endpoints. so, full solution like:

edge.seq <- e(g)[from(source)] max.weight <- max(edge.seq$weight) get.edges(graph, edge.seq[edge.seq$weight == max.weight]) 

i'm not expert in r maybe there's simpler way.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -