-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutualists.c
63 lines (61 loc) · 1.96 KB
/
mutualists.c
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
57
58
59
60
61
62
63
#include "landscape.h"
#include "array.h"
#include "randpois.h"
int mutualists(double ***SCAPE,int Ma,int **M, int **P,int beta,int deltaM,int X,int flower,int *Sds, int iter){
FILE *Mv;
int i, j, k, n, c, m, rx[2], ry[2], disp, z, q;
Mv = fopen("Mv.dat","w");
for(i=0; i<Ma; i++){
disp = randpois(beta);
j = 0;
while(j < disp){
rx[0] = M[i][0] - deltaM;
rx[1] = M[i][0] + deltaM;
ry[0] = M[i][1] - deltaM;
ry[1] = M[i][1] + deltaM;
n = floor((rx[1]-rx[0]+1)*randunif()) - deltaM;
m = floor((ry[1]-ry[0]+1)*randunif()) - deltaM;
z = M[i][0] + n;
q = M[i][1] + m;
if(z < 0){
z = X - abs(n) + z;
}
if(z >= X){
z = n - (z - X);
}
if(q < 0){
q = X - abs(m) + q;
}
if(q >= X){
q = m - (q - X);
}
M[i][0] = z;
M[i][1] = q;
c = SCAPE[z][q][1];
if(c > 0){
if(iter == 999){
fprintf(Mv,"%d\t%d\n",z,q);
}
Sds[2]++;
for(k=0; k<flower; k++){ /* OR below lets Polls use pollinated flowers */
if(P[c][k+2] == 1 || P[c][k+2] == 2){
if(randunif() > 0.5){
P[c][k+2] = 2;
}else{
P[c][k+2] = 3;
SCAPE[z][q][0]++;
}
}
}
/* break; */
}
j++;
}
if(randunif() > 0.2){
z = M[i][0];
q = M[i][1];
SCAPE[z][q][0]++;
} /* This if loop allows mutualists to survive multiple generations */
}
return EXIT_SUCCESS;
}