【发布时间】:2017-06-29 02:58:59
【问题描述】:
我有一个从几个树状结构的图像中提取的图形。该图对于每个关节点都有一个顶点,即使该点不是分支或端点(即节点顺序为 2)。我想删除这些 2 阶顶点,但保持连通性,以便通过这些中间体连接的分支点或末端顶点现在由一条边连接。我可以通过删除顶点并一次连接一个边来对小图执行此操作,但是在处理 10,000 多个边时这会很慢。
这是一个示例起始图。我想删除(例如)顶点 8 和 6,同时插入连接 9 和 4 的边。同样,我想删除顶点 5,同时插入 7 和 4 之间的边。
edge_matrix = cbind(
c(1,2,3,4,4,5,6,8,9,9,10,11),
c(2,3,4,5,6,7,8,9,10,11,12,13))
example_graph = graph.data.frame(edge_matrix, directed=F)
structure(list(13, FALSE, c(1, 2, 3, 4, 5, 10, 6, 7, 8, 9, 11,
12), c(0, 1, 2, 3, 3, 4, 5, 6, 7, 7, 8, 9), c(0, 1, 2, 3, 4,
6, 7, 8, 9, 5, 10, 11), c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
), c(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), c(0, 1, 2,
3, 5, 6, 7, 8, 10, 11, 12, 12, 12, 12), list(c(1, 0, 1), structure(list(), .Names = character(0)),
structure(list(name = c("1", "2", "3", "4", "5", "6", "8",
"9", "10", "11", "7", "12", "13")), .Names = "name"), list()),
<environment>), class = "igraph")
【问题讨论】: