Skip to content

Commit

Permalink
species obtained internally rather than passsed
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed Nov 29, 2024
1 parent 14fc40e commit 33c931b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
20 changes: 10 additions & 10 deletions src/RScore/Individual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down
34 changes: 17 additions & 17 deletions src/RScore/Patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -146,7 +151,7 @@ void Patch::setCarryingCapacity(Species* pSpecies, patchLimits landlimits,
return;
}

int ncells = cells.size();
int ncells = static_cast<int>(cells.size());
xsum = ysum = 0;
for (int i = 0; i < ncells; i++) {
if (gradK) // gradient in carrying capacity
Expand Down Expand Up @@ -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<int>(localK);
break;
case 1: // at half carrying capacity
nInds = trunc(localK / 2.0);
nInds = static_cast<int>(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<int>(init.indsHa * (float)(nCells * landResol * landResol) / 10000.0);
}
else {
nInds = init.indsCell * nCells;
Expand Down Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/RScore/Patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions src/RScore/Population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(inds.size());
if (ninds == 0) return;

int nsexes, stage, sex, njuvs, nj, nmales, nfemales;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 33c931b

Please sign in to comment.