Skip to content

Commit

Permalink
flagged rcpp output as RS_RCPP
Browse files Browse the repository at this point in the history
  • Loading branch information
JetteReeg committed Jul 16, 2024
1 parent c11b3c1 commit 4a05004
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
34 changes: 34 additions & 0 deletions Management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ void Management::translocate(int yr
, Landscape* pLandscape
, Species* pSpecies
){
#if RS_RCPP
Rcpp::Rcout << "Start translocation events in year " << yr << endl;
#endif
landParams ppLand = pLandscape->getLandParams();
auto it = nb.find(yr); // the number of translocation events is determined by the number of elements of the maps at year yr
auto nb_it = nb.find(yr);
Expand All @@ -108,52 +110,70 @@ void Management::translocate(int yr
auto sex_it = sex.find(yr);
// iterate over the number of events
for (int e = 0; e < it->second.size(); e++) {
#if RS_RCPP
Rcpp::Rcout << "Translocation event " << e << " in year " << yr << endl;
#endif
// find the source patch
Patch* s_patch;
Population* s_pPop;
if(ppLand.patchModel){
if(pLandscape->existsPatch(source_it->second[e].x)){
#if RS_RCPP
Rcpp::Rcout << "Source patch exist." << endl;
#endif
s_patch = pLandscape->findPatch(source_it->second[e].x);
if (s_patch != 0) {
// test if population in patch is not zero
s_pPop = (Population*)s_patch->getPopn((intptr)pSpecies); // returns the population of the species in that cell
if (s_pPop != 0 && s_pPop->getNInds() > 0){
} else {
#if RS_RCPP
Rcpp::Rcout << "Population does not exist in source patch or is 0! skipping translocation event." << endl;
#endif
return;
}
} else {
#if RS_RCPP
Rcpp::Rcout << "Source patch was found but NULL! skipping translocation event." << endl; // not sure if this ever happens
#endif
return;
}
//
} else{
#if RS_RCPP
Rcpp::Rcout << "Source patch was not found in landscape! skipping translocation event." << endl;
#endif
return;
}
} else{
Cell* pCell;
pCell = pLandscape->findCell(source_it->second[e].x, source_it->second[e].y);
if (pCell != 0) {
#if RS_RCPP
Rcpp::Rcout << "Source cell was found" << endl;
#endif
intptr s_ppatch = pCell->getPatch();
if (s_ppatch != 0) {
s_patch = (Patch*)s_ppatch;
// test if population in patch is not zero
s_pPop = (Population*)s_patch->getPopn((intptr)pSpecies); // returns the population of the species in that cell
if (s_pPop != 0 && s_pPop->getNInds() > 0){
} else {
#if RS_RCPP
Rcpp::Rcout << "Population does not exist in source cell or is 0! skipping translocation event." << endl;
#endif
return;
}
} else {
#if RS_RCPP
Rcpp::Rcout << "Source cell does not exist! skipping translocation event." << endl;
#endif
return;
}
} else {
#if RS_RCPP
Rcpp::Rcout << "Cell does not belong to landscape! skipping translocation event." << endl;
#endif
return;
}
}
Expand All @@ -162,26 +182,36 @@ void Management::translocate(int yr
Population* t_pPop;
if(ppLand.patchModel){
if(pLandscape->existsPatch(target_it->second[e].x)){
#if RS_RCPP
Rcpp::Rcout << "Target patch exist." << endl;
#endif
t_patch = pLandscape->findPatch(target_it->second[e].x);
} else{
#if RS_RCPP
Rcpp::Rcout << "Target patch was not found in landscape! skipping translocation event." << endl;
#endif
return;
}
} else{
Cell* pCell;
pCell = pLandscape->findCell(target_it->second[e].x, target_it->second[e].y);
if (pCell != 0) {
#if RS_RCPP
Rcpp::Rcout << "Target cell was found" << endl;
#endif
intptr t_ppatch = pCell->getPatch();
if (t_ppatch != 0) {
t_patch = (Patch*)t_ppatch;
} else {
#if RS_RCPP
Rcpp::Rcout << "Target cell does not exist! skipping translocation event." << endl;
#endif
return;
}
} else {
#if RS_RCPP
Rcpp::Rcout << "Target cell does not belong to landscape! skipping translocation event." << endl;
#endif
return;
}
}
Expand Down Expand Up @@ -209,7 +239,9 @@ void Management::translocate(int yr
// Check if a population of this species already exists in target patch t_patch
t_pPop = (Population*)t_patch->getPopn((intptr)pSpecies);
if (t_pPop == 0) { // translocated individual is the first in a previously uninhabited patch
#if RS_RCPP
Rcpp::Rcout << "Population does not exist in target patch. Creating new population." << endl;
#endif
// create a new population in the corresponding sub-community
SubCommunity* pSubComm = (SubCommunity*)t_patch->getSubComm();
t_pPop = pSubComm->newPopn(pLandscape, pSpecies, t_patch, 0);
Expand All @@ -232,7 +264,9 @@ void Management::translocate(int yr
}
}
}
#if RS_RCPP
Rcpp::Rcout << "Successfully translocated " << translocated << " out of " << nb_it->second[e] << " individuals in translocation event " << e <<"." << endl;
#endif
// remove pointers to sampled individuals
s_pPop->clean();
}
Expand Down
13 changes: 10 additions & 3 deletions Population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ void Population::reproduction(const float localK, const float envval, const int
inds[i]->resetFallow();
// NOTE: FOR COMPLEX SEXUAL MODEL, NO. OF FEMALES *ACTUALLY* BREEDING DOES NOT
// NECESSARILY EQUAL THE EXPECTED NO. FROM EQN. 7 IN THE MANUAL...
#if RS_RCPP
if(propBreed > 1) Rcpp::Rcout << "propBreed: " << propBreed << std::endl;
#endif
if (pRandom->Bernoulli(propBreed)) {
expected = fec[stage][0]; // breeds
}
Expand Down Expand Up @@ -1684,8 +1686,9 @@ std::vector <Individual*> Population::getIndsWithCharacteristics( // Select a se
// get all suitable individuals based on settings
std::vector <Individual*> filteredInds;
int ninds = (int)inds.size();
#if RS_RCPP
Rcpp::Rcout << "Number individuals in cell: " << ninds << endl;

#endif
if (ninds > 0) {
// copy ALL individuals to filteredInds
for (int i = 0; i < ninds; i++) {
Expand Down Expand Up @@ -1737,7 +1740,9 @@ std::vector <Individual*> Population::getIndsWithCharacteristics( // Select a se
}
}
} else {
#if RS_RCPP
Rcpp::Rcout << "No individuals in source patch" << endl;
#endif
return filteredInds;
}
int nfiltered = 0;
Expand Down Expand Up @@ -1775,9 +1780,9 @@ int Population::sampleIndividuals( // Select a set of individuals with specified
// get individuals with the characteristics
std::vector <Individual*> filtered;
filtered = getIndsWithCharacteristics(min_age, max_age, stage, sex);

#if RS_RCPP
Rcpp::Rcout << "Number of individuals with fitting characteristics: " << filtered.size() << endl;

#endif
if (filtered.size() <= nb)
// Sample all individuals in selected stages
sampledInds = filtered;
Expand Down Expand Up @@ -1808,7 +1813,9 @@ Individual* Population::catchIndividual( // Translocate a set of individuals wit
// If individual is part of the sampledInds vector:
if (std::find(sampledInds.begin(), sampledInds.end(), inds[j]) != std::end(sampledInds)){
// try to catch individual
#if RS_RCPP
if(catching_rate > 1) Rcpp::Rcout << "Catching rate: " << catching_rate << std::endl;
#endif
if (pRandom->Bernoulli(catching_rate)){
indStats indstat = inds[j]->getStats();
catched = inds[j];
Expand Down

0 comments on commit 4a05004

Please sign in to comment.