R / igraph :在深度优先搜索回调中获取顶点邻居列表会导致 R 关闭。有什么建议吗?

jpl*_*jpl 4 r callback igraph depth-first-search

我正在尝试在 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 = FALSE, dist = FALSE, in.callback = f.cycleDetection, out.callback = NULL, extra = NULL, rho = parent.frame())
Run Code Online (Sandbox Code Playgroud)

我发现了以下线程(R / igraph :在深度优先搜索回调中对 get/set vertex 属性的任何调用都会导致 segfault),但看起来它的答案集中在回调函数中更改图形元素的属性上,其中与我正在尝试做的有些不同。

Gab*_*rdi 5

实际上,它比所提到的问题中的更糟糕。似乎您甚至无法从回调中调用 igraph 函数。解决方法是在DFS之前查询所有邻居,使用get.adjlist然后在DFS中使用。

我为此创建了一个错误报告:https : //github.com/igraph/igraph/issues/571