Skip to content

Commit

Permalink
Add 'src/RScore/' from commit '3764f7aaaaf9a6624af0037511077a42bbb6ad4e'
Browse files Browse the repository at this point in the history
git-subtree-dir: src/RScore
git-subtree-mainline: d8d1f6d
git-subtree-split: 3764f7a
  • Loading branch information
TheoPannetier committed Nov 9, 2023
2 parents d8d1f6d + 3764f7a commit f2d0fee
Show file tree
Hide file tree
Showing 32 changed files with 21,290 additions and 0 deletions.
87 changes: 87 additions & 0 deletions src/RScore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
.gitignore
#README.md

# CodeLite
/.build-debug/
/Debug/
/Release/
/RNG_test/
.codelite/
compile_commands.json
Makefile
.build-release/
build-Release/
*.project
*.workspace
*.mk
*.tags

# Hidden source
/RangeShiftR/src/.*

# Windows files
/RangeShiftR/src/*.dll

# History files
.Rhistory
.Rapp.history

# RStudio files
.Rproj.user/
/RangeShiftR/.Rproj.user/
#/RangeShiftR/RangeShiftR.Rproj
/RangeShiftR/Read-and-delete-me
/RangeShiftR/.Rhistory
#/RangeShiftR/.Rbuildignore

# Session Data files
.RData
tags

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
*.tar.gz
/RangeShiftR/src/*.o
/RangeShiftR/src/RangeShiftR.so


# Windows files
/RangeShiftR/src/*.dll

# Output files from R CMD check
/*.Rcheck/

# Output from Rcpp compile.attributes()
#/RangeShiftR/R/RcppExports.R
#/RangeShiftR/src/RcppExports.cpp

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf
#/RangeShiftR/man/

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
/*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# compilation files
*.o

# Visual Studio
.vs/
out/
11 changes: 11 additions & 0 deletions src/RScore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Config file for compilation with CMake
# Only relevant for Batch mode, but this file needs to live in the RScore folder

add_library(RScore Species.cpp Cell.cpp Community.cpp FractalGenerator.cpp Genome.cpp Individual.cpp Landscape.cpp Model.cpp Parameters.cpp Patch.cpp Population.cpp RandomCheck.cpp RSrandom.cpp SubCommunity.cpp)

# pass config definitions to compiler
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(RScore PRIVATE "RSDEBUG" "RSWIN64" "LINUX_CLUSTER")
else() # Windows
target_compile_definitions(RScore PRIVATE "RSDEBUG" "RSWIN64")
endif()
237 changes: 237 additions & 0 deletions src/RScore/Cell.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/*----------------------------------------------------------------------------
*
* 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 "Cell.h"

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

// Cell functions

Cell::Cell(int xx,int yy,intptr patch,int hab)
{
x = xx; y = yy;
pPatch = patch;
envVal = 1.0; // default - no effect of any gradient
envDev = eps = 0.0;
habIxx.push_back(hab);
#if RSDEBUG
//DebugGUI(("Cell::Cell(): this=" + Int2Str((int)this)
// + " x=" + Int2Str(x) + " y=" + Int2Str(y)
// + " habIndex=" + Int2Str(habIndex)
//).c_str());
#endif
visits = 0;
smsData = 0;
}

Cell::Cell(int xx,int yy,intptr patch,float hab)
{
x = xx; y = yy;
pPatch = patch;
envVal = 1.0; // default - no effect of any gradient
envDev = eps = 0.0;
habitats.push_back(hab);
visits = 0;
smsData = 0;
}

Cell::~Cell() {
#if RSDEBUG
//DEBUGLOG << "Cell::~Cell(): this = " << this << " smsData = " << smsData << endl;
#endif
habIxx.clear();
habitats.clear();
if (smsData != 0) {
if (smsData->effcosts != 0) delete smsData->effcosts;
delete smsData;
}
#if RSDEBUG
//DEBUGLOG << "Cell::~Cell(): deleted" << endl;
#endif
}

void Cell::setHabIndex(short hx) {
#if RSDEBUG
//DebugGUI(("Cell::setHabIndex(): this=" + Int2Str((int)this)
// + " x=" + Int2Str(x) + " y=" + Int2Str(y)
// + " habIx=" + Int2Str(habIx)
//).c_str());
#endif
if (hx < 0) habIxx.push_back(0);
else habIxx.push_back(hx);
}

void Cell::changeHabIndex(short ix,short hx) {
if (ix >= 0 && ix < (short)habIxx.size() && hx >= 0) habIxx[ix] = hx;
else habIxx[ix] = 0;
}

int Cell::getHabIndex(int ix) {
if (ix < 0 || ix >= (int)habIxx.size())
// nodata cell OR should not occur, but treat as such
return -1;
else return habIxx[ix];
}
int Cell::nHabitats(void) {
int nh = (int)habIxx.size();
if ((int)habitats.size() > nh) nh = (int)habitats.size();
return nh;
}

void Cell::setHabitat(float q) {
if (q >= 0.0 && q <= 100.0) habitats.push_back(q);
else habitats.push_back(0.0);
}

float Cell::getHabitat(int ix) {
if (ix < 0 || ix >= (int)habitats.size())
// nodata cell OR should not occur, but treat as such
return -1.0;
else return habitats[ix];
}

void Cell::setPatch(intptr p) {
pPatch = p;
}
intptr Cell::getPatch(void)
{
#if RSDEBUG
//DebugGUI(("Cell::getPatch(): this=" + Int2Str((int)this)
// + " x=" + Int2Str(x) + " y=" + Int2Str(y)
// + " habIxx[0]=" + Int2Str(habIxx[0]) + " pPatch=" + Int2Str(pPatch)
//).c_str());
#endif
return pPatch;
}

locn Cell::getLocn(void) { locn q; q.x = x; q.y = y; return q; }

void Cell::setEnvDev(float d) { envDev = d; }

float Cell::getEnvDev(void) { return envDev; }

void Cell::setEnvVal(float e) {
if (e >= 0.0) envVal = e;
}

float Cell::getEnvVal(void) { return envVal; }

void Cell::updateEps(float ac,float randpart) {
eps = eps*ac + randpart;
}

float Cell::getEps(void) { return eps; }

// Functions to handle costs for SMS

int Cell::getCost(void) {
int c;
if (smsData == 0) c = 0; // costs not yet set up
else c = smsData->cost;
return c;
}

void Cell::setCost(int c) {
if (smsData == 0) {
smsData = new smscosts;
smsData->effcosts = 0;
}
smsData->cost = c;
}

// Reset the cost and the effective cost of the cell
void Cell::resetCost(void) {
if (smsData != 0) { resetEffCosts(); delete smsData; }
smsData = 0;
}

array3x3f Cell::getEffCosts(void) {
array3x3f a;
if (smsData == 0 || smsData->effcosts == 0) { // effective costs have not been calculated
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
a.cell[i][j] = -1.0;
}
}
}
else
a = *smsData->effcosts;
return a;
}

void Cell::setEffCosts(array3x3f a) {
if (smsData->effcosts == 0) smsData->effcosts = new array3x3f;
*smsData->effcosts = a;
}

// Reset the effective cost, but not the cost, of the cell
void Cell::resetEffCosts(void) {
if (smsData != 0) {
if (smsData->effcosts != 0) {
delete smsData->effcosts;
smsData->effcosts = 0;
}
}
}

void Cell::resetVisits(void) { visits = 0; }
void Cell::incrVisits(void) { visits++; }
unsigned long int Cell::getVisits(void) { return visits; }

//---------------------------------------------------------------------------

// Initial species distribution cell functions

DistCell::DistCell(int xx,int yy) {
x = xx; y = yy; initialise = false;
}

DistCell::~DistCell() {

}

void DistCell::setCell(bool init) {
initialise = init;
}

bool DistCell::toInitialise(locn loc) {
if (loc.x == x && loc.y == y) return initialise;
else return false;
}

bool DistCell::selected(void) { return initialise; }

locn DistCell::getLocn(void) {
locn loc; loc.x = x; loc.y = y; return loc;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------




Loading

0 comments on commit f2d0fee

Please sign in to comment.