Skip to content

Commit

Permalink
fix merge conflict with develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed Apr 17, 2024
2 parents 7a366c3 + 0b36338 commit 43c3046
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 92 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Anyone who whishes to make changes to RangeShifter's code, including regular dev
<<<<<<<< HEAD:src/RScore/CONTRIBUTING.md
![](branches.png)

*Check out the [Git cheatsheet](https://github.com/RangeShifter/RScore/git_cheatsheet.md) for a reminder on the main git commands*
*Check out the [Git cheatsheet](https://github.com/RangeShifter/RScore/blob/main/git_cheatsheet.md) for a reminder on the main git commands*

========
>>>>>>>> develop:CONTRIBUTING.md
Expand Down
150 changes: 83 additions & 67 deletions Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1302,33 +1302,36 @@ int Landscape::readLandChange(int filenum, bool costs)
if (p == pchnodata) Rcpp::Rcout << "Found patch NA in valid habitat cell." << std::endl;
else Rcpp::Rcout << "Found negative patch ID in valid habitat cell." << std::endl;
#endif
hfile.close(); hfile.clear();
pfile.close(); pfile.clear();
return 34;
}
else {
patchChgMatrix[y][x][2] = p;
if (p > 0 && !existsPatch(p)) {
addPatchNum(p);
newPatch(pchseq++, p);
}
}
}
if (costs) {
if (c < 1) { // invalid cost
hfile.close(); hfile.clear();
if (pfile.is_open()) {
pfile.close(); pfile.clear();
}
return 38;
}
else {
costsChgMatrix[y][x][2] = c;
}
}
hfile.close(); hfile.clear();
pfile.close(); pfile.clear();
return 34;
}
else {
patchChgMatrix[y][x][2] = p;
if (p > 0 && !existsPatch(p)) {
addPatchNum(p);
newPatch(pchseq++, p);
}
}
}
if (costs) {
if (c < 1) { // invalid cost
#if RS_RCPP
Rcpp::Rcout << "Found invalid cost value of " << c << " in cell x " << x << " and y " << y << std::endl;
#endif
hfile.close(); hfile.clear();
if (pfile.is_open()) {
pfile.close(); pfile.clear();
}
return 38;
}
else {
costsChgMatrix[y][x][2] = c;
}
}
}
} // for x
} // for y
#if RS_RCPP
hfile >> hfloat;
if (!hfile.eof()) EOFerrorR("habitatchgfile");
Expand Down Expand Up @@ -1440,33 +1443,36 @@ int Landscape::readLandChange(int filenum, bool costs)
if (p == pchnodata) Rcpp::Rcout << "Found patch NA in valid habitat cell." << std::endl;
else Rcpp::Rcout << "Found negative patch ID in valid habitat cell." << std::endl;
#endif
hfile.close(); hfile.clear();
pfile.close(); pfile.clear();
return 34;
}
else {
patchChgMatrix[y][x][2] = p;
if (p > 0 && !existsPatch(p)) {
addPatchNum(p);
newPatch(pchseq++, p);
}
}
hfile.close(); hfile.clear();
pfile.close(); pfile.clear();
return 34;
}
else {
patchChgMatrix[y][x][2] = p;
if (p > 0 && !existsPatch(p)) {
addPatchNum(p);
newPatch(pchseq++, p);
}
if (costs) {
if (c < 1) { // invalid cost
hfile.close(); hfile.clear();
if (pfile.is_open()) {
pfile.close(); pfile.clear();
}
return 38;
}
else {
costsChgMatrix[y][x][2] = c;
}
}
}
if (costs) {
if (c < 1) { // invalid cost
#if RS_RCPP
Rcpp::Rcout << "Found invalid cost value of " << c << "in cell x " << x << " and y " << y << std::endl;
#endif
hfile.close(); hfile.clear();
if (pfile.is_open()) {
pfile.close(); pfile.clear();
}
return 38;
}
else {
costsChgMatrix[y][x][2] = c;
}
}
}
} // end x
} // end y
#if RS_RCPP
hfile >> hfloat;
if (!hfile.eof()) EOFerrorR("habitatchgfile");
Expand Down Expand Up @@ -1694,9 +1700,7 @@ bool Landscape::inInitialDist(Species* pSpecies, locn loc) {
}

void Landscape::deleteDistribution(Species* pSpecies) {
// WILL NEED TO SELECT DISTRIBUTION FOR CORRECT SPECIES ...
// ... CURRENTLY IT IS THE ONLY ONE
if (distns[0] != 0) delete distns[0];
if (distns[0] != 0) delete distns[0]; distns.clear();
}

// Return no. of initial distributions
Expand Down Expand Up @@ -2327,14 +2331,18 @@ int Landscape::readCosts(string fname)
#else
if (header != "ncols" && header != "NCOLS") {
#endif
// MessageDlg("The selected file is not a raster.",
// MessageDlg("Header problem in import_CostsLand()",
// mtError, TMsgDlgButtons() << mbRetry,0);
costs.close(); costs.clear();
return -1;
}
costs >> maxXcost >> header >> maxYcost >> header >> minLongCost;
costs >> header >> minLatCost >> header >> resolCost >> header >> NODATACost;

