【发布时间】:2019-10-30 09:52:52
【问题描述】:
我有一个大图,我需要通过选择包含某个属性的边的顶点来过滤并创建一个子图。边有许多属性 atti={att1, att2, ..., attN} 我想根据选定的属性列表选择边
> require(igraph)
> graph <- make_ring(9) #this is my original graph
> V(graph)$name <- c("A", "B", "C", "D", "E", "F", "G", "H", "I") #name of vertices
> E(graph)$att1 <- c(1,0,0,0,1,0,0,1,0)
> E(graph)$att2 <- c(0,3,1,0,0,1,0,0,1)
> E(graph)$att3 <- c(0,0,0,1,4,0,0,0,0)
> E(graph)$att4 <- c(1,0,1,0,2,1,0,0,0)
> # this is where I have issue. i don't know how to select vertices based on a dynamically selecting edges
> selected_atts <- c("att1", "att3")
> selected_vertices <- V(graph)[inc(E(graph)[which(selected_atts> 0)])] ## select all vertices that are linked by edges with att1 > 0 or att3 > 0
> subgraph_list <- make_ego_graph(graph, order=1, selected_vertices)
在这种情况下,应选择顶点 A,B,E,F,H,I(边缘 att1 > 0)和顶点 D,E,F(边缘 att3 > 0)。
A--B att1 = 1 att3 = 0 --> select this edge, so select nodes A and B
B--C att1 = 0 att3 = 0
C--D att1 = 0 att3 = 0
D--E att1 = 0 att3 = 1 --> select this edge, so select nodes D and E
E--F att1 = 1 att3 = 4 --> select this edge, so select nodes E and F
F--G att1 = 0 att3 = 0
G--H att1 = 0 att3 = 0
H--I att1 = 1 att3 = 0 --> select this edge, so select nodes H and I
I--A att1 = 0 att3 = 0
选定的属性是动态的。它们会发生变化,并且可能很多,所以我不想对它们进行硬编码。
【问题讨论】: