Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPannetier committed May 22, 2024
2 parents dc6e9a5 + ca57ce8 commit 7aefe7a
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 52 deletions.
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Anyone who whishes to make changes to RangeShifter's code, including regular dev

![](branches.png)

*Check out the [Git cheatsheet](https://github.com/RangeShifter/RScore/blob/development-guidelines/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*

This policy applies to RScore and all three RangeShifter interfaces.
RangeShifter uses the following branching structure:
Expand All @@ -59,12 +59,12 @@ In the meantime, we encourage contributors to work in small and frequent commits

### Contributing to RangeShifter core code

Any changes regarding the RangeShifter core code should be done in this repository and can afterwards be synced with all interfaces using the git subtree feature (see [Git subtree](https://github.com/RangeShifter/RScore/tree/development-guidelines#usage-git-subtrees) section in the README).
Any changes regarding the RangeShifter core code should be done in this repository and can afterwards be synced with all interfaces using the git subtree feature (see [Git subtree](https://github.com/RangeShifter/RScore/tree/main?tab=readme-ov-file#usage-git-subtree) section in the README).

#### Bugs

To report a bug, please [open an issue](https://github.com/RangeShifter/RangeShiftR-package-dev/issues/new), using the Bug Report template.
Please do check if a related issue has already open on one of the other interfaces ([here](https://github.com/RangeShifter/RangeShifter_batch/issues) for the batch interface or [here](https://github.com/RangeShifter/RangeShiftR-package-dev) for the R package interface).
Please do check if a related issue has already open on one of the other interfaces ([here](https://github.com/RangeShifter/RangeShifter_batch-dev/issues) for the batch interface or [here](https://github.com/RangeShifter/RangeShiftR-package-dev) for the R package interface).
To propose a bug fix (thank you!!), please create and work on your own branch or fork, from either `main` or `develop` (preferred), and open a pull request when your fix is ready to be merged into the original branch.

Maintainers will review the pull request, possibly request changes, and eventually integrate the bug fix into RScore, and update the subtrees to bring the fix to all interfaces.
Expand Down
37 changes: 26 additions & 11 deletions Landscape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,9 @@ int Landscape::readLandChange(int filenum, bool costs)
}
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();
Expand All @@ -1294,8 +1297,8 @@ int Landscape::readLandChange(int filenum, bool costs)
}
}
}
}
}
} // for x
} // for y
#if RS_RCPP
hfile >> hfloat;
if (!hfile.eof()) EOFerrorR("habitatchgfile");
Expand Down Expand Up @@ -1421,6 +1424,9 @@ int Landscape::readLandChange(int filenum, bool costs)
}
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();
Expand All @@ -1432,8 +1438,8 @@ int Landscape::readLandChange(int filenum, bool costs)
}
}
}
}
}
} // end x
} // end y
#if RS_RCPP
hfile >> hfloat;
if (!hfile.eof()) EOFerrorR("habitatchgfile");
Expand Down Expand Up @@ -1658,7 +1664,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 ...
// ... FOR MULTIPLE SPECIES IT MAY BE BETTER TO USE A DYNAMIC ARRAY FOR
// ... FOR MULTIPLE SPECIES IT MAY BE BETTER TO USE A DYNAMIC ARRAY FOR
// SPECIES DISTRIBUTIONS INDEXED BY SPECIES NUMBER, RATHER THAN A VECTOR
if (distns[0] != 0) delete distns[0]; distns.clear();
}
Expand Down Expand Up @@ -1938,7 +1944,7 @@ int Landscape::readLandscape(int fileNum, string habfile, string pchfile, string
if (existsPatch(p)) {
pPatch = findPatch(p);
addNewCellToPatch(pPatch, x, y, h);
// addNewCellToPatch(findPatch(p),x,y,h);
// addNewCellToPatch(findPatch(p),x,y,h);
}
else {
pPatch = newPatch(seq++, p);
Expand Down Expand Up @@ -2288,7 +2294,7 @@ int Landscape::readCosts(string fname)
costs.close(); costs.clear();
return -1;
}
double tmpresolCost;
double tmpresolCost;
costs >> maxXcost >> header >> maxYcost >> header >> minLongCost;
costs >> header >> minLatCost >> header >> tmpresolCost >> header >> NODATACost;
resolCost = (int) tmpresolCost;
Expand Down Expand Up @@ -2316,17 +2322,26 @@ resolCost = (int) tmpresolCost;
#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;
}
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 habiat cells, but found " << hc << " in cell x: " << x << " y: " << y << "." << endl;
#endif
// costs.close(); costs.clear(); // not sure if it should stop at this point
// return -999;
}

} // end not no data vell
}
}
#if RS_RCPP
Expand Down
9 changes: 8 additions & 1 deletion Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ int _tmain(int argc, _TCHAR* argv[])
return 1;
# else
assert(0.1 > 0.0); // assert does run correctly
run_unit_tests();
try
{
run_unit_tests();
}
catch (const std::exception& e)
{
cerr << endl << "Error: " << e.what() << endl;
}
cout << "All tests have completed." << endl;
return 0; // if tests succeed, we are happy
# endif // NDEBUG
Expand Down
46 changes: 39 additions & 7 deletions Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ int RunModel(Landscape* pLandscape, int seqsim)

}

#if 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 @@ -1645,23 +1645,40 @@ void OutParameters(Landscape* pLandscape)

if (trfr.moveModel) {
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 @@ -1670,10 +1687,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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This repo contains the core simulation code for RangeShifter v2.0 and is not meant to be compiled or run on its own.

<img src="https://github.com/RangeShifter/RScore/blob/development-guidelines/RScore_logo.png" align="right" height = 200/>
<img src="https://github.com/RangeShifter/RScore/blob/main/RScore_logo.png" align="right" height = 200/>

If you are only interested in using RangeShifter, you can ignore this and head to the repo of one of the interfaces:

Expand Down Expand Up @@ -46,11 +46,15 @@ git subtree pull --prefix RangeShiftR/src/RScore RScore main

### Pushing new changes to RScore

We haven't yet found a way to push new changes made in a RScore subfolder back into the RScore repo. This is why we ask that contributions are made directly inside the RScore repo.
```bash
git subtree push --prefix <path_to_RScore_subfolder> RScore <branch>
```

If you know how to do this, please drop us a line!
e.g., from RangeShifter-batch's `main` to RScore's `main`:

Alternatively, if you have already made changes on the subfolder, you could copy its contents into a new branch in RScore, then open a pull request.
```bash
git subtree push --prefix src/RScore RScore main
```

### Switching the subfolder to a new branch

Expand Down
24 changes: 12 additions & 12 deletions RSrandom.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/*----------------------------------------------------------------------------
*
* Copyright (C) 2020 Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Anne-Kathleen Malchow, Damaris Zurell
*
*
* Copyright (C) 2020 Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Anne-Kathleen Malchow, Damaris Zurell
*
* This file is part of RangeShifter.
*
*
* RangeShifter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* RangeShifter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with RangeShifter. If not, see <https://www.gnu.org/licenses/>.
*
*
--------------------------------------------------------------------------*/


#include "RSrandom.h"

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

#if !RS_RCPP
#if !RS_RCPP

#if RSDEBUG
#include "Parameters.h"
Expand Down Expand Up @@ -113,7 +113,7 @@ int RSrandom::Poisson(double mean)
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------

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

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

Expand Down Expand Up @@ -257,11 +257,11 @@ int RSrandom::Poisson(double mean)
#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
28 changes: 16 additions & 12 deletions Species.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ Species::Species(void)

// initialise settlement parameters
stgDepSett = false; sexDepSett = false; indVarSett = false;
minSteps = 0; maxSteps = 99999999;

for (int i = 0; i < NSTAGES; i++) {
for (int j = 0; j < NSEXES; 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 @@ -1262,24 +1262,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 < NSTAGES && sex >= 0 && sex < NSEXES) {
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 < NSTAGES && sex >= 0 && sex < NSEXES) s.maxStepsYr = maxStepsYr[stg][sex];
else s.maxStepsYr = 99999999;
if (stg >= 0 && stg < NSTAGES && sex >= 0 && sex < NSEXES) {
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 @@ -701,8 +701,8 @@ class Species {
bool wait[NSTAGES][NSEXES]; // wait to continue moving next season (stage-structured model only)
bool go2nbrLocn[NSTAGES][NSEXES]; // settle in neighbouring cell/patch if available (ditto)
bool findMate[NSTAGES][NSEXES];
int minSteps; // minimum no. of steps
int maxSteps; // maximum total no. of steps
int minSteps[NSTAGES][NSEXES]; // minimum no. of steps
int maxSteps[NSTAGES][NSEXES]; // maximum total no. of steps
int maxStepsYr[NSTAGES][NSEXES]; // maximum no. of steps in any one dispersal period
float s0[NSTAGES][NSEXES]; // maximum settlement probability
float alphaS[NSTAGES][NSEXES]; // slope of the settlement reaction norm to density
Expand Down

0 comments on commit 7aefe7a

Please sign in to comment.