From 33c931b73a3307ec174b8b0c80a58ee0da1ae6eb Mon Sep 17 00:00:00 2001 From: Theo Pannetier Date: Fri, 29 Nov 2024 10:46:15 +0000 Subject: [PATCH] species obtained internally rather than passsed --- src/RScore/Individual.cpp | 20 ++++++++++---------- src/RScore/Patch.cpp | 34 +++++++++++++++++----------------- src/RScore/Patch.h | 8 ++++---- src/RScore/Population.cpp | 13 ++++++------- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/RScore/Individual.cpp b/src/RScore/Individual.cpp index 6395715b..bca577e8 100644 --- a/src/RScore/Individual.cpp +++ b/src/RScore/Individual.cpp @@ -783,7 +783,7 @@ bool Individual::moveKernel(Landscape* pLandscape, const bool absorbing) if (nx < 0.0) newX = -1; else newX = (int)nx; if (ny < 0.0) newY = -1; else newY = (int)ny; #ifndef NDEBUG - if (path != 0) (path->year)++; + if (path != nullptr) (path->year)++; #endif loopsteps++; } while (loopsteps < 1000 && @@ -796,20 +796,20 @@ bool Individual::moveKernel(Landscape* pLandscape, const bool absorbing) if (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY) { // beyond absorbing boundary // this cannot be reached if not absorbing? - pCell = 0; - patch = 0; + pCell = nullptr; + patch = nullptr; patchNum = -1; } else { pCell = pLandscape->findCell(newX, newY); - if (pCell == 0) { // no-data cell - patch = 0; + if (pCell == nullptr) { // no-data cell + patch = nullptr; patchNum = -1; } else { patch = pCell->getPatch(); - if (patch == 0) { // matrix - pPatch = 0; + if (patch == nullptr) { // matrix + pPatch = nullptr; patchNum = 0; } else { @@ -820,16 +820,16 @@ bool Individual::moveKernel(Landscape* pLandscape, const bool absorbing) } } else { // exceeded 1000 attempts - patch = 0; + patch = nullptr; patchNum = -1; } } while (!absorbing && patchNum < 0 && loopsteps < 1000); // in a no-data region } while (!usefullkernel && pPatch == pNatalPatch && loopsteps < 1000); // still in the original (natal) patch if (loopsteps < 1000) { - if (pCell == 0) { // beyond absorbing boundary or in no-data cell + if (pCell == nullptr) { // beyond absorbing boundary or in no-data cell // only if absorbing=true and out of bounddaries - pCurrCell = 0; + pCurrCell = nullptr; status = diedInTransfer; isDispersing = false; } diff --git a/src/RScore/Patch.cpp b/src/RScore/Patch.cpp index e18965a7..d5412bc6 100644 --- a/src/RScore/Patch.cpp +++ b/src/RScore/Patch.cpp @@ -32,8 +32,12 @@ Patch::Patch(int seqnum, int num) { pPop = nullptr; - patchSeqNum = seqnum; patchNum = num; nCells = 0; - xMin = yMin = 999999999; xMax = yMax = 0; x = y = 0; + patchSeqNum = seqnum; + patchNum = num; + nCells = 0; + xMin = yMin = 999999999; + xMax = yMax = 0; + x = y = 0; localK = 0.0; for (int sex = 0; sex < gMaxNbSexes; sex++) { nTemp[sex] = 0; @@ -124,9 +128,10 @@ void Patch::addCell(Cell* pCell, int x, int y) { // Calculate the total carrying capacity (no. of individuals) and // centroid co-ordinates of the patch -void Patch::setCarryingCapacity(Species* pSpecies, patchLimits landlimits, - float epsGlobal, short nHab, short rasterType, short landIx, bool gradK) { +void Patch::setCarryingCapacity(patchLimits landlimits, float epsGlobal, + short nHab, short rasterType, short landIx, bool gradK) { + Species* pSpecies = pPop->getSpecies(); envStochParams env = paramsStoch->getStoch(); locn loc; int xsum, ysum; @@ -146,7 +151,7 @@ void Patch::setCarryingCapacity(Species* pSpecies, patchLimits landlimits, return; } - int ncells = cells.size(); + int ncells = static_cast(cells.size()); xsum = ysum = 0; for (int i = 0; i < ncells; i++) { if (gradK) // gradient in carrying capacity @@ -219,14 +224,14 @@ int Patch::getInitNbInds(const bool& isPatchModel, const int& landResol) const { if (localK > 0.0) { // patch is currently suitable for this species switch (init.initDens) { case 0: // at carrying capacity - nInds = trunc(localK); + nInds = static_cast(localK); break; case 1: // at half carrying capacity - nInds = trunc(localK / 2.0); + nInds = static_cast(localK / 2.0); break; case 2: // specified no. per cell or density if (isPatchModel) { - nInds = trunc(init.indsHa * (float)(nCells * landResol * landResol) / 10000.0); + nInds = static_cast(init.indsHa * (float)(nCells * landResol * landResol) / 10000.0); } else { nInds = init.indsCell * nCells; @@ -336,18 +341,13 @@ void Patch::resetPossSettlers() { } // Record the presence of a potential settler within the Patch -void Patch::incrPossSettler(Species* pSpecies, int sex) { -// NOTE: THE FOLLOWING OPERATION WILL NEED TO BE MADE SPECIES-SPECIFIC... - if (sex >= 0 && sex < gMaxNbSexes) { - nTemp[sex]++; - } +void Patch::incrPossSettler(int sex) { + nTemp[sex]++; } // Get number of a potential settlers within the Patch -int Patch::getPossSettlers(Species* pSpecies, int sex) { -// NOTE: THE FOLLOWING OPERATION WILL NEED TO BE MADE SPECIES-SPECIFIC... - if (sex >= 0 && sex < gMaxNbSexes) return nTemp[sex]; - else return 0; +int Patch::getPossSettlers(int sex) { + return nTemp[sex]; } bool Patch::speciesIsPresent() { diff --git a/src/RScore/Patch.h b/src/RScore/Patch.h index e726f696..92117917 100644 --- a/src/RScore/Patch.h +++ b/src/RScore/Patch.h @@ -112,14 +112,14 @@ class Patch { void resetPop(); // Record the presence of a potential settler within the Patch - void incrPossSettler(Species* pSpecies, int sex); + void incrPossSettler(int sex); // Get number of a potential settlers within the Patch - int getPossSettlers(Species* pSpecies, int sex); + int getPossSettlers(int sex); void resetPossSettlers(); // Calculate total Patch carrying capacity (no. of inds) - void setCarryingCapacity(Species* pSpecies, patchLimits landlimits, - float epsGlobal, short nHab, short rasterType, short landIx, bool gradK); + void setCarryingCapacity(patchLimits landlimits, float epsGlobal, + short nHab, short rasterType, short landIx, bool gradK); float getK(); int getInitNbInds(const bool& isPatchModel, const int& landResol) const; diff --git a/src/RScore/Population.cpp b/src/RScore/Population.cpp index d2bc6f20..24644d4f 100644 --- a/src/RScore/Population.cpp +++ b/src/RScore/Population.cpp @@ -523,7 +523,7 @@ void Population::reproduction(const float localK, const float envval, const int { // get population size at start of reproduction - int ninds = inds.size(); + int ninds = static_cast(inds.size()); if (ninds == 0) return; int nsexes, stage, sex, njuvs, nj, nmales, nfemales; @@ -944,17 +944,16 @@ disperser Population::extractDisperser(int ix) { // if it is a settler, return its new location and remove it from the current population // otherwise, leave it in the matrix population for possible reporting before deletion disperser Population::extractSettler(int ix) { + disperser d = disperser(); - Cell* pCell; - indStats ind = inds[ix]->getStats(); - pCell = inds[ix]->getLocn(1); + Cell* pCell = inds[ix]->getLocn(1); d.pInd = inds[ix]; d.pCell = pCell; d.yes = false; if (ind.status == settled || ind.status == settledNeighbour) { d.yes = true; - inds[ix] = 0; + inds[ix] = nullptr; nInds[ind.stage][ind.sex]--; } return d; @@ -1017,7 +1016,7 @@ int Population::transfer(Landscape* pLandscape, short landIx, short nextseason) pCell = inds[i]->getLocn(1); pPatch = pCell->getPatch(); if (pPatch != nullptr) { // not no-data area - pPatch->incrPossSettler(pSpecies, inds[i]->getSex()); + pPatch->incrPossSettler(inds[i]->getSex()); } } } @@ -1212,7 +1211,7 @@ bool Population::isMatePresent(Cell* pCell, short othersex) } } // If empty, check for incoming settlers - if (pPatch->getPossSettlers(pSpecies, othersex) > 0) + if (pPatch->getPossSettlers(othersex) > 0) return true; } }