From 4a05004173541267970562f4a3f16f46039e5340 Mon Sep 17 00:00:00 2001 From: Jette Reeg Date: Tue, 16 Jul 2024 13:24:01 +0200 Subject: [PATCH] flagged rcpp output as RS_RCPP --- Management.cpp | 34 ++++++++++++++++++++++++++++++++++ Population.cpp | 13 ++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Management.cpp b/Management.cpp index c0a273b..821b493 100644 --- a/Management.cpp +++ b/Management.cpp @@ -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); @@ -108,36 +110,48 @@ 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; @@ -145,15 +159,21 @@ void Management::translocate(int yr 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; } } @@ -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; } } @@ -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); @@ -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(); } diff --git a/Population.cpp b/Population.cpp index 4c6f524..abf48b8 100644 --- a/Population.cpp +++ b/Population.cpp @@ -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 } @@ -1684,8 +1686,9 @@ std::vector Population::getIndsWithCharacteristics( // Select a se // get all suitable individuals based on settings std::vector 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++) { @@ -1737,7 +1740,9 @@ std::vector Population::getIndsWithCharacteristics( // Select a se } } } else { +#if RS_RCPP Rcpp::Rcout << "No individuals in source patch" << endl; +#endif return filteredInds; } int nfiltered = 0; @@ -1775,9 +1780,9 @@ int Population::sampleIndividuals( // Select a set of individuals with specified // get individuals with the characteristics std::vector 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; @@ -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];