Commit 93c06b4e authored by Johannes Leins's avatar Johannes Leins
Browse files

fixed faulty active measure by making all measure ID unsigned

building mean peaks by division through number of simulated years
parent 5f5f9970
......@@ -44,8 +44,8 @@ Point Cell::getCoord() {
return coord;
}
Measure* Cell::getMeasure(int measureID) {
if(measureID < 0 || measureByID.find(measureID) == measureByID.end()) {
Measure* Cell::getMeasure(unsigned int measureID) {
if(measureID == 0 || measureByID.find(measureID) == measureByID.end()) {
return measureByID[activeMeasureID];
}
return measureByID[measureID];
......@@ -77,7 +77,7 @@ double Cell::getCoverRatio() {
return coverRatio;
}
int Cell::getLastDisturbanceTimestep(int measureID) {
int Cell::getLastDisturbanceTimestep(unsigned int measureID) {
return getMeasure(measureID)->getLastUse();
}
......
......@@ -39,10 +39,10 @@ public:
double getCoverRatio();
void addMeasure(Measure *measure = NULL);
void clearMeasures();
Measure* getMeasure(int measureID = -1);
Measure* getMeasure(unsigned int measureID = 0);
void setActiveMeasure(unsigned int measureID);
void setInterpolRatio(Point climCoordInterpol, float ratio);
int getLastDisturbanceTimestep(int measureID = 0);
int getLastDisturbanceTimestep(unsigned int measureID = 0);
bool operator< (const Cell &ob) const;
bool operator== (const Cell &ob) const;
......
......@@ -186,7 +186,7 @@ float Environment::getValue(ClimateVariable climVar, Point coord) {
return value;
}
void Environment::setDisturbanceAt(Point coord, int disturbanceID) {
void Environment::setDisturbanceAt(Point coord, unsigned int disturbanceID) {
if(coord == Point()) {
uniformDisturbances = true;
uniformDisturbanceID = disturbanceID;
......
......@@ -53,7 +53,7 @@ private:
unsigned int maxLon = 0;
unsigned int maxLat = 0;
bool uniformDisturbances = false;
int uniformDisturbanceID;
unsigned int uniformDisturbanceID;
unordered_set<Point> fixedDisturbanceCoords;
unsigned int habitatWidth, climateCellWidth; // in m
int timestep, indexTime;
......@@ -132,7 +132,7 @@ public:
unordered_map<Point, Population*> getNeighborhood(int key);
void setDisturbanceAt(Point coord, int disturbanceID);
void setDisturbanceAt(Point coord, unsigned int disturbanceID);
unsigned int getDisturbanceAt(Point coord);
......
......@@ -46,7 +46,7 @@ private:
double initDensitySqm, minDensitySqm, density, grossDiff, gain, minDensity, meanDensity, thdQuasiExtinct, thdQuasiExtinctSqm;
unordered_map<string, double> meanStats;
unordered_map<string, double> yearlyStats;
int nReset;
int nReset, nStatYears;
int currStatYear = -1;
unordered_map<Point, double> immigrationFrom;
unordered_map<Point, double> emigrationTo;
......
......@@ -61,6 +61,8 @@ void LifeStage::reset(Environment* environment, PopulationAtts* atts) {
yearlyStats["emigration"] = 0.0;
yearlyStats["immigration"] = 0.0;
yearlyStats["mortality"] = 0.0;
currStatYear = -1;
nStatYears = 0;
nQuasiExtinction = 0;
quasiExtinct = false;
if(nReset < 0) { // was called by constructor
......@@ -207,6 +209,7 @@ void LifeStage::update(Environment* environment) {
for(auto yearlyStat : yearlyStats) {
yearlyStats[yearlyStat.first] = 0.0;
}
nStatYears++;
}
bool aliveBefore = isAlive();
density = 0;
......@@ -295,13 +298,13 @@ void LifeStage::update(Environment* environment) {
meanStats["lifetime"]++;
if(density > yearlyPeak) {
yearlyStats["peak"] = density;
meanStats["peak"] += (density - yearlyPeak);
meanStats["peak"] = (density + meanStats["peak"] * (nStatYears - 1)) / nStatYears;
}
double yearlyGrossPeak = yearlyStats["grossPeak"];
double grossDensity = density + grossDiff;
if(grossDensity > yearlyGrossPeak) {
yearlyStats["grossPeak"] = grossDensity;
meanStats["grossPeak"] += (grossDensity - yearlyGrossPeak);
meanStats["grossPeak"] = (grossDensity + meanStats["grossPeak"] * (nStatYears - 1)) / nStatYears;
}
if(quasiExtinct && !(yearlyPeak < thdQuasiExtinct)) { // if marked as quasi extinct, check if it is not below quasi extinct threshold anymore
quasiExtinct = false;
......
......@@ -1661,7 +1661,9 @@ int batchRun() {
for (auto disturbanceScheme : disturbanceSchemes) { // loop over each disturbance scheme
currDisturbanceSchemeID = disturbanceScheme.first;
for(auto lastSchemeCoord : lastSchemeCoords) {
environment->setDisturbanceAt(lastSchemeCoord, baseDisturbanceScheme[lastSchemeCoord]);
unsigned int baseDisturbanceID = baseDisturbanceScheme[lastSchemeCoord];
string distName = disturbanceNameByID[baseDisturbanceID];
environment->setDisturbanceAt(lastSchemeCoord, baseDisturbanceID);
}
lastSchemeCoords.clear();
if(nAlivePrev[currDisturbanceSchemeID] == 0 && dispersalType != BASE_IMMIGRATION && dispersalType != BOTH) { // all dead and no base immigration
......@@ -1672,7 +1674,8 @@ int batchRun() {
if(disturbanceSchemes.size() > 1) {
for(auto pairCoordDist : disturbanceScheme.second) {
Point currSchemeCoord = pairCoordDist.first;
int newDisturbanceID = pairCoordDist.second;
unsigned int newDisturbanceID = pairCoordDist.second;
string distName = disturbanceNameByID[newDisturbanceID];
if(!uniformDisturbances) {
lastSchemeCoords.insert(currSchemeCoord);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment