Reputation: 2293
How can I find the node that is furthest to another node in a directional network?
For example in the following code:
g <- graph( c('A',1,'A',2,'2','B','B',4,'B',5,5,'C','C',7,'C',8,'D',7,8,'D'))
How can I get the furthest node from B, being "7" (B>5>8>D>7) or C, being also "7" (C>8>D>7)
Thanks
Upvotes: 2
Views: 323
Reputation: 630
You could use a simple matrix multiplication. For example, the following code shows the paths from C (the 7th node) of length 1,2,3,4. By length 4 there are none.
ga <- get.adjacency(g, sparse = F)
for (i in 1:4) {
print(i)
print(matrix.power(ga,i)[7,])
}
Though it may not be practical if your graph is very large.
Upvotes: 1