Generate Food Webs
Food webs are at the core of this package, and thus can be generated in various ways depending on your needs. In the following sections, we will go over the different methods of network generation. But, first things first, let us see what is inside a Foodweb
.
A Foodweb
object contains the trophic adjacency matrix A
filled with 0s and 1s indicating respectively the absence and presence of trophic interactions. Rows are consumers and columns resources, thus A[i,j] = 1
reads "species i
eats species j
"
From an Adjacency Matrix
The most straightforward way to generate a Foodweb
is to define your own adjacency matrix (A
) by hand and give it to the Foodweb
method that will return the corresponding Foodweb
object.
A = [0 0 0; 1 0 0; 0 1 0] # 1 <- 2 <- 3.
foodweb = Foodweb(A)
blueprint for Foodweb with 2 trophic links:
A: 3×3 SparseArrays.SparseMatrixCSC{Bool, Int64} with 2 stored entries:
⋅ ⋅ ⋅
1 ⋅ ⋅
⋅ 1 ⋅
From an Adjacency List
Sometimes it is more convenient to define the food web using an adjacency list, because adjacency lists are often more readable than adjacency matrices. Adjacency lists are a list of pairs, where each pair is a consumer-resource interaction.
For instance, the food web presented in the previous example can be defined as:
list = [2 => 1, 3 => 2]
foodweb = Foodweb(list)
blueprint for Foodweb with 2 trophic links:
A:
2 eats 1
3 eats 2
Species can also be named with strings or symbols:
list = [:eagle => :rabbit, :rabbit => :grass]
foodweb = Foodweb(list)
blueprint for Foodweb with 2 trophic links:
A:
:eagle eats :rabbit
:rabbit eats :grass
Creating a Foodweb
from your own adjacency matrix or list is straightforward, but this is mostly useful for simple and small 'toy systems'. If you want to work with Foodweb
s with a large size and a realistic structure, it is more suitable to create the Foodweb
using structural models.
From a Structural Model
You can use the niche, or the cascade model to generate a food web. The niche model requires a number of species, and either a connectance C
or a number of links L
.
fw1 = Foodweb(:niche; S = 5, C = 0.2)
blueprint for Foodweb with 5 trophic links:
A: 5×5 SparseArrays.SparseMatrixCSC{Bool, Int64} with 5 stored entries:
1 1 1 ⋅ ⋅
⋅ ⋅ ⋅ 1 ⋅
⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1
⋅ ⋅ ⋅ ⋅ ⋅
fw2 = Foodweb(:niche; S = 5, L = 5)
blueprint for Foodweb with 5 trophic links:
A: 5×5 SparseArrays.SparseMatrixCSC{Bool, Int64} with 5 stored entries:
⋅ ⋅ ⋅ 1 1
1 1 1 ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅
The cascade model requires a number of species and a connectance:
fw3 = Foodweb(:cascade; S = 5, C = 0.2)
blueprint for Foodweb with 5 trophic links:
A: 5×5 SparseArrays.SparseMatrixCSC{Bool, Int64} with 5 stored entries:
⋅ ⋅ 1 1 ⋅
⋅ ⋅ 1 ⋅ 1
⋅ ⋅ ⋅ ⋅ 1
⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