我正在尝试在 R 中编写一个脚本来识别属于图循环的元素(边和顶点)。
我在 graph.dfs(igraph R 包)中使用回调函数。我不想修改图形,只想在每次 dfs 算法访问一个顶点时构建一个新的访问顶点列表(并更新它)。问题是如果我运行以下代码,R 程序将关闭。它可能做错了什么 - 有什么建议/帮助吗?
#create a simple graph with 4 nodes and 1 cycle
gIncidenceMatrix <- matrix (c(0,1,1,1,1,0,0,0,1,0,0,1,1,0,1,0), nrow=4, ncol=4, byrow=T)
g <- graph.adjacency(gIncidenceMatrix, mode = "undirected")
f.cycleDetection <- function(g, data, extra) {
vId <- data[1]
nVertices <- neighbors(g, vId+1, mode = 1) #vId + 1 is to avoid having index 0 (any suggestion?)
FALSE
}
graph.dfs(g, root=1, neimode = "all", unreachable = TRUE, order = FALSE, order.out = FALSE, father = …Run Code Online (Sandbox Code Playgroud)