// MessageDlg("The selected file is not a raster.",
// MessageDlg("Header problem in import_CostsLand()",
// mtError, TMsgDlgButtons() << mbRetry,0);
costs.close(); costs.clear();
return -1;
}
double tmpresolCost;
costs >> maxXcost >> header >> maxYcost >> header >> minLongCost;
costs >> header >> minLatCost >> header >> tmpresolCost >> header >> NODATACost;
resolCost = (int) tmpresolCost;


for (int y = maxYcost - 1; y > -1; y--) {
for (int x = 0; x < maxXcost; x++) {
Expand All @@ -2359,17 +2367,25 @@ int Landscape::readCosts(string fname)
#endif
if (hc < 1 && hc != NODATACost) {
#if RS_RCPP && !R_CMD
Rcpp::Rcout << "Cost map my only contain values of 1 or higher, but found " << fcost << "." << endl;
Rcpp::Rcout << "Cost map may only contain values of 1 or higher, but found " << fcost << "." << endl;
#endif
// error - zero / negative cost not allowed
costs.close(); costs.clear();
return -999;
}
pCell = findCell(x, y);
if (pCell != 0) { // not no-data cell
pCell->setCost(hc);
if (hc > maxcost) maxcost = hc;
}
// error - zero / negative cost not allowed
costs.close(); costs.clear();
return -999;
}
pCell = findCell(x, y);
if (pCell != 0) { // not no-data cell
if (hc > 0){ // only if cost value is above 0 in a data cell
pCell->setCost(hc);
if (hc > maxcost) maxcost = hc;
} else { // if cost value is below 0
#if RS_RCPP && !R_CMD
Rcpp::Rcout << "Cost map may only contain values of 1 or higher in habitat cells, but found " << hc << " in cell x: " << x << " y: " << y << "." << endl;
#endif
throw runtime_error("Found negative- or zero-cost habitat cell.");
}

} // end not no data cell
}
}
#if RS_RCPP
Expand Down
45 changes: 39 additions & 6 deletions Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ int RunModel(Landscape* pLandscape, int seqsim)

}

