问题
I would like to use igraph to find edge sequences corresponding to branches from a tree. Ideally, I would like to retain the branches in a data frame.
Consider this example:
library(igraph)
g <-erdos.renyi.game(50, 3/50)
mg <- minimum.spanning.tree(g)
diam <- get.diameter(mg)
E(mg)$color = "black"
E(mg, path = diam)$color = "purple"
E(mg, path = diam)$width = 6
plot(mg)
Here the main path is diam
, the purple line. Mr. Flick already kindly answered how to find the edges which are incident on diam
but not within diam
:
EL <- difference( E(mg)[inc(diam)], E(mg, path = diam) )
E(mg)[EL]$color<-"blue"
E(mg)[EL]$width<-6
plot(mg)
One may call these the branch "stubs", i.e. the first edge of each branch. The question now is how do I find the entire edge sequence of each individual branch.
I have a feeling it is with iterators using nei
and inc
following Mr. Flick's intuition, but can't see a way so far.
Example of branches:
diameter path with branch stubs
In the image, the branches would be the (undirected) edge sequences
23-19-18
23-14
23-26
1-32-24-7
1-11-42-35-41
1-11-42-35-9-17
1-11-30-38
1-28
1-33-34
1-33-29
1-48-47
1-48-12
27-49-39
27-6-45
27-6-10
31-20
16-4
来源:https://stackoverflow.com/questions/33987043/finding-edge-sequences-and-nodes-of-branches-in-igraph