-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunity.h
More file actions
240 lines (208 loc) · 7.97 KB
/
Copy pathCommunity.h
File metadata and controls
240 lines (208 loc) · 7.97 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*----------------------------------------------------------------------------
*
* Copyright (C) 2026 Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Anne-Kathleen Malchow, Roslyn Henry, Théo Pannetier, Jette Wolff, Damaris Zurell
*
* This file is part of RangeShifter.
*
* RangeShifter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RangeShifter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RangeShifter. If not, see <https://www.gnu.org/licenses/>.
*
--------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
RangeShifter v2.0 Community
Implements the Community class
There is ONLY ONE instance of a Community in an individual replicate simulation.
It holds a SubCommunity for each Patch in the Landscape (including the matrix),
and is thus the highest-level entity accessed for most processing concerned with
simulated populations.
Optionally, the Community maintains a record of the occupancy of suitable cells
or patches during the course of simulation of multiple replicates.
For full details of RangeShifter, please see:
Bocedi G., Palmer S.C.F., Pe’er G., Heikkinen R.K., Matsinos Y.G., Watts K.
and Travis J.M.J. (2014). RangeShifter: a platform for modelling spatial
eco-evolutionary dynamics and species’ responses to environmental changes.
Methods in Ecology and Evolution, 5, 388-396. doi: 10.1111/2041-210X.12162
Authors: Greta Bocedi & Steve Palmer, University of Aberdeen
Last updated: 25 June 2021 by Anne-Kathleen Malchow
------------------------------------------------------------------------------*/
#ifndef CommunityH
#define CommunityH
#include <vector>
#include <algorithm>
#include <memory>
#include <ranges>
using namespace std;
#include "SubCommunity.h"
#include "Landscape.h"
#include "Patch.h"
#include "Cell.h"
#include "Species.h"
#include "NeutralStatsManager.h"
//---------------------------------------------------------------------------
struct commStats {
int ninds,nnonjuvs,suitable,occupied;
int minX,maxX,minY,maxY;
};
#if RS_RCPP// For raster output only: which type of population output should be stored?
enum class PopOutType {
NInd, // total abundance
Stage, // specific stages
Juvs // juvenile stage
};
#endif
class Community {
public:
Community(Landscape*);
~Community(void);
SubCommunity* addSubComm(Patch*,int);
// functions to manage populations occurring in the community
void initialise(
Species*, // pointer to Species
int // year (relevent only for seedType == 2)
);
void addManuallySelected(void);
void resetPopns(void);
void localExtinction(int);
void patchChanges(void);
void reproduction(
int // year
);
void emigration(void);
#if RS_RCPP // included also SEASONAL
void dispersal(
short, // landscape change index
short // season / year
);
#else
void dispersal(
short // landscape change index
);
#endif // SEASONAL || RS_RCPP
void survival0( // Determine survival & development
short, // option0: 0 = stage 0 (juveniles) only )
// 1 = all stages ) used by part 0 only
// 2 = stage 1 and above (all non-juvs) )
short // option1: 0 - development only (when survival is annual)
// 1 - development and survival
);
void survival1(); // Apply survival changes to the population
void ageIncrement(void);
int totalInds(void);
Population* findPop( // Find the population of a given species in a given patch
Species*, // pointer to Species
Patch* // pointer to Patch
);
commStats getStats(void);
void createOccupancy(
int, // no. of rows = (no. of years / interval) + 1
int // no. of replicates
);
void updateOccupancy(
int, // row = (no. of years / interval)
int // replicate
);
void deleteOccupancy(
int // no. of rows (as above)
);
bool outRangeFinishLandscape(); // Close range file
bool outRangeStartLandscape( // Open range file and write header record
Species*, // pointer to Species
int // Landscape number
);
void outRange( // Write record to range file
Species*, // pointer to Species
int, // replicate
int, // year
int // generation
);
bool outPopFinishLandscape(); // Close population file
bool outPopStartLandscape( // Open population file and write header record
Species* // pointer to Species
);
void outPop( // Write records to population file
int, // replicate
int, // year
int // generation
);
void outIndsFinishReplicate(); // Close individuals file
void outIndsStartReplicate( // Open individuals file and write header record
int, // replicate
int // Landscape number
);
void outIndividuals( // Write records to individuals file
int, // replicate
int, // year
int // generation
);
// Close occupancy file
bool outOccupancyFinishLandscape();
// Open occupancy file, write header record and set up occupancy array
bool outOccupancyStartLandscape();
void outOccupancy(void);
void outOccSuit();
bool outTraitsFinishLandscape(); // Close traits file
bool outTraitsStartLandscape( // Open traits file and write header record
Species*, // pointer to Species
int // Landscape number
);
bool outTraitsRowsFinishLandscape(); // Close trait rows file
bool outTraitsRowsStartLandscape( // Open trait rows file and write header record
Species*, // pointer to Species
int // Landscape number
);
void outTraits( // Write records to traits file
Species*, // pointer to Species
int, // replicate
int, // year
int // generation
);
void writeTraitsRows( // Write records to trait rows file
Species*, // pointer to Species
int, // replicate
int, // year
int, // generation
int, // row number (Y cell co-ordinate)
traitsums // structure holding sums of trait genes for dispersal (see Population.h)
);
#if RS_RCPP && !R_CMD
Rcpp::IntegerMatrix addYearToPopList(int,int,PopOutType,int);
Rcpp::IntegerMatrix addYearToPopListPatchBased(int,int,Rcpp::LogicalVector);
#endif
//sample individuals for genetics (or could be used for anything)
void sampleIndividuals(Species* pSpecies);
bool openOutGenesFile(const bool& isDiploid, const int landNr, const int rep);
void outputGeneValues(const int& year, const int& gen, Species* pSpecies);
//control neutral stat output
void calculateNeutralGenetics(Species* pSpecies, int rep, int yr, int gen, bool outPairwiseFst, int outputPairwiseFstStart, int outputPairwiseFstInterval,
bool outputGlobalFst, int outputGlobalFstStart, int outputGlobalFstInterval, bool outputPerLocusFst);
//file openers
bool openNeutralOutputFile(Species* pSpecies, const int landNr);
bool openPerLocusFstFile(Species* pSpecies, Landscape* pLandscape, const int landNr, const int rep);
bool openPairwiseFstFile(Species* pSpecies, Landscape* pLandscape, const int landNr, const int rep);
//file writers
void writeNeutralOutputFile(int rep, int yr, int gen);
void writePerLocusFstatFile(Species* pSpecies, const int yr, const int gen, const int nLoci, set<int> const& patchList);
void writePairwiseFstFile(Species* pSpecies, const int yr, const int gen, set<int> const& patchList);
float getPatchHet(Species* pSpecies, int patchId, int whichLocus) const;
private:
Landscape *pLandscape;
int indIx; // index used to apply initial individuals
float **occSuit; // occupancy of suitable cells / patches
std::vector <SubCommunity*> subComms;
//below won't work for multispecies
unique_ptr<NeutralStatsManager> pNeutralStatistics;
};
extern paramSim *paramsSim;
extern paramInit *paramsInit;
//---------------------------------------------------------------------------
#endif