用 R 识别随机图中的切口和桥梁
Posted
技术标签:
【中文标题】用 R 识别随机图中的切口和桥梁【英文标题】:Identify cuts and bridges in random graphs with R 【发布时间】:2015-05-10 03:30:37 【问题描述】:我有这个生成随机图的代码, 如何识别图中的桥梁和切口
library(igraph)
G <- graph( c(1,2,1,3,1,4,3,4,3,5,5,6,6,7,7,8,8,9,3,8,5,8,10,1,10,2,11,2,12,1,13,4,13,7,14,2,15,6,16,7,17,8,19,13,18,4,19,7), directed = FALSE )
# Assign attributes to the graph
G$name <- "A colorful example graph"
# Assign attributes to the graph's vertices
V(G)$name <- toupper(letters[1:20])
V(G)$color <- sample(rainbow(20),20,replace=FALSE)
# Assign attributes to the edges
E(G)$weight <- runif(length(E(G)),.3,2)
# Plot the graph -- details in the "Drawing graphs" section of the igraph manual
plot(G, layout = layout.fruchterman.reingold,
main = G$name,
vertex.label = V(G)$name,
vertex.size = 15,
vertex.color= V(G)$color,
vertex.frame.color= "white",
vertex.label.color = "white",
vertex.label.family = "sans",
edge.width=E(G)$weight,
edge.color="black")
【问题讨论】:
你所说的“桥梁”和“削减”是什么意思?您是否只想突出显示图表中的某些边缘? cut 是图的一条边,其删除会增加其连通分量的数量。等效地,只有当它不包含在任何循环中时,边缘才是桥梁,我想知道如何突出显示边缘 你所说的削减是什么意思? @cmbarbu cut 是图的一条边,其删除会增加其连通分量的数量。 如果您只知道如何突出显示桥梁,它将同样有帮助 【参考方案1】:好的,鉴于我已经能够使用您定义的术语来辨别,这可能是一种可以帮助您实现目标的方法。希望它在一些小方面有所帮助,尽管它肯定不是最有效的桥梁查找算法(迭代删除边和图分解的计数),但它对小图的工作相对较好。如果您需要更高效的东西,您可能需要手动编写 Trajan 或其他高效算法:
library(igraph)
G <- graph( c(1,2,1,3,1,4,3,4,3,5,5,6,6,7,7,8,8,9,3,8,5,8,10,1,10,2,11,2,12,1,13,4,13,7,14,2,15,6,16,7,17,8,19,13,18,4,19,7), directed = FALSE )
# Assign attributes to the graph
G$name <- "A graph with articulated.nodes and bridges highlighted"
# Assign attributes to the graph's vertices
V(G)$name <- toupper(letters[1:20])
V(G)$color <- sample(rainbow(20),20,replace=FALSE)
# Assign attributes to the edges
E(G)$weight <- runif(length(E(G)),.3,2)
## Set normal vertices to black:
V(G)$color <- "black"
## Set articulation points to red:
V(G)$color[ articulation.points(G) ] <- "red"
## Set normal edges to black:
E(G)$color <- "black"
## Set bridge edges to red:
num_comp <- length( decompose.graph(G) )
for (i in 1:length(E(G)))
G_sub <- delete.edges(G, i)
if ( length( decompose.graph(G_sub) ) > num_comp ) E(G)$color[i] <- "red"
plot(G, layout = layout.fruchterman.reingold,
main = G$name,
vertex.label = V(G)$name,
vertex.size = 15,
vertex.color= V(G)$color,
vertex.frame.color= "white",
vertex.label.color = "white",
vertex.label.family = "sans",
edge.width=E(G)$weight,
edge.color=E(G)$color)
【讨论】:
【参考方案2】:似乎没有实现。如here 所述,您可以从查找生成树的函数开始实现Trajan's algorithm:
minimum.spanning.tree
至于剪辑,相同的来源指向与您不同的定义,但您可能想检查一下。
【讨论】:
以上是关于用 R 识别随机图中的切口和桥梁的主要内容,如果未能解决你的问题,请参考以下文章