-
Notifications
You must be signed in to change notification settings - Fork 2
/
interaction_existence_niche.m
57 lines (45 loc) · 1.06 KB
/
interaction_existence_niche.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function A_interaction = interaction_existence_niche(S,C,d)
%This function generates adjacency matrix for a niche food web
%S - Number of species
%C - Connectance
%d - Self-regulation strength
temp=zeros(S,S); beta=1/C-1;
niche_value=zeros(S,1);
niche_radius=zeros(S,1);
niche_center=zeros(S,1);
for i=1:S
niche_value(i)=rand();
end
niche_value=sort(niche_value);
for i=1:S
B=betarnd(1,beta);
niche_radius(i)=niche_value(i)*B;
temp1=0.5*niche_radius(i);
temp2=min(niche_value(i),1-0.5*niche_radius(i));
niche_center(i)=temp1+(temp2-temp1)*rand();
end
for i=1:S
for j=1:S
if(niche_value(j)>=niche_center(i)-0.5*niche_radius(i))&&(niche_value(j)<=niche_center(i)+0.5*niche_radius(i))
temp(j,i)=1;
end
end
end
for i=1:S
temp(i,i)=-d;
end
for i=1:S
for j=i+1:S
if(temp(i,j)==1)&&(temp(j,i)==1)
p=rand();
if(p<=0.5)
temp(j,i)=0;
end
if(p>0.5)
temp(i,j)=0;
end
end
end
end
A_interaction=temp;
end