Detect whether a food web is composed of several disconnected sub-networks
Detect whether a food web is composed of several disconnected sub-networks
Run a deep search first algorithm (DFS)
is_connected(fw)
Arguments
fw: binary adjacency matrix of the food web.
Returns
Boolean: TRUE if the food web is connected, FALSE if several disconnected sub-networks are detected.
Examples
library(ATNr)set.seed(123)# number of species, nutrients, and body massesn_species <-20n_basal <-5n_nutrients <-3masses <- sort(10^runif(n_species,2,6))#body mass of species# create food web matrixL <- create_Lmatrix(masses, n_basal)L[,1:n_basal]<-0fw <- L
fw[fw >0]<-1connected <- is_connected(fw)