#if RS_EMBARCADERO || LINUX_CLUSTER || RS_RCPP
#if LINUX_CLUSTER || RS_RCPP
// Check whether a specified directory path exists
bool is_directory(const char* pathname) {
struct stat info;
Expand Down Expand Up @@ -1466,22 +1466,40 @@ void OutParameters(Landscape* pLandscape)

if (trfr.usesMovtProc) {
string plusmating = "+ mating requirements";
ssteps = pSpecies->getSteps(0, 0);

outPar << "MIN. No. OF STEPS:\t " << ssteps.minSteps << endl;
outPar << "MAX. No. OF STEPS:\t ";
if (ssteps.maxSteps == 99999999) outPar << "not applied" << endl;
else outPar << ssteps.maxSteps << endl;
if (sett.sexDep) {
nsexes = 2;
outPar << sexdept << "yes" << endl;
if (sett.stgDep) {
nstages = sstruct.nStages;
outPar << stgdept << "yes" << endl;
for (int i = 0; i < nstages; i++) {
if (dem.stageStruct && nstages > 1) outPar << "stage " << i << ": " << endl;
for (int sx = 0; sx < nsexes; sx++) {
if (sx == 0) outPar << "FEMALES:" << endl;
else outPar << "MALES:" << endl;
ssteps = pSpecies->getSteps(i, sx);

outPar << "MIN. No. OF STEPS:\t " << ssteps.minSteps << endl;
outPar << "MAX. No. OF STEPS:\t ";
if (ssteps.maxSteps == 99999999) outPar << "not applied" << endl;
else outPar << ssteps.maxSteps << endl;
}
}
}
else { // !sett.stgDep
nstages = 1;
outPar << stgdept << "no" << endl;
for (int sx = 0; sx < nsexes; sx++) {
if (sx == 0) outPar << "FEMALES:" << endl;
else outPar << "MALES:" << endl;
ssteps = pSpecies->getSteps(0, sx);

outPar << "MIN. No. OF STEPS:\t " << ssteps.minSteps << endl;
outPar << "MAX. No. OF STEPS:\t ";
if (ssteps.maxSteps == 99999999) outPar << "not applied" << endl;
else outPar << ssteps.maxSteps << endl;
}
}
}
else { // !sett.sexDep
Expand All @@ -1490,10 +1508,25 @@ void OutParameters(Landscape* pLandscape)
if (sett.stgDep) {
nstages = sstruct.nStages;
outPar << stgdept << "yes" << endl;
for (int i = 0; i < nstages; i++) {
if (dem.stageStruct && nstages > 1) outPar << "stage " << i << ": " << endl;
ssteps = pSpecies->getSteps(i, 0);

outPar << "MIN. No. OF STEPS:\t " << ssteps.minSteps << endl;
outPar << "MAX. No. OF STEPS:\t ";
if (ssteps.maxSteps == 99999999) outPar << "not applied" << endl;
else outPar << ssteps.maxSteps << endl;
}
}
else { // !sett.stgDep
nstages = 1;
outPar << stgdept << "no" << endl;
ssteps = pSpecies->getSteps(0, 0);

outPar << "MIN. No. OF STEPS:\t " << ssteps.minSteps << endl;
outPar << "MAX. No. OF STEPS:\t ";
if (ssteps.maxSteps == 99999999) outPar << "not applied" << endl;
else outPar << ssteps.maxSteps << endl;
}
}
for (int sx = 0; sx < nsexes; sx++) {
Expand Down
8 changes: 4 additions & 4 deletions RSrandom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

//--------------- 2.) New version of RSrandom.cpp

#if !RS_RCPP
#if !RS_RCPP

#if RSDEBUG
#include "Parameters.h"
Expand Down Expand Up @@ -132,7 +132,7 @@ void RSrandom::fixNewSeed(int seed) {
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

#else // if RS_RCPP
#else // if RS_RCPP

//--------------- 3.) R package version of RSrandom.cpp

Expand Down Expand Up @@ -305,11 +305,11 @@ double RSrandom::Cauchy(double loc, double scale) {
#endif // RS_RCPP


#if RSDEBUG
#if RSDEBUG && !RS_RCPP
void testRSrandom() {

{
// Bernoulli distribution
// Bernoulli distribution
// Abuse cases
assert_error("Bernoulli's p cannot be negative.\n", []{
RSrandom rsr;
Expand Down
27 changes: 15 additions & 12 deletions Species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ Species::Species(void)
fullKernel = false;
// initialise settlement parameters
stgDepSett = false; sexDepSett = false; indVarSett = false;
minSteps = 0; maxSteps = 99999999;
for (int i = 0; i < maxNbStages; i++) {
for (int j = 0; j < maxNbSexes; j++) {
densDepSett[i][j] = false; wait[i][j] = false; go2nbrLocn[i][j] = false; findMate[i][j] = false;
maxStepsYr[i][j] = 99999999;
maxStepsYr[i][j] = 99999999; minSteps[i][j] = 0; maxSteps[i][j] = 99999999;
s0[i][j] = 1.0; alphaS[i][j] = 0.0; betaS[i][j] = 1.0;
}
}
Expand Down Expand Up @@ -720,24 +719,28 @@ settleRules Species::getSettRules(short stg, short sex) {
}

void Species::setSteps(const short stg, const short sex, const settleSteps s) {
if (stg == 0 && sex == 0) {
if (s.minSteps >= 0) minSteps = s.minSteps;
else minSteps = 0;
if (s.maxSteps >= 1) maxSteps = s.maxSteps;
else maxSteps = 99999999;
}
if (stg >= 0 && stg < maxNbStages && sex >= 0 && sex < maxNbSexes) {
if (s.maxStepsYr >= 1) maxStepsYr[stg][sex] = s.maxStepsYr;
else maxStepsYr[stg][sex] = 99999999;
if (s.minSteps >= 0) minSteps[stg][sex] = s.minSteps;
else minSteps[stg][sex] = 0;
if (s.maxSteps >= 1) maxSteps[stg][sex] = s.maxSteps;
else maxSteps[stg][sex] = 99999999;
}
}

settleSteps Species::getSteps(short stg, short sex) {
settleSteps s;
s.minSteps = minSteps;
s.maxSteps = maxSteps;
if (stg >= 0 && stg < maxNbStages && sex >= 0 && sex < maxNbSexes) s.maxStepsYr = maxStepsYr[stg][sex];
else s.maxStepsYr = 99999999;
if (stg >= 0 && stg < maxNbStages && sex >= 0 && sex < maxNbSexes) {
s.maxStepsYr = maxStepsYr[stg][sex];
s.minSteps = minSteps[stg][sex];
s.maxSteps = maxSteps[stg][sex];
}
else {
s.maxStepsYr = 99999999;
s.minSteps = 0;
s.maxSteps = 99999999;
}
return s;
}

Expand Down
4 changes: 2 additions & 2 deletions Species.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ class Species {
bool wait[maxNbStages][maxNbSexes]; // wait to continue moving next season (stage-structured model only)
bool go2nbrLocn[maxNbStages][maxNbSexes]; // settle in neighbouring cell/patch if available (ditto)
bool findMate[maxNbStages][maxNbSexes];
int minSteps; // minimum no. of steps
int maxSteps; // maximum total no. of steps
int minSteps[maxNbStages][maxNbSexes]; // minimum no. of steps
int maxSteps[maxNbStages][maxNbSexes]; // maximum total no. of steps
int maxStepsYr[maxNbStages][maxNbSexes]; // maximum no. of steps in any one dispersal period
float s0[maxNbStages][maxNbSexes]; // maximum settlement probability
float alphaS[maxNbStages][maxNbSexes]; // slope of the settlement reaction norm to density
Expand Down

0 comments on commit 43c3046

Please sign in to comment.