0

What I need to do is to add a new vertex to a graph and find two edges to add to it in order to get a (very) big betweenness for it. What I tried to do is to create 1 edge to a very central node and the iterate through all the other nodes and try to get the max betweenness for this new node. The problem is that R igraph is taking forever to complete (I don't know if it will ever finish).

Any thoughts?

This is my code:

    add.vertices(graph = g, nv = 1)
    newId <- max(V(g))
    add.edges(graph = g,c(newId,755))
    biggestBetNew <- 0
    bestNodeToAdd <- 0
    for(i in 1:max(V(g))){
      add.edges(graph = g,c(newId,i))
      newBet <- betweenness(graph = g, v = V(g)[newId], normalized = T)
      if(newBet > biggestBetNew){
        biggestBetNew <- newBet
        bestNodeToAdd <- i
      }
      delete.edges(graph = g, c(newId,i))
    }
TylerH
  • 20,799
  • 66
  • 75
  • 101
Javi
  • 889
  • 1
  • 16
  • 41
  • 1
    This isn't helpful without the graph. Post the output of `dput(g)` in your question. See [this post](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) for instruction on how to create a well-posed question. – jlhoward Dec 01 '14 at 20:35
  • 1
    Your code is wrong, you need to write `g <- add.edges(...)` to create a new graph and assign it to a variable. – Gabor Csardi Dec 01 '14 at 23:26
  • Yeah, that was the problem.. thanks! – Javi Dec 02 '14 at 10:32

0 Answers0