-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtinctionTracker.h
108 lines (86 loc) · 3.03 KB
/
ExtinctionTracker.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* InteractionTracker.h
*
* Created on: 3 Sep 2014
* Author: rusty
*
* Class to check for regional extinction of interactions.
* ?? ALSO NEED TO CHECK FOR EXTINCTION OF SPECIES?? (no because thsi would lead to extiction of interaction, unless species is non-interacting)
*/
#ifndef EXTINCTIONTRACKER_H_
#define EXTINCTIONTRACKER_H_
#include <vector>
using namespace std;
class ExtinctionTracker{
private:
int numberOfInteractions;
vector<vector<int> > interactionIJ; // the location of the interactions in the C_plant vector
vector<vector<double> >& C_plant;
vector<vector<double> >& C_animal;
// vector<int> interactionPresence; // to store global presence/absence of each interaction
public:
~ExtinctionTracker(){}
ExtinctionTracker(vector<vector<double> >& C_plant, vector<vector<double> >& C_animal):C_plant(C_plant), C_animal(C_animal){
int tempInteractionCount = 0;
for (unsigned int i=0; i<C_plant.size(); i++){
for (unsigned int j=0; j<C_plant.at(0).size(); j++){
if (C_plant.at(i).at(j)!=0){
tempInteractionCount++;
vector<int> tempIJ;
tempIJ.push_back(i);
tempIJ.push_back(j);
interactionIJ.push_back(tempIJ);
}
}
}
numberOfInteractions = tempInteractionCount;
// interactionPresence.resize(numberOfInteractions, 1); // initially all interactions are present (as all species exist in each patch)
}
// check for regional extinction of interactions, returns true if all interactions are present in at least one patch
bool checkExtinctions(vector<Patch>& patches){
if (!checkForInteractionExtinctions(patches)){return false;}
// if (!checkForSpeciesExtinctions(patches)){return false;} // weaker conditions than the above
return true;
}
private:
bool checkForInteractionExtinctions(vector<Patch>& patches){ // returns false if an interaction has gone extinct
for (int i=0; i<numberOfInteractions; i++){
if (!checkForIthInteraction(i, patches)){return false;} // this interaction is extinct
}
return true;
}
bool checkForSpeciesExtinctions(vector<Patch>& patches){ // returns false if at least one species is regionally extinct
for (unsigned int i=0; i<C_plant.size(); i++){
if(!checkForIthPlant(i,patches)){return false;}
}
for (unsigned int i=0; i<C_animal.size(); i++){
if(!checkForJthAnimal(i,patches)){return false;}
}
return true;
}
bool checkForIthInteraction(int I, vector<Patch>& patches){
for (unsigned int p=0; p<patches.size(); p++){
if (patches.at(p).isPlantPresent(interactionIJ.at(I).at(0)) && patches.at(p).isAnimalPresent(interactionIJ.at(I).at(1))){
return true;
}
}
return false;
}
bool checkForIthPlant(int I, vector<Patch>& patches){
for (unsigned int p=0; p<patches.size(); p++){
if (patches.at(p).isPlantPresent(I)){
return true;
}
}
return false;
}
bool checkForJthAnimal(int J, vector<Patch>& patches){
for (unsigned int p=0; p<patches.size(); p++){
if (patches.at(p).isAnimalPresent(J)){
return true;
}
}
return false;
}
};
#endif /* EXTINCTIONTRACKER_H_ */