|
From: | Belavenutti Martins da Silva, Pedro |
Subject: | Re: [igraph] (no subject) |
Date: | Tue, 10 Mar 2020 20:26:55 +0000 |
I am working from R. I am trying to implement this call back function in R but it seems to do not work.
Here in an example:
library(igraph)
d<-matrix(c(1, 0, 0, 0, 0.9,
0, 1, 0.6, 0.4, 0.5,
0, 0.6, 1, 0, 0.8,
0, 0.4, 0, 1, 0.5,
0.9, 0.5, 0.8, 0.5, 1), byrow=T, nrow=5)
g<-graph.adjacency(d, weighted=T, mode="lower",diag=FALSE, add.colnames=NA)
plot(g)
threshold-value <- 2 #Whow to use this information in the process?
dfs <- dfs(g, root = 1 ) #ex: I do not know any method to set up a threshold-value n in here to stop the function.
visited <- dfs$order
Sum_Weights <- sum(E(g)$weight[visited])# here the Sum_Weights should be the threshold-value
##################
## Terminate after the threshold-value , using a callback
threshold-value <- 2
data1 <- E(g)$weight
f.out <- function(graph, data1, extra) {
edge <- data['vid']
sum <- unlist(append(sum, data1[edge]))
sum > threshold-value
}
dfs <- dfs(g, root = 1,out.callback=f.out) # it does not work and aborts the current R section.
From: igraph-help [igraph-help-bounces+pedro.belavenutti=address@hidden] on behalf of Tamas Nepusz [address@hidden]
Sent: Tuesday, March 10, 2020 9:29 AM To: Help for igraph users Subject: Re: [igraph] (no subject)
Are you working from C? If so, you can use the "in_callback" and "out_callback" arguments of igraph_dfs to call arbitrary functions when the DFS starts visiting a node or when the DFS is done with a node and its subgraph. You can also return a non-zero
value from the callback functions to request igraph to terminate the search.
Documentation here:
T.
|
[Prev in Thread] | Current Thread | [Next in Thread] |