Find all vertices that can reach a set of other vertices [igraph package in R]

513 views Asked by At

How can I find, in a directed graph, all vertices that can reach a set of other vertices with the igraph package in R?

I'm able to find them for a single vertex using (e.g. for all vertices that can reach vertex 4):

subcomponent(g, 4, mode="in")

However, how can I replace "4" with a set of many vertices with a similar result? If I give many vertices to the default function, it seems to return only vertices that can reach all the given vertices. I would like to find all vertices that can reach any of the given vertices...

Thanks

1

There are 1 answers

1
Rorschach On BEST ANSWER

You could make the function subcomponent take a vector of arguments for the parameter v:

g <- erdos.renyi.game(100, 1/200)
mySet <- c(1,2,3)
modified <- Vectorize(igraph:::subcomponent, vectorize.args = "v")
modified(g, mySet, "in")

Which could also be done using an apply function or a loop

sapply(mySet, subcomponent, graph=g, mode="in")