I'm trying to write a script in R to identify the elements (edges and vertices) belonging to the cycles of the graph.
I'm using a callback function within the graph.dfs (igraph R package). I don't want to modify the graph, just want to build a new a list of visited vertices (and update it) each time the dfs algorithm visits a vertex. The problem is that R program closes if I run the following code. It might be doing something wrong - any suggestion/ help?
#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())
I found the following thread (R / igraph : any call to get/set vertex attribute within a depth-first-search callback causes a segfault) but it looks its answer is focused in changing properties of the graph elements within the callback function, which is somewhat different than what I'm trying to do.