diff --git a/RangeShiftR/DESCRIPTION b/RangeShiftR/DESCRIPTION
index 8f93e06..ba007f0 100644
--- a/RangeShiftR/DESCRIPTION
+++ b/RangeShiftR/DESCRIPTION
@@ -19,6 +19,8 @@ Imports:
Rcpp (>= 1.0.0),
Rdpack (>= 0.7),
methods,
+ raster
+Suggests:
rmarkdown,
terra
RdMacros: Rdpack
diff --git a/RangeShiftR/NAMESPACE b/RangeShiftR/NAMESPACE
index e294623..87853d6 100644
--- a/RangeShiftR/NAMESPACE
+++ b/RangeShiftR/NAMESPACE
@@ -28,4 +28,5 @@ export(readRange)
export(validateRSparams)
importFrom(Rcpp,sourceCpp)
importFrom(Rdpack,reprompt)
+importFrom(methods,new)
useDynLib(RangeShiftR)
diff --git a/RangeShiftR/R/RSsim.R b/RangeShiftR/R/RSsim.R
index aa459fb..f38df8d 100644
--- a/RangeShiftR/R/RSsim.R
+++ b/RangeShiftR/R/RSsim.R
@@ -130,6 +130,6 @@ RSsim <- function(batchnum = 1L,
if (!is.null(args$gene)) s <- s + gene
if (!is.null(args$init)) s <- s + init
# check validity
- if(validObject(s)) return(s)
+ if(methods::validObject(s)) return(s)
else return(NULL)
}
diff --git a/RangeShiftR/R/RangeShiftR.R b/RangeShiftR/R/RangeShiftR.R
index 9423a1c..a919319 100644
--- a/RangeShiftR/R/RangeShiftR.R
+++ b/RangeShiftR/R/RangeShiftR.R
@@ -92,5 +92,5 @@ RangeShiftR_license <- function ()
#' @export
RangeShiftR_citation <- function ()
{
- citation(package = "RangeShiftR", lib.loc = NULL, auto = NULL)
+ utils::citation(package = "RangeShiftR", lib.loc = NULL, auto = NULL)
}
diff --git a/RangeShiftR/R/Rfunctions.R b/RangeShiftR/R/Rfunctions.R
index e8d3e73..c28618c 100644
--- a/RangeShiftR/R/Rfunctions.R
+++ b/RangeShiftR/R/Rfunctions.R
@@ -32,13 +32,13 @@
#----------------------
#for Integer and Numerical so that 'Integer'-slots can also accept 'Numerical' input
-setClassUnion("integer_OR_numeric", c("integer", "numeric"))
+methods::setClassUnion("integer_OR_numeric", c("integer", "numeric"))
#for Matrix and Numerical so that 'Matrix'-slots can also accept 'Numerical' input when 1x1-Matrix is expected
-setClassUnion("matrix_OR_numeric", c("matrix", "numeric"))
+methods::setClassUnion("matrix_OR_numeric", c("matrix", "numeric"))
#for cost layer to accept habitat codes or raster map file
-setClassUnion("numeric_OR_character", c("numeric", "character"))
+methods::setClassUnion("numeric_OR_character", c("numeric", "character"))
#-- define error and warning messages
@@ -59,4 +59,4 @@ densdep <- function(x, A0 = 1.0, alpha = 1.0, beta = 0.0) {
#' Validate a given RS parameter object
#'
#' @export
-validateRSparams <- function(x){validObject(x)}
+validateRSparams <- function(x){methods::validObject(x)}
diff --git a/RangeShiftR/R/RunRS.R b/RangeShiftR/R/RunRS.R
index e8f031d..6a469d6 100644
--- a/RangeShiftR/R/RunRS.R
+++ b/RangeShiftR/R/RunRS.R
@@ -43,7 +43,7 @@ RunRS <- function(RSparams, dirpath = getwd()){
stop("Parameter object must be of class RSparams")
}
else {
- validObject(RSparams)
+ methods::validObject(RSparams)
}
}
if (is.null(dirpath)) {
diff --git a/RangeShiftR/R/addition.R b/RangeShiftR/R/addition.R
index 84678de..bbf3729 100644
--- a/RangeShiftR/R/addition.R
+++ b/RangeShiftR/R/addition.R
@@ -31,13 +31,13 @@
setGeneric("+")
setMethod("+", signature(e1 = "RSparams", e2 = "SimulationParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@simul <- e2
return(e1)}
)
setMethod("+", signature(e1 = "RSparams", e2 = "LandParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
if (class(e2)[1] == "ImportedLandscape") {
if (any(e2@PatchFile=="NULL")) {
e1@control@patchmodel = FALSE
@@ -76,7 +76,7 @@ setMethod("+", signature(e1 = "RSparams", e2 = "LandParams"), function(e1, e2) {
)
setMethod("+", signature(e1 = "RSparams", e2 = "DemogParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@control@reproductn = e2@ReproductionType
if (class(e2@StageStruct)[1] == "StagesParams") {
e1@control@repseasons = e2@StageStruct@RepSeasons
@@ -101,7 +101,7 @@ setMethod("+", signature(e1 = "RSparams", e2 = "DemogParams"), function(e1, e2)
)
setMethod("+", signature(e1 = "DemogParams", e2 = "StagesParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@StageStruct <- e2
e1@Rmax <- -9L
e1@bc <- -9L
@@ -109,7 +109,7 @@ setMethod("+", signature(e1 = "DemogParams", e2 = "StagesParams"), function(e1,
)
setMethod("+", signature(e1 = "RSparams", e2 = "DispersalParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
if (class(e2@Transfer)[1] == "DispersalKernel") {
e1@control@transfer = 0
}
@@ -131,34 +131,34 @@ setMethod("+", signature(e1 = "RSparams", e2 = "DispersalParams"), function(e1,
)
setMethod("+", signature(e1 = "DispersalParams", e2 = "EmigrationParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@Emigration <- e2
- validObject(e1)
+ methods::validObject(e1)
return(e1)}
)
setMethod("+", signature(e1 = "DispersalParams", e2 = "TransferParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@Transfer <- e2
- validObject(e1)
+ methods::validObject(e1)
return(e1)}
)
setMethod("+", signature(e1 = "DispersalParams", e2 = "SettlementParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@Settlement <- e2
- validObject(e1)
+ methods::validObject(e1)
return(e1)}
)
setMethod("+", signature(e1 = "RSparams", e2 = "GeneticsParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@gene <- e2
return(e1)}
)
setMethod("+", signature(e1 = "RSparams", e2 = "InitialisationParams"), function(e1, e2) {
- validObject(e2)
+ methods::validObject(e2)
e1@init <- e2
return(e1)}
)
diff --git a/RangeShiftR/R/class_ControlParams.R b/RangeShiftR/R/class_ControlParams.R
index 423dcc9..9b36145 100644
--- a/RangeShiftR/R/class_ControlParams.R
+++ b/RangeShiftR/R/class_ControlParams.R
@@ -25,7 +25,7 @@
# from RS 'CONTROL.txt' file
-ControlParams <- setClass("ControlParams", slots = c(
+ControlParams <- methods::setClass("ControlParams", slots = c(
#nSimuls = "integer_OR_numeric", # Not yet used by R version, in C++ version its read from parameterfile
#nLandscapes = "integer_OR_numeric", # Not yet used by R version, in C++ version its read from landfile
batchnum = "integer_OR_numeric", # only variable to set from RSsim(), optional
diff --git a/RangeShiftR/R/class_DemogParams.R b/RangeShiftR/R/class_DemogParams.R
index 82f1e5c..2c71aed 100644
--- a/RangeShiftR/R/class_DemogParams.R
+++ b/RangeShiftR/R/class_DemogParams.R
@@ -57,39 +57,39 @@
#' demographic parameters. Individuals are characterized by their age and stage. Each stage has a certain fecundity, survival probability and probability of developing to the next stage.
#'
#' These parameters are provided through classical transition matrices \insertCite{caswell2001}{RangeShiftR}.
-#' \ifelse{html}{\out{φi}}{\eqn{φ_i}} is the fecundity of stage \eqn{i} ;
-#' \ifelse{html}{\out{σi}}{\eqn{σ_i}} is the survival probability of an individual in stage \eqn{i} ;
-#' and \ifelse{html}{\out{γi-j}}{\eqn{γ_(i-j)}} is the probability of developing from stage \eqn{i} to stage \eqn{j}.
+#' \ifelse{html}{\out{φi}}{\eqn{\phi_i}} is the fecundity of stage \eqn{i} ;
+#' \ifelse{html}{\out{σi}}{\eqn{\sigma_i}} is the survival probability of an individual in stage \eqn{i} ;
+#' and \ifelse{html}{\out{γi-j}}{\eqn{\gamma_(i-j)}} is the probability of developing from stage \eqn{i} to stage \eqn{j}.
#' In this way, the transition matrix describes the effect of each individuals current stage (column) on all stages at the next timestep (rows).
#' Since all offspring is born into the juvenile stage (stage 0), all fecundities are always located in the first row of the matrix.
#'
#' However, in \emph{RangeShiftR}, these parameters are not used deterministically as \emph{rates} (like it is typical for matrix models) but, instead, as \emph{probabilities} which are
-#' applied stochastically at the individual level. Hence, each female at stage \eqn{i}, if it reproduces, produces a number of offspring given by \eqn{Poisson}(\ifelse{html}{\out{φi}}{\eqn{φ_i}}),
-#' while Bernoulli trials \eqn{Bern}(\ifelse{html}{\out{σi}}{\eqn{σ_i}}) and \eqn{Bern}(\ifelse{html}{\out{γi,i+1}}{\eqn{γ_(i,i+1)}}) determine if an individual/female survives or not
+#' applied stochastically at the individual level. Hence, each female at stage \eqn{i}, if it reproduces, produces a number of offspring given by \eqn{Poisson}(\ifelse{html}{\out{φi}}{\eqn{\phi_i}}),
+#' while Bernoulli trials \eqn{Bern}(\ifelse{html}{\out{σi}}{\eqn{\sigma_i}}) and \eqn{Bern}(\ifelse{html}{\out{γi,i+1}}{\eqn{\gamma_(i,i+1)}}) determine if an individual/female survives or not
#' and - if it survives - if it develops to the next stage or not.
#'
#' An example transition matrix for a 3-staged only-female or simple sexual (\code{ReproductionType={0,1}}) population model:
-#' \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{φ_2}} \cr
-#' \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{σ_1 (1 − γ_(1-2))}} \tab | \tab \eqn{0} \cr
-#' \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{σ_1 γ_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{σ_2}} \cr}
+#' \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{\phi_2}} \cr
+#' \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{\sigma_1 (1 - \gamma_(1-2))}} \tab | \tab \eqn{0} \cr
+#' \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{\sigma_1 \gamma_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{\sigma_2}} \cr}
#'
-#' In a female-only model (\code{ReproductionType=0}), \ifelse{html}{\out{φ}}{\eqn{φ}} represents the number of female offspring per female and reproductive event. \cr
+#' In a female-only model (\code{ReproductionType=0}), \ifelse{html}{\out{φ}}{\eqn{\phi}} represents the number of female offspring per female and reproductive event. \cr
#' Note that for an implicit (simple) sexual model (\code{ReproductionType=1}), the demographic parameters are not sex-specific. However, individuals are defined by their sex, which is acknowledged for example in the dispersal
-#' process and transmission of alleles. The fecundities \ifelse{html}{\out{φ}}{\eqn{φ}} refer to the number of all offspring (males and females) per female and reproductive event.
+#' process and transmission of alleles. The fecundities \ifelse{html}{\out{φ}}{\eqn{\phi}} refer to the number of all offspring (males and females) per female and reproductive event.
#'
#' In case of an explicit (complex) sexual model (\code{ReproductionType=2}), in contrast, each stage must be represented by two columns and rows to distinguish male and female demographic parameters.
-#' Note, however, that in any case the juvenile stage has only one row; it contains the fecundities. Male fecundities should have one of two possible values: set \ifelse{html}{\out{φm}}{\eqn{φ_m}} \eqn{=1.0} for reproductive males or \ifelse{html}{\out{φm}}{\eqn{φ_m}} \eqn{=0.0} for non-reproductive males.\cr
+#' Note, however, that in any case the juvenile stage has only one row; it contains the fecundities. Male fecundities should have one of two possible values: set \ifelse{html}{\out{φm}}{\eqn{\phi_m}} \eqn{=1.0} for reproductive males or \ifelse{html}{\out{φm}}{\eqn{\phi_m}} \eqn{=0.0} for non-reproductive males.\cr
#' An example transition matrix for a 3-staged explicit sexual population model \insertCite{weeks1986,lindstrom1998}{RangeShiftR}:
-#' \tabular{ccccccccccc}{\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{φ1m}}{\eqn{φ_1m}} \tab | \tab \ifelse{html}{\out{φ1f}}{\eqn{φ_1f}} \tab | \tab \ifelse{html}{\out{φ2m}}{\eqn{φ_2m}} \tab | \tab \ifelse{html}{\out{φ2f}}{\eqn{φ_2f}} \cr
-#' \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m (1-γ1-2,m)}}{\eqn{σ_1m (1 − γ_(1-2,m))}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
-#' \eqn{0} \tab | \tab \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{σ_1f γ_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
-#' \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m γ1-2,m}}{\eqn{σ_1m γ_(1-2,m)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2m}}{\eqn{σ_2m}} \tab | \tab \eqn{0} \cr
-#' \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{σ_1f γ_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2f}}{\eqn{σ_2f}} \cr}#' The mating system is explicitly modelled and a female’s probability of reproducing is determined as described in \code{\link[RangeShiftR]{Demography}} \insertCite{weeks1986,caswell2001}{RangeShiftR}.
+#' \tabular{ccccccccccc}{\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{φ1m}}{\eqn{\phi_1m}} \tab | \tab \ifelse{html}{\out{φ1f}}{\eqn{\phi_1f}} \tab | \tab \ifelse{html}{\out{φ2m}}{\eqn{\phi_2m}} \tab | \tab \ifelse{html}{\out{φ2f}}{\eqn{\phi_2f}} \cr
+#' \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m (1-γ1-2,m)}}{\eqn{\sigma_1m (1 - \gamma_(1-2,m))}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
+#' \eqn{0} \tab | \tab \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{\sigma_1f \gamma_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
+#' \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m γ1-2,m}}{\eqn{\sigma_1m \gamma_(1-2,m)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2m}}{\eqn{\sigma_2m}} \tab | \tab \eqn{0} \cr
+#' \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{\sigma_1f \gamma_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2f}}{\eqn{\sigma_2f}} \cr}#' The mating system is explicitly modelled and a female’s probability of reproducing is determined as described in \code{\link[RangeShiftR]{Demography}} \insertCite{weeks1986,caswell2001}{RangeShiftR}.
#'
#' A common mistake in building a transition matrix is made when offspring produced at year \eqn{t} develop to the next stage in the same year \insertCite{@ @caswell2001 pg. 60-62}{RangeShiftR}. To avoid this problem without losing the offspring stage, and hence the chance for simulating post-natal dispersal,
#' we require an additional explicit juvenile stage (stage 0). Juveniles have to develop to stage 1 in the same year they are born. Hence the minimum number of stages of a stage-structured model is always \eqn{2}. It is important to note that juvenile mortality can be accounted for in
-#' two ways. Either, as in the examples above, it is included in adult fecundity \ifelse{html}{\out{φ}}{\eqn{φ}} (by appropriately reducing its value), and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{σ_0 γ_(0-1)}} is equal to \eqn{1.0}. This is how it is typically accounted for in matrix models. Or, alternatively,
-#' φ is equal to the true maximum fecundity and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{σ_0 γ_(0-1)}} is less than \eqn{1.0}.
+#' two ways. Either, as in the examples above, it is included in adult fecundity \ifelse{html}{\out{φ}}{\eqn{\phi}} (by appropriately reducing its value), and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{\sigma_0 \gamma_(0-1)}} is equal to \eqn{1.0}. This is how it is typically accounted for in matrix models. Or, alternatively,
+#' \eqn{\phi} is equal to the true maximum fecundity and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{\sigma_0 \gamma_(0-1)}} is less than \eqn{1.0}.
#' Only the first approach allows straightforward direct comparison with standard analytical matrix models.
#'
#' \emph{Minimum ages:} For every row in the transition matrix, a minimum age must be provided through a vector in argument \code{MinAge}. It specifies the age which an individual in stage \eqn{i-1} (with sex \eqn{m/f}, if applicable) must already have reached before it can develop into the next stage \eqn{(i)}. The vector must be in
@@ -122,26 +122,26 @@
#' \emph{Density dependence} can act on each of the three demographic phases (i.e. reproduction, survival and development) and is controlled by \code{FecDensDep,DevDensDep,SurvDensDep}.
#' It is implemented as an exponential decay \insertCite{neubert2000}{RangeShiftR}:
#'
-#' \ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) N(t) }}{\deqn{φ_i(r,t)=φ_(0,i) * exp(- b(r) N(t) ) }}
+#' \ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) N(t) }}{\deqn{\phi_i(r,t)=\phi_(0,i) * exp(- b(r) N(t) ) }}
#'
-#' \ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) N(t) }}{\deqn{σ_i(r,t)=σ_(0,i) * exp(- C_\sigma b(r) N(t) ) }}
+#' \ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) N(t) }}{\deqn{\sigma_i(r,t)=\sigma_(0,i) * exp(- C_\sigma b(r) N(t) ) }}
#'
-#' \ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) N(t) }}{\deqn{γ_i(r,t)=γ_(0,i) * exp(- C_γ b(r) N(t) ) }}
+#' \ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) N(t) }}{\deqn{\gamma_i(r,t)=\gamma_(0,i) * exp(- C_\gamma b(r) N(t) ) }}
#'
#' where \eqn{b(r)} is the strength of density dependence in fecundity at site \eqn{r}, which is given by the argument \code{K_or_DensDep} in the landscape module.
-#' Furthermore, \ifelse{html}{\out{Cσ}}{\eqn{C_\sigma}} and \ifelse{html}{\out{Cγ}}{\eqn{C_γ}} (\code{DevDensCoeff,SurvDensCoeff})
+#' Furthermore, \ifelse{html}{\out{Cσ}}{\eqn{C_\sigma}} and \ifelse{html}{\out{Cγ}}{\eqn{C_\gamma}} (\code{DevDensCoeff,SurvDensCoeff})
#' scale the strength of density dependence in survival and development relative to that in fecundity.
#'
#' Moreover, the strength of density-dependence can be uniform for all stages or stage-dependent. Even greater complexity can be incorporated with
#' different stages contributing differently to density-dependence \insertCite{caswell2004}{RangeShiftR}:
#'
-#' \ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) ΣjS ωφ,ij N(j,t)}}{\deqn{φ_i(r,t)=φ_(0,i) * exp(- b(r) \Sigma_j^S ω_{φ,ij} N_j(t) ) }}
+#' \ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) ΣjS ωφ,ij N(j,t)}}{\deqn{\phi_i(r,t)=\phi_(0,i) * exp(- b(r) \Sigma_j^S \omega_{\phi,ij} N_j(t) ) }}
#'
-#' \ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) ΣjS ωσ,ij N(j,t) }}{\deqn{σ_i(r,t)=σ_(0,i) * exp(- C_\sigma b(r) \Sigma_j^S ω_{σ,ij} N_j(t) )}}
+#' \ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) ΣjS ωσ,ij N(j,t) }}{\deqn{\sigma_i(r,t)=\sigma_(0,i) * exp(- C_\sigma b(r) \Sigma_j^S \omega_{\sigma,ij} N_j(t) )}}
#'
-#' \ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) ΣjS ωγ,ij N(j,t)}}{\deqn{γ_i(r,t)=γ_(0,i) * exp(- C_γ b(r) \Sigma_j^S ω_{γ,ij} N_j(t) )}}
+#' \ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) ΣjS ωγ,ij N(j,t)}}{\deqn{\gamma_i(r,t)=\gamma_(0,i) * exp(- C_\gamma b(r) \Sigma_j^S \omega_{\gamma,ij} N_j(t) )}}
#'
-#' where \ifelse{html}{\out{ωφ}}{\eqn{ω_φ}}, \ifelse{html}{\out{ωσ}}{\eqn{ω_σ}}, \ifelse{html}{\out{ωγ}}{\eqn{ω_γ}} are weight matrices given by \code{FecStageWtsMatrix, DevStageWtsMatrix, SurvStageWtsMatrix}. Their elements \ifelse{html}{\out{ωij}}{\eqn{ω_ij}}
+#' where \ifelse{html}{\out{ωφ}}{\eqn{\omega_\phi}}, \ifelse{html}{\out{ωσ}}{\eqn{\omega_\sigma}}, \ifelse{html}{\out{ωγ}}{\eqn{\omega_\gamma}} are weight matrices given by \code{FecStageWtsMatrix, DevStageWtsMatrix, SurvStageWtsMatrix}. Their elements \ifelse{html}{\out{ωij}}{\eqn{\omega_ij}}
#' represent the contributions of the abundance of stage \eqn{j} to the density dependence in the fecundity / survival / development of stage \eqn{i}, thus they are quadratic matrices of size \code{Stages}\eqn{^2}. Note that the row sums are not required to be normalized, therefore they can be used
#' to scale the density-dependence for the different stages. In fact, any real value will be accepted for the single weights, so care should be taken when setting them.
#' @examples # Stage-structure for simple sexual model
@@ -159,7 +159,7 @@
#' @author Anne-Kathleen Malchow
#' @name StageStructure
#' @export StageStructure
-StageStructure <- setClass("StagesParams", slots = c(Stages = "integer_OR_numeric",
+StageStructure <- methods::setClass("StagesParams", slots = c(Stages = "integer_OR_numeric",
TransMatrix = "matrix",
MaxAge = "integer_OR_numeric",
MinAge = "integer_OR_numeric",
@@ -373,9 +373,9 @@ setMethod("initialize", "StagesParams", function(.Object,...) {
if (!is.null(args$SurvStageWtsMatrix)) {
.Object@SurvStageWts <- TRUE
}
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (!.Object@FecDensDep) {
if (.Object@FecStageWts) {
@@ -489,12 +489,12 @@ setMethod("plotProbs", "StagesParams", function(x, stage = NULL, sex = NULL, xma
this.sex = 0
}
if (this.stage %in% stage && this.sex %in% sex) {
- if(x@FecDensDep){ lines(xvals, fecs[line]*exp(-xvals), type = "l", lty = 1, col = line) }
- else{ lines(xvals, rep(fecs[line], length(xvals)), type = "l", lty = 1, col = line) }
- if(x@SurvDensDep){ lines(xvals, surv[line]*exp(-x@SurvDensCoeff*xvals), type = "l", lty = 2, col = line) }
- else{ lines(xvals, rep(surv[line], length(xvals)), type = "l", lty = 2, col = line) }
- if(x@DevDensDep){ lines(xvals, devs[line]*exp(-x@DevDensCoeff*xvals), type = "l", lty = 3, col = line) }
- else{ lines(xvals, rep(devs[line], length(xvals)), type = "l", lty = 3, col = line) }
+ if(x@FecDensDep){ graphics::lines(xvals, fecs[line]*exp(-xvals), type = "l", lty = 1, col = line) }
+ else{ graphics::lines(xvals, rep(fecs[line], length(xvals)), type = "l", lty = 1, col = line) }
+ if(x@SurvDensDep){ graphics::lines(xvals, surv[line]*exp(-x@SurvDensCoeff*xvals), type = "l", lty = 2, col = line) }
+ else{ graphics::lines(xvals, rep(surv[line], length(xvals)), type = "l", lty = 2, col = line) }
+ if(x@DevDensDep){ graphics::lines(xvals, devs[line]*exp(-x@DevDensCoeff*xvals), type = "l", lty = 3, col = line) }
+ else{ graphics::lines(xvals, rep(devs[line], length(xvals)), type = "l", lty = 3, col = line) }
if(SexDep) {leg.txt <- c(leg.txt, paste0("Stage ",this.stage, ifelse(this.sex," female"," male")))}
else {leg.txt <- c(leg.txt, paste0("Stage ",this.stage))}
leg.col <- c(leg.col, line)
@@ -502,7 +502,7 @@ setMethod("plotProbs", "StagesParams", function(x, stage = NULL, sex = NULL, xma
}
if (length(leg.txt)>0) {
leg.txt <- c("Fecundity","Survival prob.","Developmt. prob.",leg.txt)
- legend("topright", leg.txt, col = c(rep(1,3),leg.col), lwd = 1.5, lty = c(1:3,rep(1,length(leg.col))) )
+ graphics::legend("topright", leg.txt, col = c(rep(1,3),leg.col), lwd = 1.5, lty = c(1:3,rep(1,length(leg.col))) )
}
})
@@ -512,7 +512,7 @@ setMethod("plotProbs", "StagesParams", function(x, stage = NULL, sex = NULL, xma
# contains basic demographic parameters (originally in RS 'Rarameters'-file) and optionally the 'StageStruct' object
# define this ClassUnion so that the 'stages' slot in the parameter master class 'RSparams' can be FALSE for option 'population with non-overlapping generations'
-setClassUnion("StagesSlot", c("logical", "StagesParams"))
+methods::setClassUnion("StagesSlot", c("logical", "StagesParams"))
#' Set Demographic Parameters
#'
@@ -543,7 +543,7 @@ setClassUnion("StagesSlot", c("logical", "StagesParams"))
#' \emph{Asexual / only-female models:} (\code{ReproductionType=0})\cr
#' Recruitment is determined by a stochastic, individual-based formulation of the \insertCite{smith1973;textual}{RangeShiftR} population model, where the number of offspring produced by a single individual in the cell/patch \eqn{i} at time \eqn{t}, is drawn from the following distribution:\cr
#'
-#' \ifelse{html}{\out{ Njuv(i,t) = Poisson( R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t))bc ) ) } }{\deqn{N_juv(i,t) = Poisson( R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
+#' \ifelse{html}{\out{Njuv(i,t) = Poisson( R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t))bc ) ) } }{\deqn{N_juv(i,t) = Poisson( R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
#'
#' Here, \eqn{R(i,t)} is the maximum growth rate \code{Rmax} (obtained at very low density only) and \eqn{K(i,t)} is the carrying capacity
#' at patch \eqn{i} and time \eqn{t}.
@@ -559,7 +559,7 @@ setClassUnion("StagesSlot", c("logical", "StagesParams"))
#' This is the simplest form of mate limitation. Each female individual is assumed to mate, as long as there is at least one male in the population. As for the asexual case, the Maynard Smith and Slatkin model is used to determine the expected number of
#' offspring produced by each female. To maintain equivalence between the asexual and sexual versions, the expected value of the Poisson distribution is multiplied by \eqn{2} (Lindström & Kokko 1998):\cr
#'
-#' \ifelse{html}{\out{ Njuv(i,t) = Poisson( 2 R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t) )bc ) ) } }{\deqn{N_juv(i,t) = Poisson( 2 R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
+#' \ifelse{html}{\out{Njuv(i,t) = Poisson( 2 R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t) )bc ) ) } }{\deqn{N_juv(i,t) = Poisson( 2 R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
#'
#' \emph{Complex mating system:} (\code{ReproductionType=2})\cr
#' More complex and flexible mating system. Mating is explicitly modelled through a mating function
@@ -581,7 +581,7 @@ setClassUnion("StagesSlot", c("logical", "StagesParams"))
#' @author Anne-Kathleen Malchow
#' @name Demography
#' @export Demography
-Demography <- setClass("DemogParams", slots = c(Rmax = "integer_OR_numeric",
+Demography <- methods::setClass("DemogParams", slots = c(Rmax = "integer_OR_numeric",
bc = "numeric",
StageStruct = "StagesSlot",
ReproductionType = "integer_OR_numeric",
@@ -626,7 +626,7 @@ setValidity("DemogParams", function(object) {
}
}
}
- validObject(object@StageStruct)
+ methods::validObject(object@StageStruct)
if (class(object@StageStruct)[1]=="logical") {
if (object@StageStruct) { # StageStruct=TRUE
msg <- c(msg, "StageStruct must either be FALSE or an object of class \"StagesParams\" !")
@@ -804,9 +804,9 @@ setValidity("DemogParams", function(object) {
setMethod("initialize", "DemogParams", function(.Object,...) {
this_func = "Demography(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (class(.Object@StageStruct)[1]=="StagesParams") {
.Object@Rmax = -9L
diff --git a/RangeShiftR/R/class_DispersalParams.R b/RangeShiftR/R/class_DispersalParams.R
index 29e88a0..90951da 100644
--- a/RangeShiftR/R/class_DispersalParams.R
+++ b/RangeShiftR/R/class_DispersalParams.R
@@ -58,18 +58,18 @@
#'
#' The emigration probability \eqn{d} can be density-dependent (set \code{DensDep=TRUE}), in which case it is given by the following function, introduced by \insertCite{kun2006evolution;textual}{RangeShiftR}:
#'
-#' \ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (N(i,t) / K(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-α_E (N(i,t)/K(i,t) - β_E) ] ) } }
+#' \ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (N(i,t) / K(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-\alpha_E (N(i,t)/K(i,t) - \beta_E) ] ) } }
#'
#' In the case of stage-structured models this equation is modified to:
#'
-#' \ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (b(i,t) * N(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-α_E (b(i,t) N(i,t) - β_E) ] ) } }
+#' \ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (b(i,t) * N(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-\alpha_E (b(i,t) N(i,t) - \beta_E) ] ) } }
#'
#' In the first case, \eqn{K(i,t)} is the carrying capacity of the cell/patch \eqn{i} at time \eqn{t} given by \code{K_or_DensDep}.
#' In the latter case, \eqn{b(i,t)} represents the strength of density dependence and is given by the inverse of \code{K_or_DensDep}.\cr
#' Further, \ifelse{html}{\out{D0}}{\eqn{D_0}} is the maximum emigration probability,
#' \eqn{N(i,t)} is the number of individuals in the cell/patch \eqn{i} at time \eqn{t},
-#' \ifelse{html}{\out{βE}}{\eqn{β_S}} is the inflection point of the function and
-#' \ifelse{html}{\out{αE}}{\eqn{α_S}} is the slope at the inflection point.\cr
+#' \ifelse{html}{\out{βE}}{\eqn{\beta_S}} is the inflection point of the function and
+#' \ifelse{html}{\out{αE}}{\eqn{\alpha_S}} is the slope at the inflection point.\cr
#'
#' Various functions have been proposed for density dependent emigration \insertCite{hovestadt2010information,poethke2011ability}{RangeShiftR}.
#' This one was chosen here because it is a flexible function that
@@ -78,8 +78,8 @@
#' Information acquisition is not explicitly modelled.
#'
#' The emigration probability can be allowed to vary between individuals (set \code{IndVar=TRUE}) and to evolve. In the this case, individuals exhibit either one trait
-#' determining the density-independent \eqn{d} (when \code{DensDep=FALSE}), or the three traits \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α} and
-#' \eqn{β} determining the density-dependent emigration probability (when \code{DensDep=TRUE}).\cr
+#' determining the density-independent \eqn{d} (when \code{DensDep=FALSE}), or the three traits \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha} and
+#' \eqn{\beta} determining the density-dependent emigration probability (when \code{DensDep=TRUE}).\cr
#' For each trait the initial distribution in the population (as mean and standard variation) must be set in \code{EmigProb} (instead of only one constant value),
#' as well as their scaling factors in \code{TraitScaleFactor} (see \code{\link[RangeShiftR]{Genetics}}).
#' Also, if \code{IndVar=TRUE} is set for a stage-structured population, it is required to specify the stage which emigrates via \code{EmigStage}.
@@ -91,7 +91,7 @@
#'
#' The parameters that determine the emigration probabilities have to be provided via \code{EmigProb}, which generally takes a matrix, or - if only a single constant probability is
#' used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric. The format of the matrix is defined as follows: The number of columns depend on the options \code{DensDep} and \code{IndVar}. If \code{DensDep=FALSE}, the
-#' density-independent probability \eqn{d} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α} and \eqn{β} (cp. equation above) must be specified.
+#' density-independent probability \eqn{d} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha} and \eqn{\beta} (cp. equation above) must be specified.
#' Additionally, if \code{IndVar=FALSE}, these parameters are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective mean and
#' standard deviation. They are used to normally distribute the traits values among the individuals of the initial population.
#'
@@ -103,20 +103,20 @@
#' F \tab F \tab T \tab F \tab stage, \eqn{d} \cr
#' F \tab F \tab F \tab T \tab sex, \eqn{d} \cr
#' F \tab F \tab T \tab T \tab stage, sex, \eqn{d} \cr
-#' T \tab F \tab F \tab F \tab \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α}, \eqn{β} \cr
+#' T \tab F \tab F \tab F \tab \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha}, \eqn{\beta} \cr
#' F \tab T \tab F \tab F \tab mean\eqn{(d)}, sd\eqn{(d)} \cr
-#' T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(α)}, sd\eqn{(α)}, mean\eqn{(β)}, sd\eqn{(β)} \cr
-#' \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
-#' T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(α)}, sd\eqn{(α)}, mean\eqn{(β)}, sd\eqn{(β)}
+#' T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(\alpha)}, sd\eqn{(\alpha)}, mean\eqn{(\beta)}, sd\eqn{(\beta)} \cr
+#' \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+#' T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(\alpha)}, sd\eqn{(\alpha)}, mean\eqn{(\beta)}, sd\eqn{(\beta)}
#' }
#'
#' The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly one row for each stage/sex combination. For example, in the case of density-, stage- and sex-dependent emigration with no individual variability:
-#' \tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1.0 \tab \out{ } 20 \tab \out{ } 0.2 \cr
-#' \out{ } 0 \tab \out{ } 1 \tab \out{ } 1.0 \tab \out{ } 20 \tab \out{ } 0.1 \cr
-#' \out{ } 1 \tab \out{ } 0 \tab \out{ } 0.7 \tab \out{ } 25 \tab \out{ } 0.5 \cr
-#' \out{ } 1 \tab \out{ } 1 \tab \out{ } 0.8 \tab \out{ } 50 \tab \out{ } 0.5 \cr
-#' \out{ } 2 \tab \out{ } 0 \tab \out{ } 0.4 \tab \out{ } 10 \tab \out{ } 1.0 \cr
-#' \out{ } 2 \tab \out{ } 1 \tab \out{ } 0.5 \tab \out{ } 20 \tab \out{ } 1.0
+#' \tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1.0 \tab \out{} 20 \tab \out{} 0.2 \cr
+#' \out{} 0 \tab \out{} 1 \tab \out{} 1.0 \tab \out{} 20 \tab \out{} 0.1 \cr
+#' \out{} 1 \tab \out{} 0 \tab \out{} 0.7 \tab \out{} 25 \tab \out{} 0.5 \cr
+#' \out{} 1 \tab \out{} 1 \tab \out{} 0.8 \tab \out{} 50 \tab \out{} 0.5 \cr
+#' \out{} 2 \tab \out{} 0 \tab \out{} 0.4 \tab \out{} 10 \tab \out{} 1.0 \cr
+#' \out{} 2 \tab \out{} 1 \tab \out{} 0.5 \tab \out{} 20 \tab \out{} 1.0
#' }
#'
#' In the special case that \code{DensDep=FALSE} and transfer is realised by \code{\link[RangeShiftR]{DispersalKernel}}, then the option \code{UseFullKern} may be switched on. It
@@ -143,7 +143,7 @@
#' @author Anne-Kathleen Malchow
#' @name Emigration
#' @export Emigration
-Emigration <- setClass("EmigrationParams", slots = c(DensDep = "logical",
+Emigration <- methods::setClass("EmigrationParams", slots = c(DensDep = "logical",
IndVar = "logical",
StageDep = "logical",
SexDep = "logical",
@@ -250,10 +250,10 @@ setValidity("EmigrationParams", function(object) {
}
else {
if (object@TraitScaleFactor[1] <= 0.0 || object@TraitScaleFactor[1] > 1.0 ) {
- msg <- c(msg, "TraitScaleFactor μ(D0) must be in the half-open interval (0,1] !")
+ msg <- c(msg, "TraitScaleFactor mu(D0) must be in the half-open interval (0,1] !")
}
if (any(object@TraitScaleFactor[2:3] <= 0.0 )) {
- msg <- c(msg, "TraitScaleFactor μ(α) and μ(β) must be strictly positive !")
+ msg <- c(msg, "TraitScaleFactor mu(\alpha) and mu(\beta) must be strictly positive !")
}
}
}
@@ -263,7 +263,7 @@ setValidity("EmigrationParams", function(object) {
}
else {
if (object@TraitScaleFactor <= 0 || object@TraitScaleFactor > 1 ) {
- msg <- c(msg, "TraitScaleFactor μ(D0) must be in the half-open interval (0,1] !")
+ msg <- c(msg, "TraitScaleFactor mu(D0) must be in the half-open interval (0,1] !")
}
}
}
@@ -282,9 +282,9 @@ setValidity("EmigrationParams", function(object) {
setMethod("initialize", "EmigrationParams", function(.Object, ...) {
this_func = "Emigration(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (!is.null(args$EmigProb)) {
if (class(args$EmigProb)[1] =="numeric" && length(args$EmigProb)==1) {
@@ -385,17 +385,17 @@ setMethod("plotProbs", "EmigrationParams", function(x, stage = NULL, sex = NULL,
res[,6] <- densdep(xvals, A0 = emig[line,ind_D0]+emig[line,ind_D0+1], alpha = emig[line,ind_D0+2]-emig[line,ind_D0+3], beta = emig[line,ind_D0+4]+emig[line,ind_D0+5])
res[,7] <- densdep(xvals, A0 = emig[line,ind_D0]+emig[line,ind_D0+1], alpha = emig[line,ind_D0+2]+emig[line,ind_D0+3], beta = emig[line,ind_D0+4]-emig[line,ind_D0+5])
res[,8] <- densdep(xvals, A0 = emig[line,ind_D0]+emig[line,ind_D0+1], alpha = emig[line,ind_D0+2]+emig[line,ind_D0+3], beta = emig[line,ind_D0+4]+emig[line,ind_D0+5])
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
else {#constant
- polygon(c(0,xmax,xmax,0), c(rep(emig[line,ind_D0]-emig[line,ind_D0+1],2),rep(emig[line,ind_D0]+emig[line,ind_D0+1],2)), border=NA, col='grey80')
+ graphics::polygon(c(0,xmax,xmax,0), c(rep(emig[line,ind_D0]-emig[line,ind_D0+1],2),rep(emig[line,ind_D0]+emig[line,ind_D0+1],2)), border=NA, col='grey80')
}
}
if (x@DensDep) {
- lines(xvals, densdep(xvals, A0 = emig[line,ind_D0], alpha = emig[line,ind_D0+IV], beta = emig[line,ind_D0+2*IV]), type = "l", lty = 1, col = line)
+ graphics::lines(xvals, densdep(xvals, A0 = emig[line,ind_D0], alpha = emig[line,ind_D0+IV], beta = emig[line,ind_D0+2*IV]), type = "l", lty = 1, col = line)
}
else {#constant
- lines(x=c(0,xmax), y=rep(emig[line,ind_D0],2), type = "l", lty = 1, col = line)
+ graphics::lines(x=c(0,xmax), y=rep(emig[line,ind_D0],2), type = "l", lty = 1, col = line)
}
if (x@StageDep) {
if (x@SexDep) {leg.txt <- c(leg.txt, paste0("Stage ",emig[line,1], ifelse(emig[line,2]," male"," female")))} else {leg.txt <- c(leg.txt, paste0("Stage ",emig[line,1]))}
@@ -405,7 +405,7 @@ setMethod("plotProbs", "EmigrationParams", function(x, stage = NULL, sex = NULL,
}
}
if (length(leg.txt)>0) {
- legend("topleft", leg.txt, col = 1:nrow(emig), lwd = 1.5)
+ graphics::legend("topleft", leg.txt, col = 1:nrow(emig), lwd = 1.5)
}
})
@@ -439,7 +439,7 @@ setMethod("plotProbs", "EmigrationParams", function(x, stage = NULL, sex = NULL,
#' \insertAllCited{}
#' @author Anne-Kathleen Malchow
#' @name Transfer
-TransferParams <- setClass("TransferParams")
+TransferParams <- methods::setClass("TransferParams")
setMethod("show", "TransferParams", function(object){
if (class(object)[1] == "DispersalKernel") cat(" Dispersal Kernel\n")
if (class(object)[1] == "StochMove") cat(" Stochastic Movement Simulator\n")
@@ -491,10 +491,10 @@ setMethod("show", "TransferParams", function(object){
#'
#' \emph{Negative exponential} \cr
#' If the individual disperses, the distance and the movement direction are determined in continuous space.
-#' The distance is drawn from a negative exponential distribution with a given mean \eqn{δ}, and the direction is selected randomly from a uniform
-#' distribution between \eqn{0} and \eqn{2π} radians.
+#' The distance is drawn from a negative exponential distribution with a given mean \eqn{\delta}, and the direction is selected randomly from a uniform
+#' distribution between \eqn{0} and \eqn{2\pi} radians.
#'
-#' \ifelse{html}{\out{ p(d;δ) = δ-1 e- d / δ}}{\deqn{ p(d;δ) = 1/δ exp(-d/δ) } }
+#' \ifelse{html}{\out{ p(d;δ) = δ-1 e- d / δ}}{\deqn{ p(d;\delta) = 1/\delta exp(-d/\delta) } }
#'
#' If the arrival point lies beyond the boundary of the landscape, distance and direction are re-drawn.\cr
#' The individual is displaced from a random point (using continuous coordinates) inside the natal cell to the arrival cell where the model
@@ -511,17 +511,17 @@ setMethod("show", "TransferParams", function(object){
#'
#' \emph{Mixed kernel} \cr
#' The distance an individual moves is sampled from a mixed kernel given by the combination of two negative exponentials
-#' with different means \ifelse{html}{\out{δ1}}{\eqn{δ_1}} and \ifelse{html}{\out{δ2}}{\eqn{δ_2}},
+#' with different means \ifelse{html}{\out{δ1}}{\eqn{\delta_1}} and \ifelse{html}{\out{δ2}}{\eqn{\delta_2}},
#' occurring with probability \ifelse{html}{\out{pI}}{\eqn{p_I}} and \eqn{1-}\ifelse{html}{\out{pI}}{\eqn{p_I}} respectively \insertCite{hovestadt2011all}{RangeShiftR}.
#' Otherwise, the conditions for the single kernel apply.
#'
-#' \ifelse{html}{\out{ p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1)}}{\deqn{ p(d; δ_1,δ_2) = p_I p(d;δ_1) + (1-p_I) p(d;δ_2)}}
+#' \ifelse{html}{\out{ p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1)}}{\deqn{ p(d; \delta_1,\delta_2) = p_I p(d;\delta_1) + (1-p_I) p(d;\delta_2)}}
#'
#' For both types of kernel, inter-individual variability of the kernel traits is possible (set \code{IndVar=TRUE}). Individuals will
-#' carry either one trait for \eqn{δ} or three traits for \ifelse{html}{\out{δ1}}{\eqn{δ_1}}, \ifelse{html}{\out{δ2}}{\eqn{δ_2}} and
+#' carry either one trait for \eqn{\delta} or three traits for \ifelse{html}{\out{δ1}}{\eqn{\delta_1}}, \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} and
#' \ifelse{html}{\out{pI}}{\eqn{p_I}}, which they inherit from their parents.\cr
-#' Dispersal kernels can also be sex-dependent (set \code{SexDep=TRUE}). In the case of inter-individual variability, the number of traits is doubled to two trait (female \eqn{δ}
-#' and male δ) or six traits (female and male \ifelse{html}{\out{δ1}}{\eqn{δ_1}}, \ifelse{html}{\out{δ2}}{\eqn{δ_2}} and \ifelse{html}{\out{pI}}{\eqn{p_I}}).\cr
+#' Dispersal kernels can also be sex-dependent (set \code{SexDep=TRUE}). In the case of inter-individual variability, the number of traits is doubled to two trait (female \eqn{\delta}
+#' and male delta) or six traits (female and male \ifelse{html}{\out{δ1}}{\eqn{\delta_1}}, \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} and \ifelse{html}{\out{pI}}{\eqn{p_I}}).\cr
#' For each trait the initial distribution in the population (as mean and standard variation) must be set in \code{Distances} (instead of only one constant value),
#' as well as their scaling factors in \code{TraitScaleFactor} (see \code{\link[RangeShiftR]{Genetics}}).\cr
#'
@@ -529,8 +529,8 @@ setMethod("show", "TransferParams", function(object){
#'
#' All dispersal kernel parameters have to be provided via \code{Distances}, which generally takes a matrix, or - if only a single constant mean distance is
#' used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric. The format of the matrix is defined as follows: The number of columns depend on the options \code{IndVar} and \code{DoubleKernel}.
-#' If \code{DoubleKernel=FALSE}, the mean dispersal distance \eqn{δ} must be specified (in meters). If \code{DoubleKernel=TRUE}, the mean dispersal distances
-#' \ifelse{html}{\out{δ1}}{\eqn{δ_1}} and \ifelse{html}{\out{δ2}}{\eqn{δ_2}} (in meters), as well as the probability \ifelse{html}{\out{pI}}{\eqn{p_I}} of using Kernel-1 must be specified.
+#' If \code{DoubleKernel=FALSE}, the mean dispersal distance \eqn{\delta} must be specified (in meters). If \code{DoubleKernel=TRUE}, the mean dispersal distances
+#' \ifelse{html}{\out{δ1}}{\eqn{\delta_1}} and \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} (in meters), as well as the probability \ifelse{html}{\out{pI}}{\eqn{p_I}} of using Kernel-1 must be specified.
#' Additionally, if \code{IndVar=FALSE}, these parameters are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective mean and
#' standard deviation. They are used to normally distribute the traits values among the individuals of the initial population.
#'
@@ -539,25 +539,25 @@ setMethod("show", "TransferParams", function(object){
#' table lists the required columns and their correct order for different settings:
#'
#' \tabular{ccccc}{IndVar \tab DoubleKernel \tab StageDep \tab SexDep \tab columns \cr
-#' F \tab F \tab F \tab F \tab \eqn{δ} \cr
-#' F \tab F \tab T \tab F \tab stage, \eqn{δ} \cr
-#' F \tab F \tab F \tab T \tab sex, \eqn{δ} \cr
-#' F \tab F \tab T \tab T \tab stage, sex, \eqn{δ} \cr
-#' F \tab T \tab F \tab F \tab \ifelse{html}{\out{δ1, δ2, pI}}{\eqn{δ_1, δ_2, p_I}} \cr
-#' T \tab F \tab F \tab F \tab mean\eqn{(δ)}, sd\eqn{(δ)} \cr
-#' T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(δ_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(δ_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(δ_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(δ_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}} \cr
-#' \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
-#' T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(δ_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(δ_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(δ_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(δ_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}
+#' F \tab F \tab F \tab F \tab \eqn{\delta} \cr
+#' F \tab F \tab T \tab F \tab stage, \eqn{\delta} \cr
+#' F \tab F \tab F \tab T \tab sex, \eqn{\delta} \cr
+#' F \tab F \tab T \tab T \tab stage, sex, \eqn{\delta} \cr
+#' F \tab T \tab F \tab F \tab \ifelse{html}{\out{δ1, δ2, pI}}{\eqn{\delta_1, \delta_2, p_I}} \cr
+#' T \tab F \tab F \tab F \tab mean\eqn{(\delta)}, sd\eqn{(\delta)} \cr
+#' T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(\delta_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(\delta_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(\delta_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(\delta_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}} \cr
+#' \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+#' T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(\delta_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(\delta_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(\delta_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(\delta_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}
#' }
#'
#' The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly
#' one row for each stage/sex combination. For example, in the case of a mixed kernel with stage- and sex-dependent distances and no individual variability:
-#' \tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1000 \tab \out{ } 4500 \tab \out{ } 0.92 \cr
-#' \out{ } 0 \tab \out{ } 1 \tab \out{ } 1400 \tab \out{ } 6000 \tab \out{ } 0.95 \cr
-#' \out{ } 1 \tab \out{ } 0 \tab \out{ } 700 \tab \out{ } 500 \tab \out{ } 0.50 \cr
-#' \out{ } 1 \tab \out{ } 1 \tab \out{ } 500 \tab \out{ } 600 \tab \out{ } 0.55 \cr
-#' \out{ } 2 \tab \out{ } 0 \tab \out{ } 100 \tab \out{ } 0 \tab \out{ } 1.0 \cr
-#' \out{ } 2 \tab \out{ } 1 \tab \out{ } 100 \tab \out{ } 0 \tab \out{ } 1.0
+#' \tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1000 \tab \out{} 4500 \tab \out{} 0.92 \cr
+#' \out{} 0 \tab \out{} 1 \tab \out{} 1400 \tab \out{} 6000 \tab \out{} 0.95 \cr
+#' \out{} 1 \tab \out{} 0 \tab \out{} 700 \tab \out{} 500 \tab \out{} 0.50 \cr
+#' \out{} 1 \tab \out{} 1 \tab \out{} 500 \tab \out{} 600 \tab \out{} 0.55 \cr
+#' \out{} 2 \tab \out{} 0 \tab \out{} 100 \tab \out{} 0 \tab \out{} 1.0 \cr
+#' \out{} 2 \tab \out{} 1 \tab \out{} 100 \tab \out{} 0 \tab \out{} 1.0
#' }
#'
#' In the case that the dispersal kernel is applied to the entire
@@ -573,7 +573,7 @@ setMethod("show", "TransferParams", function(object){
#' A second source of dispersal mortality can be specified via the option \code{DistMort}: The probability of mortality is either a constant
#' (\eqn{m=}\code{MortProb}) or a function of distance \eqn{d} (i.e. individuals that travel further are more likely to die):
#'
-#' \ifelse{html}{\out{ m(d) = 1 / ( 1 + e-a (d- b) ) } }{\deqn{ m(d) = 1 / ( 1 + exp[-α (d-b) ] ) } }
+#' \ifelse{html}{\out{ m(d) = 1 / ( 1 + e-a (d- b) ) } }{\deqn{ m(d) = 1 / ( 1 + exp[-\alpha (d-b) ] ) } }
#'
#' with the inflection point \eqn{b=}\code{InflPoint} at which \eqn{m(d=b)=0.5} and the slope \eqn{a=}\code{Slope}.This option may be thought
#' to represent the increased energetic, time or attritional costs that longer-distance dispersers will experience \insertCite{bonte2012costs}{RangeShiftR}.
@@ -596,7 +596,7 @@ setMethod("show", "TransferParams", function(object){
#' @author Anne-Kathleen Malchow
#' @name DispersalKernel
#' @export DispersalKernel
-DispersalKernel <- setClass("DispersalKernel", slots = c(IndVar = "logical",
+DispersalKernel <- methods::setClass("DispersalKernel", slots = c(IndVar = "logical",
DoubleKernel = "logical",
StageDep = "logical",
SexDep = "logical",
@@ -702,10 +702,10 @@ setValidity("DispersalKernel", function(object) {
}
else {
if (object@TraitScaleFactor[3] <= 0.0 || object@TraitScaleFactor[3] > 1.0 ) {
- msg <- c(msg, "TraitScaleFactor μ(p) must be in the half-open interval (0,1] !")
+ msg <- c(msg, "TraitScaleFactor mu(p) must be in the half-open interval (0,1] !")
}
if (any(object@TraitScaleFactor[1:2] <= 0.0 )) {
- msg <- c(msg, "TraitScaleFactor μ(δ1) and μ(δ2) must be strictly positive !")
+ msg <- c(msg, "TraitScaleFactor mu(delta1) and mu(delta2) must be strictly positive !")
}
}
}
@@ -715,7 +715,7 @@ setValidity("DispersalKernel", function(object) {
}
else {
if (object@TraitScaleFactor <= 0.0) {
- msg <- c(msg, "TraitScaleFactor μ(δ) must be strictly positive !")
+ msg <- c(msg, "TraitScaleFactor mu(delta) must be strictly positive !")
}
}
}
@@ -750,9 +750,9 @@ setValidity("DispersalKernel", function(object) {
setMethod("initialize", "DispersalKernel", function(.Object, ...) {
this_func = "DispersalKernel(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (class(args$Distances)[1]=="numeric" && length(args$Distances)==1) {
.Object@Distances <- as.matrix(args$Distances)
@@ -782,7 +782,7 @@ setMethod("initialize", "DispersalKernel", function(.Object, ...) {
.Object}
)
setMethod("show", "DispersalKernel", function(object){
- callNextMethod()
+ methods::callNextMethod()
if (object@IndVar) {
cat(" IndVar =", object@IndVar, "\n")
}
@@ -876,15 +876,15 @@ setMethod("plotProbs", "DispersalKernel", function(x, mortality = FALSE, combine
if (!combinekernels){
if (x@IndVar) {
res <- matrix(ncol = 3, nrow = length(xvals))
- res[,1] <- dexp(xvals, rate = 1/(dists[line,ind_kernel1]))
- res[,2] <- dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1]))
- res[,3] <- dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1]))
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ res[,1] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]))
+ res[,2] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1]))
+ res[,3] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1]))
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
- lines(xvals,dexp(xvals,rate = 1/dists[line,ind_kernel1]), type = "l", lty = 1, col = line)
+ graphics::lines(xvals,stats::dexp(xvals,rate = 1/dists[line,ind_kernel1]), type = "l", lty = 1, col = line)
}
}
- else {lines(xvals, rep(0, length(xvals)), type = "l", lty = 1, col = line)}
+ else {graphics::lines(xvals, rep(0, length(xvals)), type = "l", lty = 1, col = line)}
if (x@DoubleKernel){
if(dists[line,ind_kernel2]>0){
if (combinekernels){
@@ -892,31 +892,31 @@ setMethod("plotProbs", "DispersalKernel", function(x, mortality = FALSE, combine
if (x@IndVar) {
pI_sd <- c(pI+dists[line,ind_pI+1],pI-dists[line,ind_pI+1])
res <- matrix(ncol = 8, nrow = length(xvals))
- res[,1] <- pI_sd[1] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
- res[,2] <- pI_sd[2] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
- res[,3] <- pI_sd[1] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
- res[,4] <- pI_sd[2] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
- res[,5] <- pI_sd[1] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
- res[,6] <- pI_sd[2] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
- res[,7] <- pI_sd[1] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
- res[,8] <- pI_sd[2] * dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ res[,1] <- pI_sd[1] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
+ res[,2] <- pI_sd[2] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
+ res[,3] <- pI_sd[1] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
+ res[,4] <- pI_sd[2] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
+ res[,5] <- pI_sd[1] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
+ res[,6] <- pI_sd[2] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]+dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
+ res[,7] <- pI_sd[1] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[1]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
+ res[,8] <- pI_sd[2] * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel1]-dists[line,ind_kernel1+1])) + (1-pI_sd[2]) * stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
- yvals <- pI * dexp(xvals, rate = 1/dists[line,ind_kernel1]) + (1-pI) * dexp(xvals, rate = 1/dists[line,ind_kernel2])
- lines(xvals, yvals , type = "l", lty = 1, col = line)
+ yvals <- pI * stats::dexp(xvals, rate = 1/dists[line,ind_kernel1]) + (1-pI) * stats::dexp(xvals, rate = 1/dists[line,ind_kernel2])
+ graphics::lines(xvals, yvals , type = "l", lty = 1, col = line)
}
else {
if (x@IndVar) {
- res[,1] <- dexp(xvals, rate = 1/(dists[line,ind_kernel2]))
- res[,2] <- dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
- res[,3] <- dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ res[,1] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]))
+ res[,2] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]+dists[line,ind_kernel2+1]))
+ res[,3] <- stats::dexp(xvals, rate = 1/(dists[line,ind_kernel2]-dists[line,ind_kernel2+1]))
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
- lines(xvals,dexp(xvals,rate = 1/dists[line,ind_kernel2]), type = "l", lty = 2, col = line)
+ graphics::lines(xvals,stats::dexp(xvals,rate = 1/dists[line,ind_kernel2]), type = "l", lty = 2, col = line)
}
}
else{
- lines(xvals, rep(0, length(xvals)), type = "l", lty = 2, col = line)
+ graphics::lines(xvals, rep(0, length(xvals)), type = "l", lty = 2, col = line)
}
}
if (x@StageDep) {
@@ -927,7 +927,7 @@ setMethod("plotProbs", "DispersalKernel", function(x, mortality = FALSE, combine
}
}
if (length(leg.txt)>0) {
- legend("topright", leg.txt, col = 1:nrow(dists), lwd = 1.5)
+ graphics::legend("topright", leg.txt, col = 1:nrow(dists), lwd = 1.5)
}
}
})
@@ -1063,7 +1063,7 @@ setMethod("plotProbs", "DispersalKernel", function(x, mortality = FALSE, combine
#' @author Anne-Kathleen Malchow
#' @name SMS
#' @export SMS
-SMS <- setClass("StochMove", slots = c(PR = "integer_OR_numeric",
+SMS <- methods::setClass("StochMove", slots = c(PR = "integer_OR_numeric",
PRMethod = "integer_OR_numeric", # Perceptual range method: 1 = arithmetic mean; 2 = harmonic mean; 3 = weighted arithmtic mean
MemSize = "integer_OR_numeric",
GoalType = "integer_OR_numeric", # 0 (none) or 2 (dispersal bias)
@@ -1311,9 +1311,9 @@ setValidity("StochMove", function(object) {
setMethod("initialize", "StochMove", function(.Object,...) {
this_func = "SMS(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (!.Object@GoalType) { # GoalType = 0
.Object@GoalBias = 1.0
@@ -1340,7 +1340,7 @@ setMethod("initialize", "StochMove", function(.Object,...) {
.Object}
)
setMethod("show", "StochMove", function(object){
- callNextMethod()
+ methods::callNextMethod()
cat(" PR =", object@PR, ", MemSize =", object@MemSize, "\n")
if (object@PRMethod == 1) cat(" Method: Arithmetic mean \n")
if (object@PRMethod == 2) cat(" Method: Harmonic mean \n")
@@ -1402,17 +1402,17 @@ setMethod("plotProbs", "StochMove", function(x, xmax = NULL, ymax = NULL){
res[,6] <- 1+densdep(xvals, A0 = (gb[1]+gb[2]-1), alpha = -(alp[1]-alp[2]), beta = (bet[1]+bet[2]))
res[,7] <- 1+densdep(xvals, A0 = (gb[1]+gb[2]-1), alpha = -(alp[1]+alp[2]), beta = (bet[1]-bet[2]))
res[,8] <- 1+densdep(xvals, A0 = (gb[1]+gb[2]-1), alpha = -(alp[1]+alp[2]), beta = (bet[1]+bet[2]))
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
else {#constant
- polygon(c(0,xmax,xmax,0), c(rep(gb[1]-gb[2],2),rep(gb[1]+gb[2],2)), border=NA, col='grey80')
+ graphics::polygon(c(0,xmax,xmax,0), c(rep(gb[1]-gb[2],2),rep(gb[1]+gb[2],2)), border=NA, col='grey80')
}
}
# plot lines
if (x@GoalType == 2) {
- lines(xvals, 1+densdep(xvals, A0 = (gb[1]-1), alpha = -alp[1], beta = bet[1]), type = "b", lty = 1, col = "blue")
+ graphics::lines(xvals, 1+densdep(xvals, A0 = (gb[1]-1), alpha = -alp[1], beta = bet[1]), type = "b", lty = 1, col = "blue")
}else { # constant
- lines(x=c(0,xmax), y=rep(gb[1],2), type = "b", lty = 1, col = "blue")
+ graphics::lines(x=c(0,xmax), y=rep(gb[1],2), type = "b", lty = 1, col = "blue")
}
})
@@ -1430,7 +1430,7 @@ setMethod("plotProbs", "StochMove", function(x, xmax = NULL, ymax = NULL){
#' StepMort = 0.0)
#' @param StepLength Step length given in meters, defaults to \eqn{1}.\cr If \code{IndVar=TRUE}, expects a vector of length three
#' specifying (Mean, SD, TraitScaleFactor) of \code{StepLength}.
-#' @param Rho Correlation parameter \eqn{ρ}, defaults to \eqn{0.5}. Must be in the open interval \eqn{(0,1)}.\cr If \code{IndVar=TRUE},
+#' @param Rho Correlation parameter \eqn{\rho}, defaults to \eqn{0.5}. Must be in the open interval \eqn{(0,1)}.\cr If \code{IndVar=TRUE},
#' expects a vector of length three specifying (Mean, SD, TraitScaleFactor) of \code{Rho}.
#' @param IndVar Individual variability in CorrRW traits (i.e. \code{StepLength} and \code{Rho})? Defaults to \code{FALSE}.
#' @param StraightenPath Straighten path after decision not to settle in a patch? Defaults to \code{TRUE}, see Details below.
@@ -1480,7 +1480,7 @@ setMethod("plotProbs", "StochMove", function(x, xmax = NULL, ymax = NULL){
#' @author Anne-Kathleen Malchow
#' @name CorrRW
#' @export CorrRW
-CorrRW <- setClass("CorrRW", slots = c(IndVar = "logical",
+CorrRW <- methods::setClass("CorrRW", slots = c(IndVar = "logical",
StepLength = "numeric",
Rho = "numeric",
StraightenPath = "logical",
@@ -1585,14 +1585,14 @@ setValidity("CorrRW", function(object) {
# setMethod("initialize", "CorrRW", function(.Object,...) {
# this_func = "CorrRW(): "
# args <- list(...)
-# .Object <- callNextMethod()
+# .Object <- methods::callNextMethod()
# if ( length(args) == 0 ) {
-# validObject(.Object)
+# methods::validObject(.Object)
# }
# .Object}
# )
setMethod("show", "CorrRW", function(object){
- callNextMethod()
+ methods::callNextMethod()
if (object@IndVar) {
cat(" StepLength =", object@StepLength[1], "\u00B1" , object@StepLength[2], ", scale \u03bc =", object@StepLength[3], "\n")
cat(" Rho =", object@Rho[1], "\u00B1" , object@Rho[2], ", scale \u03bc =", object@Rho[3], "\n")
@@ -1648,8 +1648,8 @@ setMethod("show", "CorrRW", function(object){
#' In any case, dispersing individuals are not allowed to settle in their natal cell or patch.\cr
#' \emph{RangeShiftR} incorporates some basic settlement rules that can be stage- or sex-specific or both (set \code{StageDep}, \code{SexDep}).
#' Inter-individual variability (\code{IndVar}) is implemented only for movement processes and then for the three traits
-#' determining density-dependent settlement (\ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}},
-#' \ifelse{html}{\out{βS}}{\eqn{β_S}}; see below). In this case, settlement may not be stage-dependent.\cr
+#' determining density-dependent settlement (\ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}},
+#' \ifelse{html}{\out{βS}}{\eqn{\beta_S}}; see below). In this case, settlement may not be stage-dependent.\cr
#'
#' \emph{Settlement with dispersal kernels}\cr
#' When using a \code{\link[RangeShiftR]{DispersalKernel}}, individuals are displaced directly from the starting location to the arrival location. The suitability
@@ -1679,7 +1679,7 @@ setMethod("show", "CorrRW", function(object){
#' \eqn{2} = randomly choose a suitable neighbouring cell or die,\cr
#' \eqn{3} = randomly choose a suitable neighbouring cell or wait (stage-structured models only).\cr
#'
-#' Simple example for sex-dependence only: Females choose a neighbouring cell or wait, males wait: \tabular{cc}{\out{ } 0 \tab \out{ } 3 \cr \out{ } 1 \tab \out{ } 0 }
+#' Simple example for sex-dependence only: Females choose a neighbouring cell or wait, males wait: \tabular{cc}{\out{} 0 \tab \out{} 3 \cr \out{} 1 \tab \out{} 0 }
#'
#' \emph{Settlement with movement processes}\cr
#' If individuals are dispersing by one of the two movement processes implemented (\code{\link[RangeShiftR]{SMS}} or
@@ -1692,18 +1692,18 @@ setMethod("show", "CorrRW", function(object){
#' Furthermore, the settlement decision can be density-dependent (set \code{DensDep=TRUE}). In this case, the individual has a probability \ifelse{html}{\out{pS}}{\eqn{p_S}}
#' of settling in the cell or patch \eqn{i}, given by:
#'
-#' \ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (N(i,t) / K(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-α_S (N(i,t)/K(i,t) - β_S) ] ) } }
+#' \ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (N(i,t) / K(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-\alpha_S (N(i,t)/K(i,t) - \beta_S) ] ) } }
#'
#' In the case of stage-structured models the above equation is modified to:
#'
-#' \ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (b(i,t) * N(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-α_S (b(i,t) N(i,t) - β_S) ] ) } }
+#' \ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (b(i,t) * N(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-\alpha_S (b(i,t) N(i,t) - \beta_S) ] ) } }
#'
#' In the first case, \eqn{K(i,t)} is the carrying capacity of the cell/patch \eqn{i} at time \eqn{t} given by \code{K_or_DensDep}.
#' In the latter case, \eqn{b(i,t)} represents the strength of density dependence that is given by the inverse of \code{K_or_DensDep}.\cr
#' Further, \ifelse{html}{\out{S0}}{\eqn{S_0}} is the maximum settlement probability,
#' \eqn{N(i,t)} is the number of individuals in the cell/patch \eqn{i} at time \eqn{t},
-#' \ifelse{html}{\out{βS}}{\eqn{β_S}} is the inflection point of the function and
-#' \ifelse{html}{\out{αS}}{\eqn{α_S}} is the slope at the inflection point.\cr
+#' \ifelse{html}{\out{βS}}{\eqn{\beta_S}} is the inflection point of the function and
+#' \ifelse{html}{\out{αS}}{\eqn{\alpha_S}} is the slope at the inflection point.\cr
#'
#' Inter-individual variability \code{IndVar=TRUE} and thus evolution is implemented only for the three traits determining density-dependent settlement
#' (\code{DensDep=TRUE}), and if so, it may not be stage-dependent (\code{StageDep=FALSE}).
@@ -1714,7 +1714,7 @@ setMethod("show", "CorrRW", function(object){
#' used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric.
#' The format of the matrix is defined as follows: The number of columns depend on the options \code{DensDep} and \code{IndVar}. If \code{DensDep=FALSE}, the
#' density-independent probability \ifelse{html}{\out{pS}}{\eqn{p_S}} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{S0}}{\eqn{S_0}},
-#' \ifelse{html}{\out{αS}}{\eqn{α_S}} and \ifelse{html}{\out{βS}}{\eqn{β_S}} (cf. equation above) must be specified.
+#' \ifelse{html}{\out{αS}}{\eqn{\alpha_S}} and \ifelse{html}{\out{βS}}{\eqn{\beta_S}} (cf. equation above) must be specified.
#' Additionally, if \code{IndVar=FALSE}, these traits are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective initial mean and
#' standard deviation. They are used to normally distribute the traits values among the individuals of the initial population. Additionally, the \code{TraitScaleFactor} of
#' these traits have to be set.
@@ -1729,21 +1729,21 @@ setMethod("show", "CorrRW", function(object){
#' F \tab F \tab T \tab F \tab stage \cr
#' F \tab F \tab F \tab T \tab sex \cr
#' F \tab F \tab T \tab T \tab stage, sex \cr
-#' T \tab F \tab F \tab F \tab \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}}, \ifelse{html}{\out{βS}}{\eqn{β_S}} \cr
-#' \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
-#' T \tab F \tab T \tab T \tab stage, sex, \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}}, \ifelse{html}{\out{βS}}{\eqn{β_S}} \cr
-#' T \tab T \tab F \tab F \tab mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{β_S})} \cr
-#' T \tab T \tab F \tab T \tab sex, mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}
+#' T \tab F \tab F \tab F \tab \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}}, \ifelse{html}{\out{βS}}{\eqn{\beta_S}} \cr
+#' \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+#' T \tab F \tab T \tab T \tab stage, sex, \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}}, \ifelse{html}{\out{βS}}{\eqn{\beta_S}} \cr
+#' T \tab T \tab F \tab F \tab mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})} \cr
+#' T \tab T \tab F \tab T \tab sex, mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}
#' }
#'
#' The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly one row for each stage/sex combination.
#' For example, in the case of density-, stage- and sex-dependent settlement with no individual variability:
-#' \tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1.0 \tab \out{ } 0.2 \tab \out{ } 4.0 \cr
-#' \out{ } 0 \tab \out{ } 1 \tab \out{ } 1.0 \tab \out{ } 0.1 \tab \out{ } 6.0 \cr
-#' \out{ } 1 \tab \out{ } 0 \tab \out{ } 0.7 \tab \out{ } 0.5 \tab \out{ } 2.0 \cr
-#' \out{ } 1 \tab \out{ } 1 \tab \out{ } 0.5 \tab \out{ } 0.5 \tab \out{ } 2.0 \cr
-#' \out{ } 2 \tab \out{ } 0 \tab \out{ } 0.05 \tab \out{ } 1.0 \tab \out{ } 1.0 \cr
-#' \out{ } 2 \tab \out{ } 1 \tab \out{ } 0.05 \tab \out{ } 1.0 \tab \out{ } 1.0
+#' \tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1.0 \tab \out{} 0.2 \tab \out{} 4.0 \cr
+#' \out{} 0 \tab \out{} 1 \tab \out{} 1.0 \tab \out{} 0.1 \tab \out{} 6.0 \cr
+#' \out{} 1 \tab \out{} 0 \tab \out{} 0.7 \tab \out{} 0.5 \tab \out{} 2.0 \cr
+#' \out{} 1 \tab \out{} 1 \tab \out{} 0.5 \tab \out{} 0.5 \tab \out{} 2.0 \cr
+#' \out{} 2 \tab \out{} 0 \tab \out{} 0.05 \tab \out{} 1.0 \tab \out{} 1.0 \cr
+#' \out{} 2 \tab \out{} 1 \tab \out{} 0.05 \tab \out{} 1.0 \tab \out{} 1.0
#' }
#'
#' To avoid having individuals moving perpetually because they cannot find suitable conditions to settle, the model requires a maximum number
@@ -1772,7 +1772,7 @@ setMethod("show", "CorrRW", function(object){
#' @author Anne-Kathleen Malchow
#' @name Settlement
#' @export Settlement
-Settlement <- setClass("SettlementParams", slots = c(StageDep = "logical",
+Settlement <- methods::setClass("SettlementParams", slots = c(StageDep = "logical",
SexDep = "logical",
Settle = "matrix_OR_numeric", # Settlement conditions for all sexes/stages. Settlement rule if the arrival cell/patch is unsuitable: 0 = die, 1 = wait, 2 = randomly choose a suitable cell/patch or die, 3 = randomly choose a suitable cell/patch or wait
FindMate = "logical",
@@ -1846,10 +1846,10 @@ setValidity("SettlementParams", function(object) {
}
else {
if (object@TraitScaleFactor[1] <= 0.0 || object@TraitScaleFactor[1] > 1.0 ) {
- msg <- c(msg, "TraitScaleFactor μ(S_0) must be in the half-open interval (0,1] !")
+ msg <- c(msg, "TraitScaleFactor mu(S_0) must be in the half-open interval (0,1] !")
}
if (any(object@TraitScaleFactor[2:3] <= 0.0 )) {
- msg <- c(msg, "TraitScaleFactor μ(α_s) and μ(β_s) must be strictly positive !")
+ msg <- c(msg, "TraitScaleFactor mu(\alpha_s) and mu(\beta_s) must be strictly positive !")
}
}
}
@@ -1859,7 +1859,7 @@ setValidity("SettlementParams", function(object) {
}
else {
if (object@TraitScaleFactor <= 0 || object@TraitScaleFactor > 1 ) {
- msg <- c(msg, "TraitScaleFactor μ(S_0) must be in the half-open interval (0,1] !")
+ msg <- c(msg, "TraitScaleFactor mu(S_0) must be in the half-open interval (0,1] !")
}
}
}
@@ -1915,9 +1915,9 @@ setValidity("SettlementParams", function(object) {
setMethod("initialize", "SettlementParams", function(.Object,...) {
this_func = "Settlement(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (!is.null(args$Settle)) {
if (class(args$Settle)[1]=="numeric" && length(args$Settle)==1) {
@@ -2000,9 +2000,9 @@ setMethod("plotProbs", "SettlementParams", function(x, stage = NULL, sex = NULL,
res[,6] <- densdep(xvals, A0 = sett[line,ind_D0]+sett[line,ind_D0+1], alpha = sett[line,ind_D0+2]-sett[line,ind_D0+3], beta = sett[line,ind_D0+4]+sett[line,ind_D0+5])
res[,7] <- densdep(xvals, A0 = sett[line,ind_D0]+sett[line,ind_D0+1], alpha = sett[line,ind_D0+2]+sett[line,ind_D0+3], beta = sett[line,ind_D0+4]-sett[line,ind_D0+5])
res[,8] <- densdep(xvals, A0 = sett[line,ind_D0]+sett[line,ind_D0+1], alpha = sett[line,ind_D0+2]+sett[line,ind_D0+3], beta = sett[line,ind_D0+4]+sett[line,ind_D0+5])
- polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
+ graphics::polygon(c(xvals,rev(xvals)), c(apply(res, 1, min), rev(apply(res, 1, max))), border=NA, col='grey80')
}
- lines(xvals, densdep(xvals, A0 = sett[line,ind_D0], alpha = sett[line,ind_D0+IV], beta = sett[line,ind_D0+2*IV]), type = "l", lty = 1, col = line)
+ graphics::lines(xvals, densdep(xvals, A0 = sett[line,ind_D0], alpha = sett[line,ind_D0+IV], beta = sett[line,ind_D0+2*IV]), type = "l", lty = 1, col = line)
if (x@StageDep) {
if (x@SexDep) {leg.txt <- c(leg.txt, paste0("Stage ",sett[line,1], ifelse(sett[line,2]," male"," female")))} else {leg.txt <- c(leg.txt, paste0("Stage ",sett[line,1]))}
@@ -2012,7 +2012,7 @@ setMethod("plotProbs", "SettlementParams", function(x, stage = NULL, sex = NULL,
}
}
if (length(leg.txt)>0) {
- legend("topright", leg.txt, col = 1:nrow(sett), lwd = 1.5)
+ graphics::legend("topright", leg.txt, col = 1:nrow(sett), lwd = 1.5)
}
}
else{ print("Plotting is only implemented for density-dependent settlement (in a movement process).\n") }
@@ -2074,7 +2074,7 @@ setMethod("plotProbs", "SettlementParams", function(x, stage = NULL, sex = NULL,
#' @author Anne-Kathleen Malchow
#' @name Dispersal
#' @export Dispersal
-Dispersal <- setClass("DispersalParams", slots = c(Emigration = "EmigrationParams",
+Dispersal <- methods::setClass("DispersalParams", slots = c(Emigration = "EmigrationParams",
Transfer = "TransferParams",
Settlement = "SettlementParams")
, prototype = list(Emigration = Emigration(),
@@ -2085,14 +2085,14 @@ Dispersal <- setClass("DispersalParams", slots = c(Emigration = "EmigrationParam
setValidity("DispersalParams", function(object) {
msg <- NULL
- validObject(object@Emigration)
+ methods::validObject(object@Emigration)
if (object@Emigration@UseFullKern) {
if (!class(object@Transfer)[1] == "DispersalKernel") {
msg <- c(msg, "Dispersal(): The emigration option \"UseFullKern\" can only be used if a dispersal kernel is used as transfer method!")
}
}
- validObject(object@Transfer)
- validObject(object@Settlement)
+ methods::validObject(object@Transfer)
+ methods::validObject(object@Settlement)
if (class(object@Transfer)[1] == "DispersalKernel") {
if (object@Settlement@DensDep) {
msg <- c(msg, "Dispersal(): Settlement can only be density-dependent (DensDep = TRUE) if a movement process is used as transfer method!")
@@ -2107,9 +2107,9 @@ setValidity("DispersalParams", function(object) {
setMethod("initialize", "DispersalParams", function(.Object,...) {
this_func = "Dispersal(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
.Object}
)
diff --git a/RangeShiftR/R/class_GeneticsParams.R b/RangeShiftR/R/class_GeneticsParams.R
index de519f4..9fa855a 100644
--- a/RangeShiftR/R/class_GeneticsParams.R
+++ b/RangeShiftR/R/class_GeneticsParams.R
@@ -190,7 +190,7 @@
#' @author Anne-Kathleen Malchow
#' @name Genetics
#' @export Genetics
-Genetics <- setClass("GeneticsParams", slots = c(Architecture = "integer_OR_numeric",
+Genetics <- methods::setClass("GeneticsParams", slots = c(Architecture = "integer_OR_numeric",
NLoci = "integer_OR_numeric",
ArchFile = "character",
ProbMutn = "numeric",
@@ -268,7 +268,7 @@ setValidity('GeneticsParams', function(object){
setMethod('initialize', 'GeneticsParams', function(.Object, ...) {
this_func = "Genetics(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if(.Object@Architecture == 0) {
if (!is.null(args$ArchFile)) {
warning(this_func, "ArchFile", warn_msg_ignored, "since Architecture = 0 (one chromosome per trait).", call. = FALSE)
diff --git a/RangeShiftR/R/class_InitialisationParams.R b/RangeShiftR/R/class_InitialisationParams.R
index 6fccbf7..bf60612 100644
--- a/RangeShiftR/R/class_InitialisationParams.R
+++ b/RangeShiftR/R/class_InitialisationParams.R
@@ -157,7 +157,7 @@
#' @author Anne-Kathleen Malchow
#' @name Initialise
#' @export Initialise
-Initialise <- setClass("InitialisationParams", slots = c(InitType = "integer_OR_numeric",
+Initialise <- methods::setClass("InitialisationParams", slots = c(InitType = "integer_OR_numeric",
FreeType = "integer_OR_numeric",
SpType = "integer_OR_numeric",
NrCells = "integer_OR_numeric",
@@ -415,7 +415,7 @@ setValidity('InitialisationParams', function(object){
setMethod('initialize', 'InitialisationParams', function(.Object, ...) {
this_func = "Initialise(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if (.Object@InitType != 0) {
.Object@FreeType = -9L
if (!is.null(args$FreeType)) {
diff --git a/RangeShiftR/R/class_LandParams.R b/RangeShiftR/R/class_LandParams.R
index 1c73d10..030cb0c 100644
--- a/RangeShiftR/R/class_LandParams.R
+++ b/RangeShiftR/R/class_LandParams.R
@@ -26,7 +26,7 @@
# from RS 'Land' file
# can take one of two forms: 'ArtificialLandscape' or 'ImportedLandscape'
-LandParams <- setClass("LandParams", slots = c(LandNum = "integer_OR_numeric")
+LandParams <- methods::setClass("LandParams", slots = c(LandNum = "integer_OR_numeric")
, prototype = list(LandNum = 1L)
)
# landscape number must be unique
@@ -44,7 +44,7 @@ setValidity("LandParams", function(object) {
if (is.null(msg)) TRUE else msg}
)
setMethod("initialize", "LandParams", function(.Object, ...) {
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
.Object}
)
@@ -100,7 +100,8 @@ setMethod("initialize", "LandParams", function(.Object, ...) {
#' @author Anne-Kathleen Malchow
#' @name ArtificialLandscape
#' @export ArtificialLandscape
-ArtificialLandscape <- setClass("ArtificialLandscape", slots = c(propSuit = "numeric",
+#' @importFrom methods new
+ArtificialLandscape <- methods::setClass("ArtificialLandscape", slots = c(propSuit = "numeric",
K_or_DensDep = "integer_OR_numeric",
Resolution = "integer_OR_numeric",
dimX = "integer_OR_numeric",
@@ -122,7 +123,7 @@ ArtificialLandscape <- setClass("ArtificialLandscape", slots = c(propSuit = "num
#maxPct,
, contains = "LandParams")
-setValidity("ArtificialLandscape", function(object) {
+methods::setValidity("ArtificialLandscape", function(object) {
msg <- NULL
if (anyNA(object@propSuit) || length(object@propSuit)!=1) {
msg <- c(msg, "Proportion of suitable habitat must be set and of length 1!")
@@ -233,12 +234,12 @@ setValidity("ArtificialLandscape", function(object) {
}
if (is.null(msg)) TRUE else msg}
)
-setMethod("initialize", "ArtificialLandscape", function(.Object,...) {
+methods::setMethod("initialize", "ArtificialLandscape", function(.Object,...) {
this_func = "ArtificialLandscape(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (!.Object@fractal) {
.Object@hurst = -9L
@@ -258,7 +259,7 @@ setMethod("initialize", "ArtificialLandscape", function(.Object,...) {
}
.Object}
)
-setMethod("show", "ArtificialLandscape", function(object){
+methods::setMethod("show", "ArtificialLandscape", function(object){
cat(" Artificial landscape: ")
#cat(" Artificial landscape #", object@LandNum, ": ")
if(object@fractal) {
@@ -531,9 +532,9 @@ setValidity("ImportedLandscape", function(object) {
setMethod("initialize", "ImportedLandscape", function(.Object, ...) {
this_func = "ImportedLandscape(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if (.Object@HabPercent) {
.Object@Nhabitats = 1L
diff --git a/RangeShiftR/R/class_RSparams.R b/RangeShiftR/R/class_RSparams.R
index b417103..1df83e6 100644
--- a/RangeShiftR/R/class_RSparams.R
+++ b/RangeShiftR/R/class_RSparams.R
@@ -30,7 +30,7 @@
#' @include class_DispersalParams.R
#' @include class_GeneticsParams.R
#' @include class_InitialisationParams.R
-RSparams <- setClass("RSparams", slots = c(control = "ControlParams",
+RSparams <- methods::setClass("RSparams", slots = c(control = "ControlParams",
simul = "SimulationParams",
land = "LandParams",
demog = "DemogParams",
@@ -41,9 +41,9 @@ RSparams <- setClass("RSparams", slots = c(control = "ControlParams",
setValidity("RSparams", function(object) {
msg <- NULL
#CONTROL
- validObject(object@control)
+ methods::validObject(object@control)
#SIMULATION
- validObject(object@simul)
+ methods::validObject(object@simul)
if (object@control@patchmodel) {
if (object@simul@Gradient) {
msg <- c(msg, "Environmental gradients are not implemented for patch-based models!")
@@ -82,7 +82,7 @@ setValidity("RSparams", function(object) {
}
}
#LAND
- validObject(object@land)
+ methods::validObject(object@land)
if (any(object@control@landtype==c(0,2))){
if (any(object@land@DynamicLandYears>object@simul@Years)) {
warning("ImportedLandscape(): Dynamic landscape contains years that exceed the simulated years, so that some land changes will not apply.", call. = FALSE)
@@ -99,9 +99,9 @@ setValidity("RSparams", function(object) {
}
}
#DEMOGRAPHY
- validObject(object@demog)
+ methods::validObject(object@demog)
#DISPERSAL
- validObject(object@dispersal)
+ methods::validObject(object@dispersal)
## Emigration: check dimensions and values of EmigProb and EmigStage:
# check StageDep and SexDep
dim_ok = TRUE
@@ -211,19 +211,19 @@ setValidity("RSparams", function(object) {
}
else {
if(any(object@dispersal@Emigration@EmigProb[,(offset+2)] > object@dispersal@Emigration@TraitScaleFactor[1])) {
- msg <- c(msg, paste0("Column ", (offset+2), " of emigration traits matrix (EmigProb) must contain sd(D0), with values less than or equal to TraitScaleFactor μ(D0)!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of emigration traits matrix (EmigProb) must contain sd(D0), with values less than or equal to TraitScaleFactor mu(D0)!"))
}
}
if (object@dispersal@Emigration@DensDep) {
if(any(object@dispersal@Emigration@EmigProb[,c((offset+4),(offset+6))]<=0 )){
- msg <- c(msg, paste0("Columns ", (offset+4), " and ", (offset+6), " of emigration traits matrix (EmigProb) must contain sd(α) and sd(β), with strictly positive values!"))
+ msg <- c(msg, paste0("Columns ", (offset+4), " and ", (offset+6), " of emigration traits matrix (EmigProb) must contain sd(alpha) and sd(beta), with strictly positive values!"))
}
else {
if(any(object@dispersal@Emigration@EmigProb[,(offset+4)] > object@dispersal@Emigration@TraitScaleFactor[2])) {
- msg <- c(msg, paste0("Column ", (offset+4), " of emigration traits matrix (EmigProb) must contain sd(α), with values less than or equal to TraitScaleFactor μ(α)!"))
+ msg <- c(msg, paste0("Column ", (offset+4), " of emigration traits matrix (EmigProb) must contain sd(alpha), with values less than or equal to TraitScaleFactor mu(alpha)!"))
}
if(any(object@dispersal@Emigration@EmigProb[,(offset+6)] > object@dispersal@Emigration@TraitScaleFactor[3])) {
- msg <- c(msg, paste0("Column ", (offset+6), " of emigration traits matrix (EmigProb) must contain sd(β), with values less than or equal to TraitScaleFactor μ(β)!"))
+ msg <- c(msg, paste0("Column ", (offset+6), " of emigration traits matrix (EmigProb) must contain sd(beta), with values less than or equal to TraitScaleFactor mu(beta)!"))
}
}
}
@@ -348,25 +348,25 @@ setValidity("RSparams", function(object) {
if (object@dispersal@Transfer@IndVar) {
if (object@dispersal@Transfer@DoubleKernel) {
if(any(object@dispersal@Transfer@Distances[,(offset+1)]= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
+ msg <- c(msg, paste0("Column ", (offset+1), " of dispersal kernel traits (Distances) matrix must contain the mean of the mean distance of Kernel 1, mean(delta1), with values >= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
}
if(any(object@dispersal@Transfer@Distances[,(offset+2)]<=0.0)){
- msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance of Kernel 1, sd(δ1), with strictly positive values!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance of Kernel 1, sd(delta1), with strictly positive values!"))
}
else {
if(any(object@dispersal@Transfer@Distances[,(offset+2)] > object@dispersal@Transfer@TraitScaleFactor[1])) {
- msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain sd(δ1), with values less than or equal to TraitScaleFactor μ(δ1)!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain sd(delta1), with values less than or equal to TraitScaleFactor mu(delta1)!"))
}
}
if(any(object@dispersal@Transfer@Distances[,(offset+3)]= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
+ msg <- c(msg, paste0("Column ", (offset+3), " of dispersal kernel traits (Distances) matrix must contain the mean of the mean distance of Kernel 2, mean(delta2), with values >= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
}
if(any(object@dispersal@Transfer@Distances[,(offset+4)]<=0.0)){
- msg <- c(msg, paste0("Column ", (offset+4), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance of Kernel 2, sd(δ2), with strictly positive values!"))
+ msg <- c(msg, paste0("Column ", (offset+4), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance of Kernel 2, sd(delta2), with strictly positive values!"))
}
else {
if(any(object@dispersal@Transfer@Distances[,(offset+4)] > object@dispersal@Transfer@TraitScaleFactor[2])) {
- msg <- c(msg, paste0("Column ", (offset+4), " of dispersal kernel traits (Distances) matrix must contain sd(δ2), with values less than or equal to TraitScaleFactor μ(δ2)!"))
+ msg <- c(msg, paste0("Column ", (offset+4), " of dispersal kernel traits (Distances) matrix must contain sd(delta2), with values less than or equal to TraitScaleFactor mu(delta2)!"))
}
}
if(any(object@dispersal@Transfer@Distances[,(offset+5)]<=0.0 | object@dispersal@Transfer@Distances[,(offset+5)]>=1.0)){
@@ -377,20 +377,20 @@ setValidity("RSparams", function(object) {
}
else {
if(any(object@dispersal@Transfer@Distances[,(offset+6)] > object@dispersal@Transfer@TraitScaleFactor[3])) {
- msg <- c(msg, paste0("Column ", (offset+6), " of dispersal kernel traits (Distances) matrix must contain sd(p), with values less than or equal to TraitScaleFactor μ(p)!"))
+ msg <- c(msg, paste0("Column ", (offset+6), " of dispersal kernel traits (Distances) matrix must contain sd(p), with values less than or equal to TraitScaleFactor mu(p)!"))
}
}
}
else { # !DoubleKernel
if(any(object@dispersal@Transfer@Distances[,(offset+1)]= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
+ msg <- c(msg, paste0("Column ", (offset+1), " of dispersal kernel traits (Distances) matrix must contain the mean of the mean distance, mean(delta), with values >= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
}
if(any(object@dispersal@Transfer@Distances[,(offset+2)]<=0.0)){
- msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance, sd(δ), with strictly positive values!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain the std. dev. of the mean distance, sd(delta), with strictly positive values!"))
}
else {
if(any(object@dispersal@Transfer@Distances[,(offset+2)] > object@dispersal@Transfer@TraitScaleFactor[1])) {
- msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain sd(δ), with values less than or equal to TraitScaleFactor μ(δ)!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain sd(delta), with values less than or equal to TraitScaleFactor mu(delta)!"))
}
}
}
@@ -398,7 +398,7 @@ setValidity("RSparams", function(object) {
else { # !IndVar
if (object@dispersal@Transfer@DoubleKernel) {
if(any(object@dispersal@Transfer@Distances[,(offset+1):(offset+2)]= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
+ msg <- c(msg, paste0("Columns ", (offset+1), " and ", (offset+2), " of dispersal kernel traits (Distances) matrix must contain the two mean distance delta1 and delta2, with values >= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
}
if(any(object@dispersal@Transfer@Distances[,(offset+3)]<=0 | object@dispersal@Transfer@Distances[,(offset+3)]>=1)) {
msg <- c(msg, paste0("Column ", (offset+3), " of dispersal kernel traits (Distances) matrix must contain the probability p of using kernel 1, with values in the open interval (0,1) !"))
@@ -406,7 +406,7 @@ setValidity("RSparams", function(object) {
}
else{
if(any(object@dispersal@Transfer@Distances[,(offset+1)]= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
+ msg <- c(msg, paste0("Column ", (offset+1), " of dispersal kernel traits (Distances) matrix must contain the mean distance delta, with values >= ", (resol), " (=landscape resolution (unless UseFullKernel=TRUE)) !"))
}
}
}
@@ -617,18 +617,18 @@ setValidity("RSparams", function(object) {
}
else {
if(any(object@dispersal@Settlement@Settle[,(offset+2)] > object@dispersal@Settlement@TraitScaleFactor[1])) {
- msg <- c(msg, paste0("Column ", (offset+2), " of settlement traits matrix (Settle) must contain sd(S0), with values less than or equal to TraitScaleFactor μ(S0)!"))
+ msg <- c(msg, paste0("Column ", (offset+2), " of settlement traits matrix (Settle) must contain sd(S0), with values less than or equal to TraitScaleFactor mu(S0)!"))
}
}
if(any(object@dispersal@Settlement@Settle[,c((offset+4),(offset+6))]<=0 )){
- msg <- c(msg, paste0("Columns ", (offset+4), " and ", (offset+6), " of settlement traits matrix (Settle) must contain sd(α_s) and sd(β_s), with strictly positive values!"))
+ msg <- c(msg, paste0("Columns ", (offset+4), " and ", (offset+6), " of settlement traits matrix (Settle) must contain sd(alpha_s) and sd(beta_s), with strictly positive values!"))
}
else {
if(any(object@dispersal@Settlement@Settle[,(offset+4)] > object@dispersal@Settlement@TraitScaleFactor[2])) {
- msg <- c(msg, paste0("Column ", (offset+4), " of settlement traits matrix (Settle) must contain sd(α_s), with values less than or equal to TraitScaleFactor μ(α_s)!"))
+ msg <- c(msg, paste0("Column ", (offset+4), " of settlement traits matrix (Settle) must contain sd(alpha_s), with values less than or equal to TraitScaleFactor mu(alpha_s)!"))
}
if(any(object@dispersal@Settlement@Settle[,(offset+6)] > object@dispersal@Settlement@TraitScaleFactor[3])) {
- msg <- c(msg, paste0("Column ", (offset+6), " of settlement traits matrix (Settle) must contain sd(β_s), with values less than or equal to TraitScaleFactor μ(β_s)!"))
+ msg <- c(msg, paste0("Column ", (offset+6), " of settlement traits matrix (Settle) must contain sd(beta_s), with values less than or equal to TraitScaleFactor mu(beta_s)!"))
}
}
}
@@ -675,13 +675,13 @@ setValidity("RSparams", function(object) {
}
#GENETICS
- validObject(object@gene)
+ methods::validObject(object@gene)
if(any(object@dispersal@Emigration@IndVar,object@dispersal@Transfer@IndVar,object@dispersal@Settlement@IndVar)) anyIndVar <- TRUE
else anyIndVar <- FALSE
# if( ...(object@gene) & !anyIndVar) # TODO: check if genetics module is set but no variable traits -> give warning in this case
#INITIALISATION
- validObject(object@init)
+ methods::validObject(object@init)
if (object@control@landtype == 9) { # artificial land
if (object@init@InitType) {
msg <- c(msg, 'Initialise(): InitType must be set to 0 (Free initialisation) for an artificial landscape!')
diff --git a/RangeShiftR/R/class_SimulationParams.R b/RangeShiftR/R/class_SimulationParams.R
index 06c73a6..03023bb 100644
--- a/RangeShiftR/R/class_SimulationParams.R
+++ b/RangeShiftR/R/class_SimulationParams.R
@@ -149,7 +149,7 @@
#' The local heterogeneity is determined by a random number drawn from a uniform distribution between \eqn{-1} and \eqn{1} for each cell
#' and \code{f}, the local scaling factor that determines the magnitude of this stochastic local variation relative to the extremal value.
#'
-#' The gradient in fecundity φ applies to the fecundity of each stage. Negative local values in \eqn{z(x,y)} are set to \eqn{0}.
+#' The gradient in fecundity \eqn{\phi} applies to the fecundity of each stage. Negative local values in \eqn{z(x,y)} are set to \eqn{0}.
#'
#' It is also possible to simulate the shifting of the gradient by setting the option \code{Shifting}. Here the position \eqn{y} of the species’
#' optimum is shifted northwards (increasing \eqn{y}) at a given rate \code{ShiftRate} (in units of rows per year),
@@ -166,18 +166,18 @@
#' \emph{Environmental Stochasticity}\cr
#' It is possible to model environmental stochasticity via the option \code{EnvStoch} acting at a global or local scale
#' and can be applied to \code{K_or_DensDep}, the demographic density dependence (\code{EnvStoch=1}), or to growth rate / fecundity (\code{EnvStoch=0}).
-#' It is implemented using a first order autoregressive process to generate time series of the noise value \eqn{ε}
+#' It is implemented using a first order autoregressive process to generate time series of the noise value \eqn{\epsilon}
#' \insertCite{ruokolainen2009}{RangeShiftR}:
#'
-#' \deqn{ε(t+1) = κ ε(t) + \omega(t) \sqrt(1-\kappa^2)}
+#' \deqn{\epsilon(t+1) = \kappa \epsilon(t) + \omega(t) \sqrt(1-\kappa^2)}
#'
-#' where κ is the autocorrelation coefficient (\code{ac}) and ω is a random normal variable drawn from \eqn{N(0,σ)}.
-#' Changing σ (\code{std}) changes the magnitude of the fluctuations. The spatial scale of the variation can either be global (a single time series
+#' where \eqn{\kappa} is the autocorrelation coefficient (\code{ac}) and \eqn{\omega} is a random normal variable drawn from \eqn{N(0,\sigma)}.
+#' Changing \eqn{\sigma} (\code{std}) changes the magnitude of the fluctuations. The spatial scale of the variation can either be global (a single time series
#' for the entire landscape) or local (each cell fluctuates independently), and is always applied on a yearly basis.
#' Different degrees of spatial autocorrelation are not implemented in the current version.
#'
#' The noise affects the species' selected parameter \eqn{Z} as follows:
-#' \deqn{Z(x,y,t) = Z(x,y,0) + Z ε(t)}
+#' \deqn{Z(x,y,t) = Z(x,y,0) + Z \epsilon(t)}
#' where \eqn{x} and \eqn{y} are the cell coordinates and \eqn{Z} is the original parameter value in absence of stochasticity and gradients.
#' In the presence of an environmental gradient, \eqn{Z(x,y,0)} is the gradient value at the cell location, otherwise its equal to \eqn{Z}.
#' The resulting values \eqn{Z(x,y,t)} are limited to the maximum and minimum values \code{minR,maxR} or \code{minK,maxK}, respectively.
@@ -187,7 +187,7 @@
#' All the output files will be named with a standard name reporting the simulation ID number and
#' the type of output. The file name will start with the batch number, and also indicate the number
#' of the landscape to which the output refers. Additionally, for each simulation all the set parameters
-#' will be automatically written to a text file named \"Sim0_Parameters.txt\" in the case of simulation\eqn{#=0}.
+#' will be automatically written to a text file named \"Sim0_Parameters.txt\" in the case of simulation\eqn{=0}.
#'
#' - \emph{Species range} (\code{Sim0_Range.txt}) \cr
#' contains the following general information regarding the species’ range:\cr
@@ -308,7 +308,7 @@
#' \insertAllCited{}
#' @name Simulation
#' @export Simulation
-Simulation <- setClass("SimulationParams", slots = c(Simulation = "integer_OR_numeric",
+Simulation <- methods::setClass("SimulationParams", slots = c(Simulation = "integer_OR_numeric",
Replicates = "integer_OR_numeric",
Years = "integer_OR_numeric",
Absorbing = "logical",
@@ -852,9 +852,9 @@ setValidity('SimulationParams', function(object){
setMethod("initialize", "SimulationParams", function(.Object, ...) {
this_func = "Simulation(): "
args <- list(...)
- .Object <- callNextMethod()
+ .Object <- methods::callNextMethod()
if ( length(args) == 0 ) {
- validObject(.Object)
+ methods::validObject(.Object)
}
if(.Object@Gradient == 0){
.Object@GradSteep = -9L
diff --git a/RangeShiftR/R/output_handling.R b/RangeShiftR/R/output_handling.R
index fc42dfb..019c4a4 100644
--- a/RangeShiftR/R/output_handling.R
+++ b/RangeShiftR/R/output_handling.R
@@ -43,7 +43,7 @@ setGeneric("readRange", function(s,dirpath) standardGeneric("readRange") )
setMethod("readRange", c(s="RSparams", dirpath="character"), function(s,dirpath) {
path <- paste0(dirpath, "Outputs/Batch", s@control@batchnum, "_Sim", s@simul@Simulation, "_Land", s@land@LandNum, "_Range.txt")
if(file.exists(path)){
- return(read.table(path, h = T, sep = "\t"))
+ return(utils::read.table(path, h = T, sep = "\t"))
}else {
warning("The 'range' output file for this simulation does not exist.", call. = FALSE)
}
@@ -64,7 +64,7 @@ setGeneric("readPop", function(s,dirpath,...) standardGeneric("readPop") )
setMethod("readPop", c(s="RSparams", dirpath="character"), function(s,dirpath,center=TRUE) {
path <- paste0(dirpath, "Outputs/Batch", s@control@batchnum, "_Sim", s@simul@Simulation, "_Land", s@land@LandNum, "_Pop.txt")
if(file.exists(path)){
- pop_table <- read.table(path, h = T, sep = "\t")
+ pop_table <- utils::read.table(path, h = T, sep = "\t")
if (sum(grepl('x',names(pop_table))) & center){
pop_table$x <- (pop_table$x+0.5)*s@land@Resolution
pop_table$y <- (pop_table$y+0.5)*s@land@Resolution
@@ -136,7 +136,7 @@ setMethod("ColonisationStats", "data.frame", function(x, y = NULL, years = numer
digitsY <- ifelse(maxY < 1, 0, floor(log10(maxY)) + 1)
x$PatchID <- (x$x*(10^digitsY)) + (x$y) #+ (maxY+1-x$y)
}
-
+ NInd <- NULL # not used, necessary to pass CRAN check
x <- subset(x, NInd>0, select = c("Rep","PatchID","Year","NInd") )
reps <- sort(unique(x$Rep))
n=length(reps)
@@ -285,13 +285,13 @@ setMethod("ColonisationStats", "data.frame", function(x, y = NULL, years = numer
patch_outstack <- c(patch_outstack, patch_occ_prob)
terra::values(patch_outstack[[j]])[value_ix] <- occ_prob[,j+2]
}
- crs(patch_outstack) <- NA
+ terra::crs(patch_outstack) <- NA
#} else{
# raster::values(patch_occ_prob)[value_ix] <- occ_prob[,1]
# patch_outstack <- patch_occ_prob
#}
terra::values(patch_col_time)[value_ix] <- ifelse(is.na(col_time_mean[]),-9,col_time_mean[])
- crs(patch_col_time) <- NA
+ terra::crs(patch_col_time) <- NA
return(list(occ_prob=occ_prob, col_time=col_time, map_occ_prob=patch_outstack, map_col_time=patch_col_time))
@@ -351,7 +351,7 @@ setMethod("ColonisationStats", "RSparams", function(x, y = getwd(), years = nume
if ( class(patch_curr) == "try-error" ) warning("ColonisationStats(): Couldn't read patch raster file nr ", current , " for this simulation.", call. = FALSE)
else patch_r <- c(patch_r , patch_curr)
- if(class(pop_df) == "data.frame" & nlyr(patch_r)==(length(years)+1) ) res <- ColonisationStats(pop_df,patch_r,years)
+ if(class(pop_df) == "data.frame" & terra::nlyr(patch_r)==(length(years)+1) ) res <- ColonisationStats(pop_df,patch_r,years)
}
}else{
# for cell-based model, read only main habitat maps to use as raster template
@@ -398,10 +398,10 @@ setGeneric("plotAbundance", function(s,...) standardGeneric("plotAbundance") )
setMethod("plotAbundance", "data.frame", function(s, sd = FALSE, replicates = TRUE, ylim=NULL, ...) {
# Calculate means
- rep_means <- aggregate(NInds~Year, data = s, FUN = "mean")
+ rep_means <- stats::aggregate(NInds~Year, data = s, FUN = "mean")
# Calculate standard deviation
if (sd) {
- rep_sd <- aggregate(NInds~Year, data = s, FUN = "sd")
+ rep_sd <- stats::aggregate(NInds~Year, data = s, FUN = "sd")
rep_sd[is.na(rep_sd)] <- 0
}
# Set y-limits
@@ -420,16 +420,16 @@ setMethod("plotAbundance", "data.frame", function(s, sd = FALSE, replicates = TR
plot(NULL, type = "n", ylab = "Abundance", xlab = "Year", xlim=c(0, max(s$Year)), ylim=ylim, ...)
# Plot standard deviation
if (sd) {
- polygon(c(rep_sd$Year,rev(rep_sd$Year)), c(rep_means$NInds+rep_sd$NInds, rev(pmax(0,rep_means$NInds-rep_sd$NInds))), border=NA, col='grey80')
+ graphics::polygon(c(rep_sd$Year,rev(rep_sd$Year)), c(rep_means$NInds+rep_sd$NInds, rev(pmax(0,rep_means$NInds-rep_sd$NInds))), border=NA, col='grey80')
}
# Plot replicates
if (replicates) {
for (i in 0:max(s$Rep)) {
- lines(s$Year[s$Rep==i], s$NInds[s$Rep==i], type = "l", lwd = 0.5)
+ graphics::lines(s$Year[s$Rep==i], s$NInds[s$Rep==i], type = "l", lwd = 0.5)
}
}
# Plot abundance
- lines(rep_means$Year, rep_means$NInds, type = "l", lwd = 3, col = "red")
+ graphics::lines(rep_means$Year, rep_means$NInds, type = "l", lwd = 3, col = "red")
})
setMethod("plotAbundance", "RSparams", function(s, dirpath, ...) {
if (class(dirpath)=="character"){
@@ -458,10 +458,10 @@ setGeneric("plotOccupancy", function(s,...) standardGeneric("plotOccupancy") )
setMethod("plotOccupancy", "data.frame", function(s, sd = FALSE, replicates = TRUE, ylim=NULL, ...) {
names(s)[grep('NOccup',names(s))] <- 'NOccup'
# Calculate means
- rep_means <- aggregate(NOccup~Year, data = s, FUN = "mean")
+ rep_means <- stats::aggregate(NOccup~Year, data = s, FUN = "mean")
# Calculate standard deviation
if (sd) {
- rep_sd <- aggregate(NOccup~Year, data = s, FUN = "sd")
+ rep_sd <- stats::aggregate(NOccup~Year, data = s, FUN = "sd")
rep_sd[is.na(rep_sd)] <- 0
}
# Set y-limits
@@ -480,16 +480,16 @@ setMethod("plotOccupancy", "data.frame", function(s, sd = FALSE, replicates = TR
plot(NULL, type = "n", ylab = "Occupancy", xlab = "Year", xlim=c(0, max(s$Year)), ylim=ylim, ...)
# Plot standard deviation
if (sd) {
- polygon(c(rep_sd$Year,rev(rep_sd$Year)), c(rep_means$NOccup+rep_sd$NOccup, rev(pmax(0,rep_means$NOccup-rep_sd$NOccup))), border=NA, col='grey80')
+ graphics::polygon(c(rep_sd$Year,rev(rep_sd$Year)), c(rep_means$NOccup+rep_sd$NOccup, rev(pmax(0,rep_means$NOccup-rep_sd$NOccup))), border=NA, col='grey80')
}
# plot replicates
if (replicates) {
for (i in 0:max(s$Rep)) {
- lines(s$Year[s$Rep==i], s$NOccup[s$Rep==i], type = "l", lwd = 0.5)
+ graphics::lines(s$Year[s$Rep==i], s$NOccup[s$Rep==i], type = "l", lwd = 0.5)
}
}
# Plot occupancy
- lines(rep_means$Year, rep_means$NOccup, type = "l", lwd = 3, col = "blue")
+ graphics::lines(rep_means$Year, rep_means$NOccup, type = "l", lwd = 3, col = "blue")
})
setMethod("plotOccupancy", "RSparams", function(s, dirpath, ...) {
if (class(dirpath)=="character"){
@@ -537,7 +537,7 @@ setMethod("SMSpathLengths", c(s="RSparams", dirpath="character"), function(s,dir
null_tb <- rep(0,maxLength)
names(null_tb) <- sapply(1:maxLength, FUN=paste0)
for(i in 0:(s@simul@Replicates-1)){
- steps <- try(read.table(paste0(dirpath,
+ steps <- try(utils::read.table(paste0(dirpath,
"Outputs/Batch",s@control@batchnum,
"_Sim",s@simul@Simulation,
"_Land",s@land@LandNum,
@@ -551,10 +551,10 @@ setMethod("SMSpathLengths", c(s="RSparams", dirpath="character"), function(s,dir
steps_y <- sapply(seq(nr_maps), FUN = function(y){
tb <- null_tb
lo <- year_blocks[y]
- if (y==nr_maps) tb_n <- table(aggregate(Step~IndID, data=subset(steps, Year >= lo), FUN = max)$Step)
+ if (y==nr_maps) tb_n <- table(stats::aggregate(Step~IndID, data=subset(steps, Year >= lo), FUN = max)$Step)
else {
up <- year_blocks[y+1]
- tb_n <- table(aggregate(Step~IndID, data=subset(steps, Year >= lo & Year < up), FUN = max)$Step)
+ tb_n <- table(stats::aggregate(Step~IndID, data=subset(steps, Year >= lo & Year < up), FUN = max)$Step)
}
ix <- names(tb) %in% names(tb_n)
tb[ix] <- tb_n[1:sum(ix)]
@@ -855,9 +855,9 @@ setMethod("getLocalisedEquilPop", "DemogParams", function(demog, DensDep_values,
xlabs <- print(DensDep_values, digits = 2)
# which stages to plot?
if(is.null(stages_out)) stages_out = seq((!juv.stage),demog@StageStruct@Stages-1)
- colors <- hcl.colors(length(stages_out), palette = "Harmonic")
+ colors <- grDevices::hcl.colors(length(stages_out), palette = "Harmonic")
if(demog@ReproductionType <2){
- barplot(res[as.character(stages_out),], names.arg = xlabs, beside = F, col = colors,
+ graphics::barplot(res[as.character(stages_out),], names.arg = xlabs, beside = F, col = colors,
main = "Localised equilibrium densities", xlab = "1/b", ylab = "Population density")
}
if(demog@ReproductionType==2){
@@ -868,13 +868,13 @@ setMethod("getLocalisedEquilPop", "DemogParams", function(demog, DensDep_values,
fem <- seq.int(2,length(stages_out)*2,2)
res_2 <- cbind(res_2[mal,1:length(DensDep_values)],res_2[fem,1:length(DensDep_values)])
res_2 <- cbind(res_2[,c(sapply(1:length(DensDep_values), function(i){c(0,1)*length(DensDep_values)+i}))])
- barplot(res_2, space=c(0.3,0.1), names.arg = c(rbind(xlabs,NA)), beside = F, col = rep(colors, 2),
+ graphics::barplot(res_2, space=c(0.3,0.1), names.arg = c(rbind(xlabs,NA)), beside = F, col = rep(colors, 2),
main = "Localised equilibrium densities", xlab = "1/b", ylab = "Population density")
- text(seq(0.5,length(DensDep_values)*2,2)*1.2, colSums(res_2[,seq(1,length(DensDep_values)*2,2)])*1.1, "m", cex=1, col="black")
- text(seq(1.5,length(DensDep_values)*2,2)*1.2, colSums(res_2[,seq(2,length(DensDep_values)*2,2)])*1.1, "f", cex=1, col="black")
+ graphics::text(seq(0.5,length(DensDep_values)*2,2)*1.2, colSums(res_2[,seq(1,length(DensDep_values)*2,2)])*1.1, "m", cex=1, col="black")
+ graphics::text(seq(1.5,length(DensDep_values)*2,2)*1.2, colSums(res_2[,seq(2,length(DensDep_values)*2,2)])*1.1, "f", cex=1, col="black")
}
}
- legend("topleft", legend = rev(sapply(stages_out, function(s){paste("Stage",s)})), col = rev(colors), pch = 16)
+ graphics::legend("topleft", legend = rev(sapply(stages_out, function(s){paste("Stage",s)})), col = rev(colors), pch = 16)
}
# return equilibrium population densities
return(res)
diff --git a/RangeShiftR/R/plotProbs.R b/RangeShiftR/R/plotProbs.R
index bcd6b00..0c6bebe 100644
--- a/RangeShiftR/R/plotProbs.R
+++ b/RangeShiftR/R/plotProbs.R
@@ -49,21 +49,21 @@
#' If a mixed kernel was defined (i.e. \code{DoubleKernel=TRUE}), plot the resulting dispersal probability by...
#' \itemize{
#' \item \code{combinekernels=FALSE} - ...plotting both kernels separately (default)
-#' \item \code{combinekernels= TRUE} - ...combining both kernels, i.e. \ifelse{html}{ \out{p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1) } }{\deqn{ p(d; δ_1,δ_2) = p_I p(d;δ_1) + (1-p_I) p(d;δ_2)} }
+#' \item \code{combinekernels= TRUE} - ...combining both kernels, i.e. \ifelse{html}{ \out{p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1) } }{\deqn{ p(d; \delta_1,\delta_2) = p_I p(d;\delta_1) + (1-p_I) p(d;\delta_2)} }
#' }
#' \item \code{\link[RangeShiftR]{StageStructure}}: plot fecundity as well as survival and development probabilities.
#'
#' Survival and development are calculated based on the transition matrix. Consider e.g. a 3 stage matrix with a transition matrix of
#'
-#' \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{φ_2}} \cr
-#' \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{σ_1 (1 − γ_(1-2))}} \tab | \tab \eqn{0} \cr
-#' \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{σ_1 γ_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{σ_2}} \cr}
+#' \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{\phi_2}} \cr
+#' \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{\sigma_1 (1 - \gamma_(1-2))}} \tab | \tab \eqn{0} \cr
+#' \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{\sigma_1 \gamma_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{\sigma_2}} \cr}
#'
#' The survival probability is calculated as the sum of the probability to stay in the same stage and the probability to reach the next stage.
-#' E.g. for stage 1: \ifelse{html}{\out{σ1 = sum( σ1 (1-γ1-2), σ1 γ1-2}}{\eqn{σ_1 = sum(σ_1 (1 − γ_(1-2)), σ_1 γ_(1-2))}}
+#' E.g. for stage 1: \ifelse{html}{\out{σ1 = sum( σ1 (1-γ1-2), σ1 γ1-2}}{\eqn{\sigma_1 = sum(\sigma_1 (1 - \gamma_(1-2)), \sigma_1 \gamma_(1-2))}}
#'
#' The development probability of stage 1 to stage 2 is the ratio of the probability to reach stage 2 and the previously calculated survival probability.
-#' E.g. for stage 1: \ifelse{html}{\out{γ1-2 = σ1 γ1-2 / σ1}}{\eqn{γ_(1-2) = σ_1 / (σ_1 γ_(1-2) )}}
+#' E.g. for stage 1: \ifelse{html}{\out{γ1-2 = σ1 γ1-2 / σ1}}{\eqn{\gamma_(1-2) = \sigma_1 / (\sigma_1 \gamma_(1-2) )}}
#' }
#' @export
setGeneric("plotProbs", function(x, ...) standardGeneric("plotProbs") )
diff --git a/RangeShiftR/man/CorrRW.Rd b/RangeShiftR/man/CorrRW.Rd
index 4c057c8..869e739 100644
--- a/RangeShiftR/man/CorrRW.Rd
+++ b/RangeShiftR/man/CorrRW.Rd
@@ -14,7 +14,7 @@ CorrRW(StepLength = 1, Rho = 0.5,
\item{StepLength}{Step length given in meters, defaults to \eqn{1}.\cr If \code{IndVar=TRUE}, expects a vector of length three
specifying (Mean, SD, TraitScaleFactor) of \code{StepLength}.}
-\item{Rho}{Correlation parameter \eqn{ρ}, defaults to \eqn{0.5}. Must be in the open interval \eqn{(0,1)}.\cr If \code{IndVar=TRUE},
+\item{Rho}{Correlation parameter \eqn{\rho}, defaults to \eqn{0.5}. Must be in the open interval \eqn{(0,1)}.\cr If \code{IndVar=TRUE},
expects a vector of length three specifying (Mean, SD, TraitScaleFactor) of \code{Rho}.}
\item{IndVar}{Individual variability in CorrRW traits (i.e. \code{StepLength} and \code{Rho})? Defaults to \code{FALSE}.}
diff --git a/RangeShiftR/man/Demography.Rd b/RangeShiftR/man/Demography.Rd
index dcd69d7..c460c55 100644
--- a/RangeShiftR/man/Demography.Rd
+++ b/RangeShiftR/man/Demography.Rd
@@ -45,7 +45,7 @@ and for species for which it is considered crucial to model both sexes explicitl
\emph{Asexual / only-female models:} (\code{ReproductionType=0})\cr
Recruitment is determined by a stochastic, individual-based formulation of the \insertCite{smith1973;textual}{RangeShiftR} population model, where the number of offspring produced by a single individual in the cell/patch \eqn{i} at time \eqn{t}, is drawn from the following distribution:\cr
-\ifelse{html}{\out{ Njuv(i,t) = Poisson( R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t))bc ) ) } }{\deqn{N_juv(i,t) = Poisson( R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
+\ifelse{html}{\out{Njuv(i,t) = Poisson( R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t))bc ) ) } }{\deqn{N_juv(i,t) = Poisson( R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
Here, \eqn{R(i,t)} is the maximum growth rate \code{Rmax} (obtained at very low density only) and \eqn{K(i,t)} is the carrying capacity
at patch \eqn{i} and time \eqn{t}.
@@ -61,7 +61,7 @@ In this type of models, individuals are explicitly characterized by their sex. T
This is the simplest form of mate limitation. Each female individual is assumed to mate, as long as there is at least one male in the population. As for the asexual case, the Maynard Smith and Slatkin model is used to determine the expected number of
offspring produced by each female. To maintain equivalence between the asexual and sexual versions, the expected value of the Poisson distribution is multiplied by \eqn{2} (Lindström & Kokko 1998):\cr
-\ifelse{html}{\out{ Njuv(i,t) = Poisson( 2 R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t) )bc ) ) } }{\deqn{N_juv(i,t) = Poisson( 2 R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
+\ifelse{html}{\out{Njuv(i,t) = Poisson( 2 R(i,t) / (1+|R(i,t) - 1| * (N(i,t) / K(i,t) )bc ) ) } }{\deqn{N_juv(i,t) = Poisson( 2 R(i,t) / (1 + |R(i,t) - 1|*( N(i,t) / K(i,t) )^bc ) ) } }
\emph{Complex mating system:} (\code{ReproductionType=2})\cr
More complex and flexible mating system. Mating is explicitly modelled through a mating function
diff --git a/RangeShiftR/man/DispersalKernel.Rd b/RangeShiftR/man/DispersalKernel.Rd
index f7b7cd4..5f8ee72 100644
--- a/RangeShiftR/man/DispersalKernel.Rd
+++ b/RangeShiftR/man/DispersalKernel.Rd
@@ -59,10 +59,10 @@ valuable method for discerning between common short-distance and rare long-dista
\emph{Negative exponential} \cr
If the individual disperses, the distance and the movement direction are determined in continuous space.
-The distance is drawn from a negative exponential distribution with a given mean \eqn{δ}, and the direction is selected randomly from a uniform
-distribution between \eqn{0} and \eqn{2π} radians.
+The distance is drawn from a negative exponential distribution with a given mean \eqn{\delta}, and the direction is selected randomly from a uniform
+distribution between \eqn{0} and \eqn{2\pi} radians.
-\ifelse{html}{\out{ p(d;δ) = δ-1 e- d / δ}}{\deqn{ p(d;δ) = 1/δ exp(-d/δ) } }
+\ifelse{html}{\out{ p(d;δ) = δ-1 e- d / δ}}{\deqn{ p(d;\delta) = 1/\delta exp(-d/\delta) } }
If the arrival point lies beyond the boundary of the landscape, distance and direction are re-drawn.\cr
The individual is displaced from a random point (using continuous coordinates) inside the natal cell to the arrival cell where the model
@@ -79,17 +79,17 @@ not they emigrate.
\emph{Mixed kernel} \cr
The distance an individual moves is sampled from a mixed kernel given by the combination of two negative exponentials
-with different means \ifelse{html}{\out{δ1}}{\eqn{δ_1}} and \ifelse{html}{\out{δ2}}{\eqn{δ_2}},
+with different means \ifelse{html}{\out{δ1}}{\eqn{\delta_1}} and \ifelse{html}{\out{δ2}}{\eqn{\delta_2}},
occurring with probability \ifelse{html}{\out{pI}}{\eqn{p_I}} and \eqn{1-}\ifelse{html}{\out{pI}}{\eqn{p_I}} respectively \insertCite{hovestadt2011all}{RangeShiftR}.
Otherwise, the conditions for the single kernel apply.
-\ifelse{html}{\out{ p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1)}}{\deqn{ p(d; δ_1,δ_2) = p_I p(d;δ_1) + (1-p_I) p(d;δ_2)}}
+\ifelse{html}{\out{ p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1)}}{\deqn{ p(d; \delta_1,\delta_2) = p_I p(d;\delta_1) + (1-p_I) p(d;\delta_2)}}
For both types of kernel, inter-individual variability of the kernel traits is possible (set \code{IndVar=TRUE}). Individuals will
-carry either one trait for \eqn{δ} or three traits for \ifelse{html}{\out{δ1}}{\eqn{δ_1}}, \ifelse{html}{\out{δ2}}{\eqn{δ_2}} and
+carry either one trait for \eqn{\delta} or three traits for \ifelse{html}{\out{δ1}}{\eqn{\delta_1}}, \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} and
\ifelse{html}{\out{pI}}{\eqn{p_I}}, which they inherit from their parents.\cr
-Dispersal kernels can also be sex-dependent (set \code{SexDep=TRUE}). In the case of inter-individual variability, the number of traits is doubled to two trait (female \eqn{δ}
-and male δ) or six traits (female and male \ifelse{html}{\out{δ1}}{\eqn{δ_1}}, \ifelse{html}{\out{δ2}}{\eqn{δ_2}} and \ifelse{html}{\out{pI}}{\eqn{p_I}}).\cr
+Dispersal kernels can also be sex-dependent (set \code{SexDep=TRUE}). In the case of inter-individual variability, the number of traits is doubled to two trait (female \eqn{\delta}
+and male delta) or six traits (female and male \ifelse{html}{\out{δ1}}{\eqn{\delta_1}}, \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} and \ifelse{html}{\out{pI}}{\eqn{p_I}}).\cr
For each trait the initial distribution in the population (as mean and standard variation) must be set in \code{Distances} (instead of only one constant value),
as well as their scaling factors in \code{TraitScaleFactor} (see \code{\link[RangeShiftR]{Genetics}}).\cr
@@ -97,8 +97,8 @@ Further, dispersal kernels can be stage-specific (set \code{StageDep=TRUE}). For
All dispersal kernel parameters have to be provided via \code{Distances}, which generally takes a matrix, or - if only a single constant mean distance is
used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric. The format of the matrix is defined as follows: The number of columns depend on the options \code{IndVar} and \code{DoubleKernel}.
-If \code{DoubleKernel=FALSE}, the mean dispersal distance \eqn{δ} must be specified (in meters). If \code{DoubleKernel=TRUE}, the mean dispersal distances
-\ifelse{html}{\out{δ1}}{\eqn{δ_1}} and \ifelse{html}{\out{δ2}}{\eqn{δ_2}} (in meters), as well as the probability \ifelse{html}{\out{pI}}{\eqn{p_I}} of using Kernel-1 must be specified.
+If \code{DoubleKernel=FALSE}, the mean dispersal distance \eqn{\delta} must be specified (in meters). If \code{DoubleKernel=TRUE}, the mean dispersal distances
+\ifelse{html}{\out{δ1}}{\eqn{\delta_1}} and \ifelse{html}{\out{δ2}}{\eqn{\delta_2}} (in meters), as well as the probability \ifelse{html}{\out{pI}}{\eqn{p_I}} of using Kernel-1 must be specified.
Additionally, if \code{IndVar=FALSE}, these parameters are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective mean and
standard deviation. They are used to normally distribute the traits values among the individuals of the initial population.
@@ -107,25 +107,25 @@ If \code{SexDep=TRUE}, state the corresponding stage in the next (i.e. first/sec
table lists the required columns and their correct order for different settings:
\tabular{ccccc}{IndVar \tab DoubleKernel \tab StageDep \tab SexDep \tab columns \cr
- F \tab F \tab F \tab F \tab \eqn{δ} \cr
- F \tab F \tab T \tab F \tab stage, \eqn{δ} \cr
- F \tab F \tab F \tab T \tab sex, \eqn{δ} \cr
- F \tab F \tab T \tab T \tab stage, sex, \eqn{δ} \cr
- F \tab T \tab F \tab F \tab \ifelse{html}{\out{δ1, δ2, pI}}{\eqn{δ_1, δ_2, p_I}} \cr
- T \tab F \tab F \tab F \tab mean\eqn{(δ)}, sd\eqn{(δ)} \cr
- T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(δ_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(δ_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(δ_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(δ_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}} \cr
- \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
- T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(δ_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(δ_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(δ_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(δ_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}
+ F \tab F \tab F \tab F \tab \eqn{\delta} \cr
+ F \tab F \tab T \tab F \tab stage, \eqn{\delta} \cr
+ F \tab F \tab F \tab T \tab sex, \eqn{\delta} \cr
+ F \tab F \tab T \tab T \tab stage, sex, \eqn{\delta} \cr
+ F \tab T \tab F \tab F \tab \ifelse{html}{\out{δ1, δ2, pI}}{\eqn{\delta_1, \delta_2, p_I}} \cr
+ T \tab F \tab F \tab F \tab mean\eqn{(\delta)}, sd\eqn{(\delta)} \cr
+ T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(\delta_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(\delta_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(\delta_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(\delta_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}} \cr
+ \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+ T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(δ1)}}{mean\eqn{(\delta_1)}}, \ifelse{html}{\out{sd(δ1)}}{sd\eqn{(\delta_1)}}, \ifelse{html}{\out{mean(δ2)}}{mean\eqn{(\delta_2)}}, \ifelse{html}{\out{sd(δ2)}}{sd\eqn{(\delta_2)}}, mean\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}, sd\ifelse{html}{\out{(pI)}}{\eqn{(p_I)}}
}
The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly
one row for each stage/sex combination. For example, in the case of a mixed kernel with stage- and sex-dependent distances and no individual variability:
-\tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1000 \tab \out{ } 4500 \tab \out{ } 0.92 \cr
- \out{ } 0 \tab \out{ } 1 \tab \out{ } 1400 \tab \out{ } 6000 \tab \out{ } 0.95 \cr
- \out{ } 1 \tab \out{ } 0 \tab \out{ } 700 \tab \out{ } 500 \tab \out{ } 0.50 \cr
- \out{ } 1 \tab \out{ } 1 \tab \out{ } 500 \tab \out{ } 600 \tab \out{ } 0.55 \cr
- \out{ } 2 \tab \out{ } 0 \tab \out{ } 100 \tab \out{ } 0 \tab \out{ } 1.0 \cr
- \out{ } 2 \tab \out{ } 1 \tab \out{ } 100 \tab \out{ } 0 \tab \out{ } 1.0
+\tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1000 \tab \out{} 4500 \tab \out{} 0.92 \cr
+ \out{} 0 \tab \out{} 1 \tab \out{} 1400 \tab \out{} 6000 \tab \out{} 0.95 \cr
+ \out{} 1 \tab \out{} 0 \tab \out{} 700 \tab \out{} 500 \tab \out{} 0.50 \cr
+ \out{} 1 \tab \out{} 1 \tab \out{} 500 \tab \out{} 600 \tab \out{} 0.55 \cr
+ \out{} 2 \tab \out{} 0 \tab \out{} 100 \tab \out{} 0 \tab \out{} 1.0 \cr
+ \out{} 2 \tab \out{} 1 \tab \out{} 100 \tab \out{} 0 \tab \out{} 1.0
}
In the case that the dispersal kernel is applied to the entire
@@ -141,7 +141,7 @@ proportion of suitable habitat in the landscape and will increase as the availab
A second source of dispersal mortality can be specified via the option \code{DistMort}: The probability of mortality is either a constant
(\eqn{m=}\code{MortProb}) or a function of distance \eqn{d} (i.e. individuals that travel further are more likely to die):
-\ifelse{html}{\out{ m(d) = 1 / ( 1 + e-a (d- b) ) } }{\deqn{ m(d) = 1 / ( 1 + exp[-α (d-b) ] ) } }
+\ifelse{html}{\out{ m(d) = 1 / ( 1 + e-a (d- b) ) } }{\deqn{ m(d) = 1 / ( 1 + exp[-\alpha (d-b) ] ) } }
with the inflection point \eqn{b=}\code{InflPoint} at which \eqn{m(d=b)=0.5} and the slope \eqn{a=}\code{Slope}.This option may be thought
to represent the increased energetic, time or attritional costs that longer-distance dispersers will experience \insertCite{bonte2012costs}{RangeShiftR}.
diff --git a/RangeShiftR/man/Emigration.Rd b/RangeShiftR/man/Emigration.Rd
index b66dae9..7eed664 100644
--- a/RangeShiftR/man/Emigration.Rd
+++ b/RangeShiftR/man/Emigration.Rd
@@ -48,18 +48,18 @@ rate can be larger than \eqn{d}, if a stage with \eqn{d>0} lasts for more than o
The emigration probability \eqn{d} can be density-dependent (set \code{DensDep=TRUE}), in which case it is given by the following function, introduced by \insertCite{kun2006evolution;textual}{RangeShiftR}:
-\ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (N(i,t) / K(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-α_E (N(i,t)/K(i,t) - β_E) ] ) } }
+\ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (N(i,t) / K(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-\alpha_E (N(i,t)/K(i,t) - \beta_E) ] ) } }
In the case of stage-structured models this equation is modified to:
-\ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (b(i,t) * N(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-α_E (b(i,t) N(i,t) - β_E) ] ) } }
+\ifelse{html}{\out{ d(i,t) = D0 / ( 1 + e-αsub>E (b(i,t) * N(i,t) - βsub>E) ) } }{\deqn{ d(i,t) = D_0 / ( 1 + exp[-\alpha_E (b(i,t) N(i,t) - \beta_E) ] ) } }
In the first case, \eqn{K(i,t)} is the carrying capacity of the cell/patch \eqn{i} at time \eqn{t} given by \code{K_or_DensDep}.
In the latter case, \eqn{b(i,t)} represents the strength of density dependence and is given by the inverse of \code{K_or_DensDep}.\cr
Further, \ifelse{html}{\out{D0}}{\eqn{D_0}} is the maximum emigration probability,
\eqn{N(i,t)} is the number of individuals in the cell/patch \eqn{i} at time \eqn{t},
-\ifelse{html}{\out{βE}}{\eqn{β_S}} is the inflection point of the function and
-\ifelse{html}{\out{αE}}{\eqn{α_S}} is the slope at the inflection point.\cr
+\ifelse{html}{\out{βE}}{\eqn{\beta_S}} is the inflection point of the function and
+\ifelse{html}{\out{αE}}{\eqn{\alpha_S}} is the slope at the inflection point.\cr
Various functions have been proposed for density dependent emigration \insertCite{hovestadt2010information,poethke2011ability}{RangeShiftR}.
This one was chosen here because it is a flexible function that
@@ -68,8 +68,8 @@ emigration, we assume individuals to have full knowledge of the population densi
Information acquisition is not explicitly modelled.
The emigration probability can be allowed to vary between individuals (set \code{IndVar=TRUE}) and to evolve. In the this case, individuals exhibit either one trait
-determining the density-independent \eqn{d} (when \code{DensDep=FALSE}), or the three traits \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α} and
-\eqn{β} determining the density-dependent emigration probability (when \code{DensDep=TRUE}).\cr
+determining the density-independent \eqn{d} (when \code{DensDep=FALSE}), or the three traits \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha} and
+\eqn{\beta} determining the density-dependent emigration probability (when \code{DensDep=TRUE}).\cr
For each trait the initial distribution in the population (as mean and standard variation) must be set in \code{EmigProb} (instead of only one constant value),
as well as their scaling factors in \code{TraitScaleFactor} (see \code{\link[RangeShiftR]{Genetics}}).
Also, if \code{IndVar=TRUE} is set for a stage-structured population, it is required to specify the stage which emigrates via \code{EmigStage}.
@@ -81,7 +81,7 @@ However, the current version does not accommodate inter-individual variation in
The parameters that determine the emigration probabilities have to be provided via \code{EmigProb}, which generally takes a matrix, or - if only a single constant probability is
used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric. The format of the matrix is defined as follows: The number of columns depend on the options \code{DensDep} and \code{IndVar}. If \code{DensDep=FALSE}, the
-density-independent probability \eqn{d} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α} and \eqn{β} (cp. equation above) must be specified.
+density-independent probability \eqn{d} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha} and \eqn{\beta} (cp. equation above) must be specified.
Additionally, if \code{IndVar=FALSE}, these parameters are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective mean and
standard deviation. They are used to normally distribute the traits values among the individuals of the initial population.
@@ -93,20 +93,20 @@ If \code{SexDep=TRUE}, state the corresponding stage in the next (i.e. first/sec
F \tab F \tab T \tab F \tab stage, \eqn{d} \cr
F \tab F \tab F \tab T \tab sex, \eqn{d} \cr
F \tab F \tab T \tab T \tab stage, sex, \eqn{d} \cr
- T \tab F \tab F \tab F \tab \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{α}, \eqn{β} \cr
+ T \tab F \tab F \tab F \tab \ifelse{html}{\out{D0}}{\eqn{D_0}}, \eqn{\alpha}, \eqn{\beta} \cr
F \tab T \tab F \tab F \tab mean\eqn{(d)}, sd\eqn{(d)} \cr
- T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(α)}, sd\eqn{(α)}, mean\eqn{(β)}, sd\eqn{(β)} \cr
- \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
- T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(α)}, sd\eqn{(α)}, mean\eqn{(β)}, sd\eqn{(β)}
+ T \tab T \tab F \tab F \tab \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(\alpha)}, sd\eqn{(\alpha)}, mean\eqn{(\beta)}, sd\eqn{(\beta)} \cr
+ \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+ T \tab T \tab F \tab T \tab sex, \ifelse{html}{\out{mean(D0)}}{mean\eqn{(D_0)}}, \ifelse{html}{\out{sd(D0)}}{sd\eqn{(D_0)}}, mean\eqn{(\alpha)}, sd\eqn{(\alpha)}, mean\eqn{(\beta)}, sd\eqn{(\beta)}
}
The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly one row for each stage/sex combination. For example, in the case of density-, stage- and sex-dependent emigration with no individual variability:
-\tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1.0 \tab \out{ } 20 \tab \out{ } 0.2 \cr
- \out{ } 0 \tab \out{ } 1 \tab \out{ } 1.0 \tab \out{ } 20 \tab \out{ } 0.1 \cr
- \out{ } 1 \tab \out{ } 0 \tab \out{ } 0.7 \tab \out{ } 25 \tab \out{ } 0.5 \cr
- \out{ } 1 \tab \out{ } 1 \tab \out{ } 0.8 \tab \out{ } 50 \tab \out{ } 0.5 \cr
- \out{ } 2 \tab \out{ } 0 \tab \out{ } 0.4 \tab \out{ } 10 \tab \out{ } 1.0 \cr
- \out{ } 2 \tab \out{ } 1 \tab \out{ } 0.5 \tab \out{ } 20 \tab \out{ } 1.0
+\tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1.0 \tab \out{} 20 \tab \out{} 0.2 \cr
+ \out{} 0 \tab \out{} 1 \tab \out{} 1.0 \tab \out{} 20 \tab \out{} 0.1 \cr
+ \out{} 1 \tab \out{} 0 \tab \out{} 0.7 \tab \out{} 25 \tab \out{} 0.5 \cr
+ \out{} 1 \tab \out{} 1 \tab \out{} 0.8 \tab \out{} 50 \tab \out{} 0.5 \cr
+ \out{} 2 \tab \out{} 0 \tab \out{} 0.4 \tab \out{} 10 \tab \out{} 1.0 \cr
+ \out{} 2 \tab \out{} 1 \tab \out{} 0.5 \tab \out{} 20 \tab \out{} 1.0
}
In the special case that \code{DensDep=FALSE} and transfer is realised by \code{\link[RangeShiftR]{DispersalKernel}}, then the option \code{UseFullKern} may be switched on. It
diff --git a/RangeShiftR/man/Settlement.Rd b/RangeShiftR/man/Settlement.Rd
index 474811b..ff64309 100644
--- a/RangeShiftR/man/Settlement.Rd
+++ b/RangeShiftR/man/Settlement.Rd
@@ -57,8 +57,8 @@ The type of implemented settlement rules depends on the movement model utilized
In any case, dispersing individuals are not allowed to settle in their natal cell or patch.\cr
\emph{RangeShiftR} incorporates some basic settlement rules that can be stage- or sex-specific or both (set \code{StageDep}, \code{SexDep}).
Inter-individual variability (\code{IndVar}) is implemented only for movement processes and then for the three traits
-determining density-dependent settlement (\ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}},
-\ifelse{html}{\out{βS}}{\eqn{β_S}}; see below). In this case, settlement may not be stage-dependent.\cr
+determining density-dependent settlement (\ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}},
+\ifelse{html}{\out{βS}}{\eqn{\beta_S}}; see below). In this case, settlement may not be stage-dependent.\cr
\emph{Settlement with dispersal kernels}\cr
When using a \code{\link[RangeShiftR]{DispersalKernel}}, individuals are displaced directly from the starting location to the arrival location. The suitability
@@ -88,7 +88,7 @@ Settlement condition codes: If the individuals current step ends in unsuitable h
\eqn{2} = randomly choose a suitable neighbouring cell or die,\cr
\eqn{3} = randomly choose a suitable neighbouring cell or wait (stage-structured models only).\cr
-Simple example for sex-dependence only: Females choose a neighbouring cell or wait, males wait: \tabular{cc}{\out{ } 0 \tab \out{ } 3 \cr \out{ } 1 \tab \out{ } 0 }
+Simple example for sex-dependence only: Females choose a neighbouring cell or wait, males wait: \tabular{cc}{\out{} 0 \tab \out{} 3 \cr \out{} 1 \tab \out{} 0 }
\emph{Settlement with movement processes}\cr
If individuals are dispersing by one of the two movement processes implemented (\code{\link[RangeShiftR]{SMS}} or
@@ -101,18 +101,18 @@ it gets converted to \eqn{S_0=1.0}, i.e. 'always settle when habitat is suitable
Furthermore, the settlement decision can be density-dependent (set \code{DensDep=TRUE}). In this case, the individual has a probability \ifelse{html}{\out{pS}}{\eqn{p_S}}
of settling in the cell or patch \eqn{i}, given by:
-\ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (N(i,t) / K(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-α_S (N(i,t)/K(i,t) - β_S) ] ) } }
+\ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (N(i,t) / K(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-\alpha_S (N(i,t)/K(i,t) - \beta_S) ] ) } }
In the case of stage-structured models the above equation is modified to:
-\ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (b(i,t) * N(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-α_S (b(i,t) N(i,t) - β_S) ] ) } }
+\ifelse{html}{\out{ pS(i,t) = S0 / ( 1 + e-αS (b(i,t) * N(i,t) - βS) ) } }{\deqn{ p_S(i,t) = S_0 / ( 1 + exp[-\alpha_S (b(i,t) N(i,t) - \beta_S) ] ) } }
In the first case, \eqn{K(i,t)} is the carrying capacity of the cell/patch \eqn{i} at time \eqn{t} given by \code{K_or_DensDep}.
In the latter case, \eqn{b(i,t)} represents the strength of density dependence that is given by the inverse of \code{K_or_DensDep}.\cr
Further, \ifelse{html}{\out{S0}}{\eqn{S_0}} is the maximum settlement probability,
\eqn{N(i,t)} is the number of individuals in the cell/patch \eqn{i} at time \eqn{t},
-\ifelse{html}{\out{βS}}{\eqn{β_S}} is the inflection point of the function and
-\ifelse{html}{\out{αS}}{\eqn{α_S}} is the slope at the inflection point.\cr
+\ifelse{html}{\out{βS}}{\eqn{\beta_S}} is the inflection point of the function and
+\ifelse{html}{\out{αS}}{\eqn{\alpha_S}} is the slope at the inflection point.\cr
Inter-individual variability \code{IndVar=TRUE} and thus evolution is implemented only for the three traits determining density-dependent settlement
(\code{DensDep=TRUE}), and if so, it may not be stage-dependent (\code{StageDep=FALSE}).
@@ -123,7 +123,7 @@ The parameters that determine the settlement probabilities have to be provided v
used (i.e. \code{DensDep, IndVar, StageDep, SexDep = FALSE}) - a single numeric.
The format of the matrix is defined as follows: The number of columns depend on the options \code{DensDep} and \code{IndVar}. If \code{DensDep=FALSE}, the
density-independent probability \ifelse{html}{\out{pS}}{\eqn{p_S}} must be specified. If \code{DensDep=TRUE}, the functional parameters \ifelse{html}{\out{S0}}{\eqn{S_0}},
-\ifelse{html}{\out{αS}}{\eqn{α_S}} and \ifelse{html}{\out{βS}}{\eqn{β_S}} (cf. equation above) must be specified.
+\ifelse{html}{\out{αS}}{\eqn{\alpha_S}} and \ifelse{html}{\out{βS}}{\eqn{\beta_S}} (cf. equation above) must be specified.
Additionally, if \code{IndVar=FALSE}, these traits are fixed, but if \code{IndVar=TRUE} each of them is replaced by two parameters: their respective initial mean and
standard deviation. They are used to normally distribute the traits values among the individuals of the initial population. Additionally, the \code{TraitScaleFactor} of
these traits have to be set.
@@ -137,21 +137,21 @@ The following table lists the required columns and their correct order for diffe
F \tab F \tab T \tab F \tab stage \cr
F \tab F \tab F \tab T \tab sex \cr
F \tab F \tab T \tab T \tab stage, sex \cr
- T \tab F \tab F \tab F \tab \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}}, \ifelse{html}{\out{βS}}{\eqn{β_S}} \cr
- \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \tab \out{⋮} \cr
- T \tab F \tab T \tab T \tab stage, sex, \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{α_S}}, \ifelse{html}{\out{βS}}{\eqn{β_S}} \cr
- T \tab T \tab F \tab F \tab mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{β_S})} \cr
- T \tab T \tab F \tab T \tab sex, mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{α_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{β_S})}
+ T \tab F \tab F \tab F \tab \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}}, \ifelse{html}{\out{βS}}{\eqn{\beta_S}} \cr
+ \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \tab \out{:} \cr
+ T \tab F \tab T \tab T \tab stage, sex, \ifelse{html}{\out{S0}}{\eqn{S_0}}, \ifelse{html}{\out{αS}}{\eqn{\alpha_S}}, \ifelse{html}{\out{βS}}{\eqn{\beta_S}} \cr
+ T \tab T \tab F \tab F \tab mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})} \cr
+ T \tab T \tab F \tab T \tab sex, mean\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, sd\ifelse{html}{\out{(S0)}}{\eqn{(S_0)}}, mean\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, sd\ifelse{html}{\out{(αS)}}{(\eqn{\alpha_S})}, mean\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}, sd\ifelse{html}{\out{(βS)}}{(\eqn{\beta_S})}
}
The column headings need not be included, only the numeric matrix is required. The rows require no particular order, but there must be exactly one row for each stage/sex combination.
For example, in the case of density-, stage- and sex-dependent settlement with no individual variability:
-\tabular{ccccc}{ \out{ } 0 \tab \out{ } 0 \tab \out{ } 1.0 \tab \out{ } 0.2 \tab \out{ } 4.0 \cr
- \out{ } 0 \tab \out{ } 1 \tab \out{ } 1.0 \tab \out{ } 0.1 \tab \out{ } 6.0 \cr
- \out{ } 1 \tab \out{ } 0 \tab \out{ } 0.7 \tab \out{ } 0.5 \tab \out{ } 2.0 \cr
- \out{ } 1 \tab \out{ } 1 \tab \out{ } 0.5 \tab \out{ } 0.5 \tab \out{ } 2.0 \cr
- \out{ } 2 \tab \out{ } 0 \tab \out{ } 0.05 \tab \out{ } 1.0 \tab \out{ } 1.0 \cr
- \out{ } 2 \tab \out{ } 1 \tab \out{ } 0.05 \tab \out{ } 1.0 \tab \out{ } 1.0
+\tabular{ccccc}{ \out{} 0 \tab \out{} 0 \tab \out{} 1.0 \tab \out{} 0.2 \tab \out{} 4.0 \cr
+ \out{} 0 \tab \out{} 1 \tab \out{} 1.0 \tab \out{} 0.1 \tab \out{} 6.0 \cr
+ \out{} 1 \tab \out{} 0 \tab \out{} 0.7 \tab \out{} 0.5 \tab \out{} 2.0 \cr
+ \out{} 1 \tab \out{} 1 \tab \out{} 0.5 \tab \out{} 0.5 \tab \out{} 2.0 \cr
+ \out{} 2 \tab \out{} 0 \tab \out{} 0.05 \tab \out{} 1.0 \tab \out{} 1.0 \cr
+ \out{} 2 \tab \out{} 1 \tab \out{} 0.05 \tab \out{} 1.0 \tab \out{} 1.0
}
To avoid having individuals moving perpetually because they cannot find suitable conditions to settle, the model requires a maximum number
diff --git a/RangeShiftR/man/Simulation.Rd b/RangeShiftR/man/Simulation.Rd
index fe2fd82..5c127e2 100644
--- a/RangeShiftR/man/Simulation.Rd
+++ b/RangeShiftR/man/Simulation.Rd
@@ -146,7 +146,7 @@ and \eqn{G} (\code{GradSteep}), the gradient steepness in units of fraction of t
The local heterogeneity is determined by a random number drawn from a uniform distribution between \eqn{-1} and \eqn{1} for each cell
and \code{f}, the local scaling factor that determines the magnitude of this stochastic local variation relative to the extremal value.
-The gradient in fecundity φ applies to the fecundity of each stage. Negative local values in \eqn{z(x,y)} are set to \eqn{0}.
+The gradient in fecundity \eqn{\phi} applies to the fecundity of each stage. Negative local values in \eqn{z(x,y)} are set to \eqn{0}.
It is also possible to simulate the shifting of the gradient by setting the option \code{Shifting}. Here the position \eqn{y} of the species’
optimum is shifted northwards (increasing \eqn{y}) at a given rate \code{ShiftRate} (in units of rows per year),
@@ -163,18 +163,18 @@ This does not affect any demographic parameters but simply kills off the local p
\emph{Environmental Stochasticity}\cr
It is possible to model environmental stochasticity via the option \code{EnvStoch} acting at a global or local scale
and can be applied to \code{K_or_DensDep}, the demographic density dependence (\code{EnvStoch=1}), or to growth rate / fecundity (\code{EnvStoch=0}).
-It is implemented using a first order autoregressive process to generate time series of the noise value \eqn{ε}
+It is implemented using a first order autoregressive process to generate time series of the noise value \eqn{\epsilon}
\insertCite{ruokolainen2009}{RangeShiftR}:
-\deqn{ε(t+1) = κ ε(t) + \omega(t) \sqrt(1-\kappa^2)}
+\deqn{\epsilon(t+1) = \kappa \epsilon(t) + \omega(t) \sqrt(1-\kappa^2)}
-where κ is the autocorrelation coefficient (\code{ac}) and ω is a random normal variable drawn from \eqn{N(0,σ)}.
-Changing σ (\code{std}) changes the magnitude of the fluctuations. The spatial scale of the variation can either be global (a single time series
+where \eqn{\kappa} is the autocorrelation coefficient (\code{ac}) and \eqn{\omega} is a random normal variable drawn from \eqn{N(0,\sigma)}.
+Changing \eqn{\sigma} (\code{std}) changes the magnitude of the fluctuations. The spatial scale of the variation can either be global (a single time series
for the entire landscape) or local (each cell fluctuates independently), and is always applied on a yearly basis.
Different degrees of spatial autocorrelation are not implemented in the current version.
The noise affects the species' selected parameter \eqn{Z} as follows:
-\deqn{Z(x,y,t) = Z(x,y,0) + Z ε(t)}
+\deqn{Z(x,y,t) = Z(x,y,0) + Z \epsilon(t)}
where \eqn{x} and \eqn{y} are the cell coordinates and \eqn{Z} is the original parameter value in absence of stochasticity and gradients.
In the presence of an environmental gradient, \eqn{Z(x,y,0)} is the gradient value at the cell location, otherwise its equal to \eqn{Z}.
The resulting values \eqn{Z(x,y,t)} are limited to the maximum and minimum values \code{minR,maxR} or \code{minK,maxK}, respectively.
@@ -184,7 +184,7 @@ Seven different types of outputs can be produced, plus one more for patch-based
All the output files will be named with a standard name reporting the simulation ID number and
the type of output. The file name will start with the batch number, and also indicate the number
of the landscape to which the output refers. Additionally, for each simulation all the set parameters
-will be automatically written to a text file named \"Sim0_Parameters.txt\" in the case of simulation\eqn{#=0}.
+will be automatically written to a text file named \"Sim0_Parameters.txt\" in the case of simulation\eqn{=0}.
- \emph{Species range} (\code{Sim0_Range.txt}) \cr
contains the following general information regarding the species’ range:\cr
diff --git a/RangeShiftR/man/StageStructure.Rd b/RangeShiftR/man/StageStructure.Rd
index 60a492a..598e553 100644
--- a/RangeShiftR/man/StageStructure.Rd
+++ b/RangeShiftR/man/StageStructure.Rd
@@ -49,39 +49,39 @@ In stage-structured populations, generations can overlap and individuals can be
demographic parameters. Individuals are characterized by their age and stage. Each stage has a certain fecundity, survival probability and probability of developing to the next stage.
These parameters are provided through classical transition matrices \insertCite{caswell2001}{RangeShiftR}.
-\ifelse{html}{\out{φi}}{\eqn{φ_i}} is the fecundity of stage \eqn{i} ;
-\ifelse{html}{\out{σi}}{\eqn{σ_i}} is the survival probability of an individual in stage \eqn{i} ;
-and \ifelse{html}{\out{γi-j}}{\eqn{γ_(i-j)}} is the probability of developing from stage \eqn{i} to stage \eqn{j}.
+\ifelse{html}{\out{φi}}{\eqn{\phi_i}} is the fecundity of stage \eqn{i} ;
+\ifelse{html}{\out{σi}}{\eqn{\sigma_i}} is the survival probability of an individual in stage \eqn{i} ;
+and \ifelse{html}{\out{γi-j}}{\eqn{\gamma_(i-j)}} is the probability of developing from stage \eqn{i} to stage \eqn{j}.
In this way, the transition matrix describes the effect of each individuals current stage (column) on all stages at the next timestep (rows).
Since all offspring is born into the juvenile stage (stage 0), all fecundities are always located in the first row of the matrix.
However, in \emph{RangeShiftR}, these parameters are not used deterministically as \emph{rates} (like it is typical for matrix models) but, instead, as \emph{probabilities} which are
-applied stochastically at the individual level. Hence, each female at stage \eqn{i}, if it reproduces, produces a number of offspring given by \eqn{Poisson}(\ifelse{html}{\out{φi}}{\eqn{φ_i}}),
-while Bernoulli trials \eqn{Bern}(\ifelse{html}{\out{σi}}{\eqn{σ_i}}) and \eqn{Bern}(\ifelse{html}{\out{γi,i+1}}{\eqn{γ_(i,i+1)}}) determine if an individual/female survives or not
+applied stochastically at the individual level. Hence, each female at stage \eqn{i}, if it reproduces, produces a number of offspring given by \eqn{Poisson}(\ifelse{html}{\out{φi}}{\eqn{\phi_i}}),
+while Bernoulli trials \eqn{Bern}(\ifelse{html}{\out{σi}}{\eqn{\sigma_i}}) and \eqn{Bern}(\ifelse{html}{\out{γi,i+1}}{\eqn{\gamma_(i,i+1)}}) determine if an individual/female survives or not
and - if it survives - if it develops to the next stage or not.
An example transition matrix for a 3-staged only-female or simple sexual (\code{ReproductionType={0,1}}) population model:
-\tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{φ_2}} \cr
-\eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{σ_1 (1 − γ_(1-2))}} \tab | \tab \eqn{0} \cr
-\eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{σ_1 γ_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{σ_2}} \cr}
+\tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{\phi_2}} \cr
+\eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{\sigma_1 (1 - \gamma_(1-2))}} \tab | \tab \eqn{0} \cr
+\eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{\sigma_1 \gamma_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{\sigma_2}} \cr}
-In a female-only model (\code{ReproductionType=0}), \ifelse{html}{\out{φ}}{\eqn{φ}} represents the number of female offspring per female and reproductive event. \cr
+In a female-only model (\code{ReproductionType=0}), \ifelse{html}{\out{φ}}{\eqn{\phi}} represents the number of female offspring per female and reproductive event. \cr
Note that for an implicit (simple) sexual model (\code{ReproductionType=1}), the demographic parameters are not sex-specific. However, individuals are defined by their sex, which is acknowledged for example in the dispersal
-process and transmission of alleles. The fecundities \ifelse{html}{\out{φ}}{\eqn{φ}} refer to the number of all offspring (males and females) per female and reproductive event.
+process and transmission of alleles. The fecundities \ifelse{html}{\out{φ}}{\eqn{\phi}} refer to the number of all offspring (males and females) per female and reproductive event.
In case of an explicit (complex) sexual model (\code{ReproductionType=2}), in contrast, each stage must be represented by two columns and rows to distinguish male and female demographic parameters.
-Note, however, that in any case the juvenile stage has only one row; it contains the fecundities. Male fecundities should have one of two possible values: set \ifelse{html}{\out{φm}}{\eqn{φ_m}} \eqn{=1.0} for reproductive males or \ifelse{html}{\out{φm}}{\eqn{φ_m}} \eqn{=0.0} for non-reproductive males.\cr
+Note, however, that in any case the juvenile stage has only one row; it contains the fecundities. Male fecundities should have one of two possible values: set \ifelse{html}{\out{φm}}{\eqn{\phi_m}} \eqn{=1.0} for reproductive males or \ifelse{html}{\out{φm}}{\eqn{\phi_m}} \eqn{=0.0} for non-reproductive males.\cr
An example transition matrix for a 3-staged explicit sexual population model \insertCite{weeks1986,lindstrom1998}{RangeShiftR}:
-\tabular{ccccccccccc}{\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{φ1m}}{\eqn{φ_1m}} \tab | \tab \ifelse{html}{\out{φ1f}}{\eqn{φ_1f}} \tab | \tab \ifelse{html}{\out{φ2m}}{\eqn{φ_2m}} \tab | \tab \ifelse{html}{\out{φ2f}}{\eqn{φ_2f}} \cr
-\eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m (1-γ1-2,m)}}{\eqn{σ_1m (1 − γ_(1-2,m))}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
-\eqn{0} \tab | \tab \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{σ_1f γ_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
-\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m γ1-2,m}}{\eqn{σ_1m γ_(1-2,m)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2m}}{\eqn{σ_2m}} \tab | \tab \eqn{0} \cr
-\eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{σ_1f γ_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2f}}{\eqn{σ_2f}} \cr}#' The mating system is explicitly modelled and a female’s probability of reproducing is determined as described in \code{\link[RangeShiftR]{Demography}} \insertCite{weeks1986,caswell2001}{RangeShiftR}.
+\tabular{ccccccccccc}{\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{φ1m}}{\eqn{\phi_1m}} \tab | \tab \ifelse{html}{\out{φ1f}}{\eqn{\phi_1f}} \tab | \tab \ifelse{html}{\out{φ2m}}{\eqn{\phi_2m}} \tab | \tab \ifelse{html}{\out{φ2f}}{\eqn{\phi_2f}} \cr
+\eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m (1-γ1-2,m)}}{\eqn{\sigma_1m (1 - \gamma_(1-2,m))}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
+\eqn{0} \tab | \tab \eqn{1.0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{\sigma_1f \gamma_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \cr
+\eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1m γ1-2,m}}{\eqn{\sigma_1m \gamma_(1-2,m)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2m}}{\eqn{\sigma_2m}} \tab | \tab \eqn{0} \cr
+\eqn{0} \tab | \tab \eqn{0} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ1f γ1-2,f}}{\eqn{\sigma_1f \gamma_(1-2,f)}} \tab | \tab \eqn{0} \tab | \tab \ifelse{html}{\out{σ2f}}{\eqn{\sigma_2f}} \cr}#' The mating system is explicitly modelled and a female’s probability of reproducing is determined as described in \code{\link[RangeShiftR]{Demography}} \insertCite{weeks1986,caswell2001}{RangeShiftR}.
A common mistake in building a transition matrix is made when offspring produced at year \eqn{t} develop to the next stage in the same year \insertCite{@ @caswell2001 pg. 60-62}{RangeShiftR}. To avoid this problem without losing the offspring stage, and hence the chance for simulating post-natal dispersal,
we require an additional explicit juvenile stage (stage 0). Juveniles have to develop to stage 1 in the same year they are born. Hence the minimum number of stages of a stage-structured model is always \eqn{2}. It is important to note that juvenile mortality can be accounted for in
-two ways. Either, as in the examples above, it is included in adult fecundity \ifelse{html}{\out{φ}}{\eqn{φ}} (by appropriately reducing its value), and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{σ_0 γ_(0-1)}} is equal to \eqn{1.0}. This is how it is typically accounted for in matrix models. Or, alternatively,
-φ is equal to the true maximum fecundity and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{σ_0 γ_(0-1)}} is less than \eqn{1.0}.
+two ways. Either, as in the examples above, it is included in adult fecundity \ifelse{html}{\out{φ}}{\eqn{\phi}} (by appropriately reducing its value), and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{\sigma_0 \gamma_(0-1)}} is equal to \eqn{1.0}. This is how it is typically accounted for in matrix models. Or, alternatively,
+\eqn{\phi} is equal to the true maximum fecundity and \ifelse{html}{\out{σ0 γ(0-1)}}{\eqn{\sigma_0 \gamma_(0-1)}} is less than \eqn{1.0}.
Only the first approach allows straightforward direct comparison with standard analytical matrix models.
\emph{Minimum ages:} For every row in the transition matrix, a minimum age must be provided through a vector in argument \code{MinAge}. It specifies the age which an individual in stage \eqn{i-1} (with sex \eqn{m/f}, if applicable) must already have reached before it can develop into the next stage \eqn{(i)}. The vector must be in
@@ -114,26 +114,26 @@ If the transition matrix contains the annual survival and development rates, \co
\emph{Density dependence} can act on each of the three demographic phases (i.e. reproduction, survival and development) and is controlled by \code{FecDensDep,DevDensDep,SurvDensDep}.
It is implemented as an exponential decay \insertCite{neubert2000}{RangeShiftR}:
-\ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) N(t) }}{\deqn{φ_i(r,t)=φ_(0,i) * exp(- b(r) N(t) ) }}
+\ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) N(t) }}{\deqn{\phi_i(r,t)=\phi_(0,i) * exp(- b(r) N(t) ) }}
-\ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) N(t) }}{\deqn{σ_i(r,t)=σ_(0,i) * exp(- C_\sigma b(r) N(t) ) }}
+\ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) N(t) }}{\deqn{\sigma_i(r,t)=\sigma_(0,i) * exp(- C_\sigma b(r) N(t) ) }}
-\ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) N(t) }}{\deqn{γ_i(r,t)=γ_(0,i) * exp(- C_γ b(r) N(t) ) }}
+\ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) N(t) }}{\deqn{\gamma_i(r,t)=\gamma_(0,i) * exp(- C_\gamma b(r) N(t) ) }}
where \eqn{b(r)} is the strength of density dependence in fecundity at site \eqn{r}, which is given by the argument \code{K_or_DensDep} in the landscape module.
-Furthermore, \ifelse{html}{\out{Cσ}}{\eqn{C_\sigma}} and \ifelse{html}{\out{Cγ}}{\eqn{C_γ}} (\code{DevDensCoeff,SurvDensCoeff})
+Furthermore, \ifelse{html}{\out{Cσ}}{\eqn{C_\sigma}} and \ifelse{html}{\out{Cγ}}{\eqn{C_\gamma}} (\code{DevDensCoeff,SurvDensCoeff})
scale the strength of density dependence in survival and development relative to that in fecundity.
Moreover, the strength of density-dependence can be uniform for all stages or stage-dependent. Even greater complexity can be incorporated with
different stages contributing differently to density-dependence \insertCite{caswell2004}{RangeShiftR}:
-\ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) ΣjS ωφ,ij N(j,t)}}{\deqn{φ_i(r,t)=φ_(0,i) * exp(- b(r) \Sigma_j^S ω_{φ,ij} N_j(t) ) }}
+\ifelse{html}{\out{ φi(r,t) = φ0,i * e - b(r) ΣjS ωφ,ij N(j,t)}}{\deqn{\phi_i(r,t)=\phi_(0,i) * exp(- b(r) \Sigma_j^S \omega_{\phi,ij} N_j(t) ) }}
-\ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) ΣjS ωσ,ij N(j,t) }}{\deqn{σ_i(r,t)=σ_(0,i) * exp(- C_\sigma b(r) \Sigma_j^S ω_{σ,ij} N_j(t) )}}
+\ifelse{html}{\out{ σi(r,t) = σ0,i * e - Cσ b(r) ΣjS ωσ,ij N(j,t) }}{\deqn{\sigma_i(r,t)=\sigma_(0,i) * exp(- C_\sigma b(r) \Sigma_j^S \omega_{\sigma,ij} N_j(t) )}}
-\ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) ΣjS ωγ,ij N(j,t)}}{\deqn{γ_i(r,t)=γ_(0,i) * exp(- C_γ b(r) \Sigma_j^S ω_{γ,ij} N_j(t) )}}
+\ifelse{html}{\out{ γi(r,t) = γ0,i * e - Cγ b(r) ΣjS ωγ,ij N(j,t)}}{\deqn{\gamma_i(r,t)=\gamma_(0,i) * exp(- C_\gamma b(r) \Sigma_j^S \omega_{\gamma,ij} N_j(t) )}}
-where \ifelse{html}{\out{ωφ}}{\eqn{ω_φ}}, \ifelse{html}{\out{ωσ}}{\eqn{ω_σ}}, \ifelse{html}{\out{ωγ}}{\eqn{ω_γ}} are weight matrices given by \code{FecStageWtsMatrix, DevStageWtsMatrix, SurvStageWtsMatrix}. Their elements \ifelse{html}{\out{ωij}}{\eqn{ω_ij}}
+where \ifelse{html}{\out{ωφ}}{\eqn{\omega_\phi}}, \ifelse{html}{\out{ωσ}}{\eqn{\omega_\sigma}}, \ifelse{html}{\out{ωγ}}{\eqn{\omega_\gamma}} are weight matrices given by \code{FecStageWtsMatrix, DevStageWtsMatrix, SurvStageWtsMatrix}. Their elements \ifelse{html}{\out{ωij}}{\eqn{\omega_ij}}
represent the contributions of the abundance of stage \eqn{j} to the density dependence in the fecundity / survival / development of stage \eqn{i}, thus they are quadratic matrices of size \code{Stages}\eqn{^2}. Note that the row sums are not required to be normalized, therefore they can be used
to scale the density-dependence for the different stages. In fact, any real value will be accepted for the single weights, so care should be taken when setting them.
}
diff --git a/RangeShiftR/man/plotProbs.Rd b/RangeShiftR/man/plotProbs.Rd
index 29d6497..98b37b3 100644
--- a/RangeShiftR/man/plotProbs.Rd
+++ b/RangeShiftR/man/plotProbs.Rd
@@ -31,20 +31,20 @@ Available methods and their options:
If a mixed kernel was defined (i.e. \code{DoubleKernel=TRUE}), plot the resulting dispersal probability by...
\itemize{
\item \code{combinekernels=FALSE} - ...plotting both kernels separately (default)
- \item \code{combinekernels= TRUE} - ...combining both kernels, i.e. \ifelse{html}{ \out{p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1) } }{\deqn{ p(d; δ_1,δ_2) = p_I p(d;δ_1) + (1-p_I) p(d;δ_2)} }
+ \item \code{combinekernels= TRUE} - ...combining both kernels, i.e. \ifelse{html}{ \out{p(d; δ1,δ2) = pI p(d;δ1) + (1-pI) p(d;δ1) } }{\deqn{ p(d; \delta_1,\delta_2) = p_I p(d;\delta_1) + (1-p_I) p(d;\delta_2)} }
}
\item \code{\link[RangeShiftR]{StageStructure}}: plot fecundity as well as survival and development probabilities.
Survival and development are calculated based on the transition matrix. Consider e.g. a 3 stage matrix with a transition matrix of
- \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{φ_2}} \cr
- \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{σ_1 (1 − γ_(1-2))}} \tab | \tab \eqn{0} \cr
- \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{σ_1 γ_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{σ_2}} \cr}
+ \tabular{ccccc}{0 \tab | \tab 0 \tab | \tab \ifelse{html}{\out{φ2}}{\eqn{\phi_2}} \cr
+ \eqn{1.0} \tab | \tab \ifelse{html}{\out{σ1 (1-γ1-2)}}{\eqn{\sigma_1 (1 - \gamma_(1-2))}} \tab | \tab \eqn{0} \cr
+ \eqn{0} \tab | \tab \ifelse{html}{\out{σ1 γ1-2}}{\eqn{\sigma_1 \gamma_(1-2)}} \tab | \tab \ifelse{html}{\out{σ2}}{\eqn{\sigma_2}} \cr}
The survival probability is calculated as the sum of the probability to stay in the same stage and the probability to reach the next stage.
- E.g. for stage 1: \ifelse{html}{\out{σ1 = sum( σ1 (1-γ1-2), σ1 γ1-2}}{\eqn{σ_1 = sum(σ_1 (1 − γ_(1-2)), σ_1 γ_(1-2))}}
+ E.g. for stage 1: \ifelse{html}{\out{σ1 = sum( σ1 (1-γ1-2), σ1 γ1-2}}{\eqn{\sigma_1 = sum(\sigma_1 (1 - \gamma_(1-2)), \sigma_1 \gamma_(1-2))}}
The development probability of stage 1 to stage 2 is the ratio of the probability to reach stage 2 and the previously calculated survival probability.
- E.g. for stage 1: \ifelse{html}{\out{γ1-2 = σ1 γ1-2 / σ1}}{\eqn{γ_(1-2) = σ_1 / (σ_1 γ_(1-2) )}}
+ E.g. for stage 1: \ifelse{html}{\out{γ1-2 = σ1 γ1-2 / σ1}}{\eqn{\gamma_(1-2) = \sigma_1 / (\sigma_1 \gamma_(1-2) )}}
}
}
diff --git a/RangeShiftR/src/Makevars b/RangeShiftR/src/Makevars
index 5744dce..06bd40d 100644
--- a/RangeShiftR/src/Makevars
+++ b/RangeShiftR/src/Makevars
@@ -1,4 +1,9 @@
-SOURCES = $(wildcard RScore/*.cpp)
+# all except RScore/main.cpp
+SOURCES = RScore/Cell.cpp RScore/Community.cpp RScore/FractalGenerator.cpp \
+ RScore/Genome.cpp RScore/Individual.cpp RScore/Landscape.cpp \
+ RScore/Model.cpp RScore/Parameters.cpp RScore/Patch.cpp \
+ RScore/Population.cpp RScore/RandomCheck.cpp RScore/RSrandom.cpp \
+ RScore/Species.cpp RScore/SubCommunity.cpp RScore/Utils.cpp
OBJECTS = Rinterface.o RcppExports.o $(SOURCES:.cpp=.o)
diff --git a/RangeShiftR/src/Makevars.win b/RangeShiftR/src/Makevars.win
index 477f4d0..2130c9e 100644
--- a/RangeShiftR/src/Makevars.win
+++ b/RangeShiftR/src/Makevars.win
@@ -1,7 +1,12 @@
-SOURCES = $(wildcard RScore/*.cpp)
+# all except RScore/main.cpp
+SOURCES = RScore/Cell.cpp RScore/Community.cpp RScore/FractalGenerator.cpp \
+ RScore/Genome.cpp RScore/Individual.cpp RScore/Landscape.cpp \
+ RScore/Model.cpp RScore/Parameters.cpp RScore/Patch.cpp \
+ RScore/Population.cpp RScore/RandomCheck.cpp RScore/RSrandom.cpp \
+ RScore/Species.cpp RScore/SubCommunity.cpp RScore/Utils.cpp
OBJECTS = Rinterface.o RcppExports.o $(SOURCES:.cpp=.o)
CXX_STD = CXX11
-PKG_CXXFLAGS = -DRSWIN64 -w
+PKG_CXXFLAGS = -DRSWIN64 -DRS_RCPP -w
#PKG_CXXFLAGS = -H
\ No newline at end of file
diff --git a/RangeShiftR/src/RScore/.github/workflows/check.yml b/RangeShiftR/src/RScore/.github/workflows/check.yml
new file mode 100644
index 0000000..2e86587
--- /dev/null
+++ b/RangeShiftR/src/RScore/.github/workflows/check.yml
@@ -0,0 +1,26 @@
+name: check
+on: push
+
+jobs:
+ check:
+ strategy:
+ matrix:
+ os: [windows-latest, ubuntu-latest, macos-latest]
+ include:
+ - os: windows-latest
+ path_to_exe: ./build/Debug/RScore.exe
+ - os: ubuntu-latest
+ path_to_exe: ./build/RScore
+ - os: macos-latest
+ path_to_exe: ./build/RScore
+ runs-on: ${{ matrix.os }}
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: build
+ run: |
+ mkdir build && cd build
+ cmake ../ && cmake --build .
+
+ - name: run
+ run: ${{ matrix.path_to_exe }}
diff --git a/RangeShiftR/src/RScore/.gitignore b/RangeShiftR/src/RScore/.gitignore
index 31831ca..0545382 100644
--- a/RangeShiftR/src/RScore/.gitignore
+++ b/RangeShiftR/src/RScore/.gitignore
@@ -11,11 +11,9 @@ compile_commands.json
Makefile
.build-release/
build-Release/
-*.txt
*.project
*.workspace
*.mk
-*.txt
*.tags
# Hidden source
@@ -83,3 +81,7 @@ vignettes/*.pdf
# compilation files
*.o
+
+# Visual Studio
+.vs/
+out/
diff --git a/RangeShiftR/src/RScore/CMakeLists.txt b/RangeShiftR/src/RScore/CMakeLists.txt
new file mode 100644
index 0000000..c14a3e3
--- /dev/null
+++ b/RangeShiftR/src/RScore/CMakeLists.txt
@@ -0,0 +1,30 @@
+# Config file for compilation with CMake
+
+if (NOT batchmode) # that is, RScore as a standalone
+ cmake_minimum_required(VERSION 3.10)
+ # set the project name and version
+ project(RScore VERSION 2.1.0)
+ # specify the C++ standard
+ set(CMAKE_CXX_STANDARD 17)
+ set(CMAKE_CXX_STANDARD_REQUIRED True)
+ add_executable(RScore Main.cpp 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 Utils.cpp)
+else() # that is, RScore compiled as library within RangeShifter_batch
+ 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 Utils.cpp)
+endif()
+
+# pass config definitions to compiler
+target_compile_definitions(RScore PRIVATE RSWIN64)
+
+# enable LINUX_CLUSTER macro on Linux + macOS
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+ add_compile_definitions("LINUX_CLUSTER")
+endif()
+
+# Debug Mode by default, unless "release" is passed
+if(NOT DEFINED release)
+ add_compile_definitions(RSDEBUG)
+endif()
+
+if(NOT batchmode)
+ target_include_directories(RScore PUBLIC "${PROJECT_BINARY_DIR}")
+endif()
\ No newline at end of file
diff --git a/RangeShiftR/src/RScore/Community.h b/RangeShiftR/src/RScore/Community.h
index 6a07b5b..36a4a12 100644
--- a/RangeShiftR/src/RScore/Community.h
+++ b/RangeShiftR/src/RScore/Community.h
@@ -52,9 +52,9 @@ Last updated: 25 June 2021 by Anne-Kathleen Malchow
#include
#include
using namespace std;
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
diff --git a/RangeShiftR/src/RScore/Individual.cpp b/RangeShiftR/src/RScore/Individual.cpp
index 357f175..cc7bf6e 100644
--- a/RangeShiftR/src/RScore/Individual.cpp
+++ b/RangeShiftR/src/RScore/Individual.cpp
@@ -1,26 +1,26 @@
/*----------------------------------------------------------------------------
- *
- * 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 .
- *
+ *
--------------------------------------------------------------------------*/
-
-
-//---------------------------------------------------------------------------
+
+
+ //---------------------------------------------------------------------------
#include "Individual.h"
//---------------------------------------------------------------------------
@@ -30,82 +30,70 @@ int Individual::indCounter = 0;
//---------------------------------------------------------------------------
// Individual constructor
-Individual::Individual(Cell *pCell,Patch *pPatch,short stg,short a,short repInt,
- float probmale,bool movt,short moveType)
+Individual::Individual(Cell* pCell, Patch* pPatch, short stg, short a, short repInt,
+ float probmale, bool movt, short moveType)
{
-indId = indCounter; indCounter++; // unique identifier for each individual
-#if RSDEBUG
-//DEBUGLOG << "Individual::Individual(): indId=" << indId
-// << " stg=" << stg << " a=" << a << " probmale=" << probmale
-// << endl;
-#endif
+ indId = indCounter;
+ indCounter++; // unique identifier for each individual
-stage = stg;
-if (probmale <= 0.0) sex = 0;
-else sex = pRandom->Bernoulli(probmale);
-age = a;
-status = 0;
+ stage = stg;
+ if (probmale <= 0.0) sex = 0;
+ else sex = pRandom->Bernoulli(probmale);
+ age = a;
+ status = 0;
-if (sex == 0 && repInt > 0) { // set no. of fallow seasons for female
- fallow = pRandom->IRandom(0,repInt);
-}
-else fallow = 9999;
-isDeveloping = false;
-pPrevCell = pCurrCell = pCell;
-pNatalPatch = pPatch;
-if (movt) {
- locn loc = pCell->getLocn();
- path = new pathData;
- path->year = 0; path->total = 0; path->out = 0;
- path->pSettPatch = 0; path->settleStatus = 0;
-// path->leftNatalPatch = false;
+ if (sex == 0 && repInt > 0) { // set no. of fallow seasons for female
+ fallow = pRandom->IRandom(0, repInt);
+ }
+ else fallow = 9999;
+ isDeveloping = false;
+ pPrevCell = pCurrCell = pCell;
+ pNatalPatch = pPatch;
+ if (movt) {
+ locn loc = pCell->getLocn();
+ path = new pathData;
+ path->year = 0; path->total = 0; path->out = 0;
+ path->pSettPatch = 0; path->settleStatus = 0;
#if RS_RCPP
- path->pathoutput = 1;
-#endif
- if (moveType == 1) { // SMS
- // set up location data for SMS
- smsData = new smsdata;
- smsData->dp = smsData->gb = smsData->alphaDB = 1.0;
- smsData->betaDB = 1;
- smsData->prev.x = loc.x; smsData->prev.y = loc.y; // previous location
- smsData->goal.x = loc.x; smsData->goal.y = loc.y; // goal location - initialised for dispersal bias
- }
- else smsData = 0;
- if (moveType == 2) { // CRW
- // set up continuous co-ordinates etc. for CRW movement
- crw = new crwParams;
- crw->xc = ((float)pRandom->Random()*0.999f) + (float)loc.x;
- crw->yc = (float)(pRandom->Random()*0.999f) + (float)loc.y;
- crw->prevdrn = (float)(pRandom->Random()*2.0 * PI);
- crw->stepL = crw->rho = 0.0;
- }
- else crw = 0;
-}
-else {
- path = 0; crw = 0; smsData = 0;
-}
-emigtraits = 0;
-kerntraits = 0;
-setttraits = 0;
-pGenome = 0;
-#if RSDEBUG
-//locn currloc = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::Individual(): indId=" << indId
-// << " x=" << currloc.x << " y=" << currloc.y
-//// << " smsData=" << smsData << " dp=" << smsData->dp
-// << endl;
-#endif
+ path->pathoutput = 1;
+#endif
+ if (moveType == 1) { // SMS
+ // set up location data for SMS
+ smsData = new smsdata;
+ smsData->dp = smsData->gb = smsData->alphaDB = 1.0;
+ smsData->betaDB = 1;
+ smsData->prev.x = loc.x; smsData->prev.y = loc.y; // previous location
+ smsData->goal.x = loc.x; smsData->goal.y = loc.y; // goal location - initialised for dispersal bias
+ }
+ else smsData = 0;
+ if (moveType == 2) { // CRW
+ // set up continuous co-ordinates etc. for CRW movement
+ crw = new crwParams;
+ crw->xc = ((float)pRandom->Random() * 0.999f) + (float)loc.x;
+ crw->yc = (float)(pRandom->Random() * 0.999f) + (float)loc.y;
+ crw->prevdrn = (float)(pRandom->Random() * 2.0 * PI);
+ crw->stepL = crw->rho = 0.0;
+ }
+ else crw = 0;
+ }
+ else {
+ path = 0; crw = 0; smsData = 0;
+ }
+ emigtraits = 0;
+ kerntraits = 0;
+ setttraits = 0;
+ pGenome = 0;
}
Individual::~Individual(void) {
-if (path != 0) delete path;
-if (crw != 0) delete crw;
-if (smsData != 0) delete smsData;
-if (emigtraits != 0) delete emigtraits;
-if (kerntraits != 0) delete kerntraits;
-if (setttraits != 0) delete setttraits;
+ if (path != 0) delete path;
+ if (crw != 0) delete crw;
+ if (smsData != 0) delete smsData;
+ if (emigtraits != 0) delete emigtraits;
+ if (kerntraits != 0) delete kerntraits;
+ if (setttraits != 0) delete setttraits;
-if (pGenome != 0) delete pGenome;
+ if (pGenome != 0) delete pGenome;
}
@@ -114,376 +102,301 @@ if (pGenome != 0) delete pGenome;
//---------------------------------------------------------------------------
// Set genes for individual variation from species initialisation parameters
-void Individual::setGenes(Species *pSpecies,int resol) {
-demogrParams dem = pSpecies->getDemogr();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
-genomeData gen = pSpecies->getGenomeData();
-simParams sim = paramsSim->getSim();
-int ntraits; // first trait for all/female expression, second for male expression
-
-if (gen.trait1Chromosome) {
- pGenome = new Genome(pSpecies->getNChromosomes(),pSpecies->getNLoci(0),
- pSpecies->isDiploid());
-}
-else {
- pGenome = new Genome(pSpecies);
-}
-#if RSDEBUG
-//DEBUGLOG << endl;
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " sex=" << sex
-// << " trait1Chromosome=" << gen.trait1Chromosome << " pGenome=" << pGenome
-// << endl;
-#endif
-
-int gposn = 0; // current position on genome
-int expr = 0; // gene expression type - NOT CURRENTLY USED
-
-//int emigposn = 0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setGenes(): emigration genes" << endl;
-#endif
-if (emig.indVar) { // set emigration genes
- int emigposn = gposn;
- double d0,alpha,beta;
- emigParams eparams;
-// emigScales scale = pSpecies->getEmigScales();
- if (emig.sexDep) { // must be a sexual species
- ntraits = 2;
+void Individual::setGenes(Species* pSpecies, int resol) {
+ demogrParams dem = pSpecies->getDemogr();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
+ genomeData gen = pSpecies->getGenomeData();
+ simParams sim = paramsSim->getSim();
+ int ntraits; // first trait for all/female expression, second for male expression
+
+ if (gen.trait1Chromosome) {
+ pGenome = new Genome(pSpecies->getNChromosomes(), pSpecies->getNLoci(0),
+ pSpecies->isDiploid());
}
else {
- if (dem.repType == 0) { // asexual reproduction (haploid)
- ntraits = 1;
- }
- else { // sexual reproduction
- ntraits = 1;
- }
+ pGenome = new Genome(pSpecies);
}
- for (int g = 0; g < ntraits; g++) { // first trait for females/all, second for males
- eparams = pSpecies->getEmigParams(0,g);
- d0 = pRandom->Normal(0.0,eparams.d0SD) / eparams.d0Scale;
- if (emig.densDep) {
- alpha = pRandom->Normal(0.0,eparams.alphaSD) / eparams.alphaScale;
- beta = pRandom->Normal(0.0,eparams.betaSD) / eparams.betaScale;
+
+ int gposn = 0; // current position on genome
+ int expr = 0; // gene expression type - NOT CURRENTLY USED
+
+ if (emig.indVar) { // set emigration genes
+ int emigposn = gposn;
+ double d0, alpha, beta;
+ emigParams eparams;
+ if (emig.sexDep) { // must be a sexual species
+ ntraits = 2;
}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " eparams.d0Mean=" << eparams.d0Mean << " eparams.d0SD=" << eparams.d0SD
-// << " eparams.d0Scale=" << eparams.d0Scale << " d0=" << d0
-//// << " log(d0/(1.0-d0))=" << log(d0/(1.0-d0))
-// << endl;
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " eparams.alphaMean=" << eparams.alphaMean << " eparams.alphaSD=" << eparams.alphaSD
-// << " eparams.alphaScale=" << eparams.alphaScale << " alpha=" << alpha
-// << endl;
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " eparams.betaMean=" << eparams.betaMean << " eparams.betaSD=" << eparams.betaSD
-// << " eparams.betaScale=" << eparams.betaScale << " beta=" << beta
-// << endl;
-#endif
- if (gen.trait1Chromosome) {
- pGenome->setGene(gposn++,expr,d0,gen.alleleSD);
- if (emig.densDep) {
- pGenome->setGene(gposn++,expr,alpha,gen.alleleSD);
- pGenome->setGene(gposn++,expr,beta,gen.alleleSD);
+ else {
+ if (dem.repType == 0) { // asexual reproduction (haploid)
+ ntraits = 1;
+ }
+ else { // sexual reproduction
+ ntraits = 1;
}
}
- else {
- pGenome->setTrait(pSpecies,gposn++,d0,gen.alleleSD);
+ for (int g = 0; g < ntraits; g++) { // first trait for females/all, second for males
+ eparams = pSpecies->getEmigParams(0, g);
+ d0 = pRandom->Normal(0.0, eparams.d0SD) / eparams.d0Scale;
if (emig.densDep) {
- pGenome->setTrait(pSpecies,gposn++,alpha,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,beta,gen.alleleSD);
+ alpha = pRandom->Normal(0.0, eparams.alphaSD) / eparams.alphaScale;
+ beta = pRandom->Normal(0.0, eparams.betaSD) / eparams.betaScale;
+ }
+ if (gen.trait1Chromosome) {
+ pGenome->setGene(gposn++, expr, d0, gen.alleleSD);
+ if (emig.densDep) {
+ pGenome->setGene(gposn++, expr, alpha, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, beta, gen.alleleSD);
+ }
+ }
+ else {
+ pGenome->setTrait(pSpecies, gposn++, d0, gen.alleleSD);
+ if (emig.densDep) {
+ pGenome->setTrait(pSpecies, gposn++, alpha, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, beta, gen.alleleSD);
+ }
}
}
- }
- // record phenotypic traits
- if (emig.densDep) {
- setEmigTraits(pSpecies,emigposn,3,emig.sexDep);
- }
- else {
- setEmigTraits(pSpecies,emigposn,1,emig.sexDep);
- }
-}
-
-//int trfrposn = 0;
-if (trfr.indVar) { // set transfer genes
- int trfrposn = gposn;
- if (trfr.sexDep) { // must be a sexual species
- ntraits = 2;
- }
- else {
- if (dem.repType == 0) { // asexual reproduction
- ntraits = 1;
+ // record phenotypic traits
+ if (emig.densDep) {
+ setEmigTraits(pSpecies, emigposn, 3, emig.sexDep);
}
- else { // sexual reproduction
- ntraits = 1;
+ else {
+ setEmigTraits(pSpecies, emigposn, 1, emig.sexDep);
}
}
-// trfrScales scale = pSpecies->getTrfrScales();
- if (trfr.moveModel) {
- if (trfr.moveType == 1) { // set SMS genes
- double dp,gb,alphaDB,betaDB;
- trfrSMSParams smsparams = pSpecies->getSMSParams(0,0); // only traits for females/all
- trfrSMSTraits smstraits = pSpecies->getSMSTraits();
- dp = pRandom->Normal(0.0,smsparams.dpSD) / smsparams.dpScale;
- gb = pRandom->Normal(0.0,smsparams.gbSD) / smsparams.gbScale;
- if (smstraits.goalType == 2) {
- alphaDB = pRandom->Normal(0.0,smsparams.alphaDBSD) / smsparams.alphaDBScale;
- betaDB = pRandom->Normal(0.0,smsparams.betaDBSD) / smsparams.betaDBScale;
+
+ //int trfrposn = 0;
+ if (trfr.indVar) { // set transfer genes
+ int trfrposn = gposn;
+ if (trfr.sexDep) { // must be a sexual species
+ ntraits = 2;
+ }
+ else {
+ if (dem.repType == 0) { // asexual reproduction
+ ntraits = 1;
}
- if (gen.trait1Chromosome) {
- pGenome->setGene(gposn++,expr,dp,gen.alleleSD);
- pGenome->setGene(gposn++,expr,gb,gen.alleleSD);
+ else { // sexual reproduction
+ ntraits = 1;
+ }
+ }
+ if (trfr.moveModel) {
+ if (trfr.moveType == 1) { // set SMS genes
+ double dp, gb, alphaDB, betaDB;
+ trfrSMSParams smsparams = pSpecies->getSMSParams(0, 0); // only traits for females/all
+ trfrSMSTraits smstraits = pSpecies->getSMSTraits();
+ dp = pRandom->Normal(0.0, smsparams.dpSD) / smsparams.dpScale;
+ gb = pRandom->Normal(0.0, smsparams.gbSD) / smsparams.gbScale;
if (smstraits.goalType == 2) {
- pGenome->setGene(gposn++,expr,alphaDB,gen.alleleSD);
- pGenome->setGene(gposn++,expr,betaDB,gen.alleleSD);
+ alphaDB = pRandom->Normal(0.0, smsparams.alphaDBSD) / smsparams.alphaDBScale;
+ betaDB = pRandom->Normal(0.0, smsparams.betaDBSD) / smsparams.betaDBScale;
+ }
+ if (gen.trait1Chromosome) {
+ pGenome->setGene(gposn++, expr, dp, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, gb, gen.alleleSD);
+ if (smstraits.goalType == 2) {
+ pGenome->setGene(gposn++, expr, alphaDB, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, betaDB, gen.alleleSD);
+ }
+ }
+ else {
+ pGenome->setTrait(pSpecies, gposn++, dp, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, gb, gen.alleleSD);
+ if (smstraits.goalType == 2) {
+ pGenome->setTrait(pSpecies, gposn++, alphaDB, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, betaDB, gen.alleleSD);
+ }
}
+ // record phenotypic traits
+ if (smstraits.goalType == 2)
+ setSMSTraits(pSpecies, trfrposn, 4, false);
+ else
+ setSMSTraits(pSpecies, trfrposn, 2, false);
}
- else {
- pGenome->setTrait(pSpecies,gposn++,dp,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,gb,gen.alleleSD);
- if (smstraits.goalType == 2) {
- pGenome->setTrait(pSpecies,gposn++,alphaDB,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,betaDB,gen.alleleSD);
+ if (trfr.moveType == 2) { // set CRW genes
+ double stepL, rho;
+ trfrCRWParams m = pSpecies->getCRWParams(0, 0); // only traits for females/all
+ stepL = pRandom->Normal(0.0, m.stepLgthSD) / m.stepLScale;
+ rho = pRandom->Normal(0.0, m.rhoSD) / m.rhoScale;
+ if (gen.trait1Chromosome) {
+ pGenome->setGene(gposn++, expr, stepL, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, rho, gen.alleleSD);
+ }
+ else {
+ pGenome->setTrait(pSpecies, gposn++, stepL, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, rho, gen.alleleSD);
+ }
+ // record phenotypic traits
+ setCRWTraits(pSpecies, trfrposn, 2, false);
+ }
+ }
+ else { // set kernel genes
+ double dist1, dist2, prob1;
+ trfrKernParams k;
+ for (int g = 0; g < ntraits; g++) { // first traits for females/all, second for males
+ k = pSpecies->getKernParams(0, g);
+ dist1 = pRandom->Normal(0.0, k.dist1SD) / k.dist1Scale;
+ if (trfr.twinKern)
+ {
+ dist2 = pRandom->Normal(0.0, k.dist2SD) / k.dist2Scale;
+ prob1 = pRandom->Normal(0.0, k.PKern1SD) / k.PKern1Scale;
+ }
+ if (gen.trait1Chromosome) {
+ pGenome->setGene(gposn++, expr, dist1, gen.alleleSD);
+ if (trfr.twinKern)
+ {
+ pGenome->setGene(gposn++, expr, dist2, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, prob1, gen.alleleSD);
+ }
+ }
+ else {
+ pGenome->setTrait(pSpecies, gposn++, dist1, gen.alleleSD);
+ if (trfr.twinKern)
+ {
+ pGenome->setTrait(pSpecies, gposn++, dist2, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, prob1, gen.alleleSD);
+ }
}
}
// record phenotypic traits
- if (smstraits.goalType == 2)
- setSMSTraits(pSpecies,trfrposn,4,false);
- else
- setSMSTraits(pSpecies,trfrposn,2,false);
- }
- if (trfr.moveType == 2) { // set CRW genes
- double stepL,rho;
- trfrCRWParams m = pSpecies->getCRWParams(0,0); // only traits for females/all
- stepL = pRandom->Normal(0.0,m.stepLgthSD) / m.stepLScale;
- rho = pRandom->Normal(0.0,m.rhoSD) / m.rhoScale;
- if (gen.trait1Chromosome) {
- pGenome->setGene(gposn++,expr,stepL,gen.alleleSD);
- pGenome->setGene(gposn++,expr,rho,gen.alleleSD);
+ if (trfr.twinKern)
+ {
+ setKernTraits(pSpecies, trfrposn, 3, resol, trfr.sexDep);
}
else {
- pGenome->setTrait(pSpecies,gposn++,stepL,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,rho,gen.alleleSD);
+ setKernTraits(pSpecies, trfrposn, 1, resol, trfr.sexDep);
}
- // record phenotypic traits
- setCRWTraits(pSpecies,trfrposn,2,false);
}
}
- else { // set kernel genes
- double dist1,dist2,prob1;
- trfrKernParams k;
- for (int g = 0; g < ntraits; g++) { // first traits for females/all, second for males
- k = pSpecies->getKernParams(0,g);
- dist1 = pRandom->Normal(0.0,k.dist1SD) / k.dist1Scale;
- if (trfr.twinKern)
- {
- dist2 = pRandom->Normal(0.0,k.dist2SD) / k.dist2Scale;
- prob1 = pRandom->Normal(0.0,k.PKern1SD) / k.PKern1Scale;
+
+ if (sett.indVar) {
+ int settposn = gposn;
+ double s0, alpha, beta;
+ settParams sparams;
+ if (sett.sexDep) { // must be a sexual species
+ ntraits = 2;
+ }
+ else {
+ if (dem.repType == 0) { // asexual reproduction
+ ntraits = 1;
}
+ else { // sexual reproduction
+ ntraits = 1;
+ }
+ }
+ for (int g = 0; g < ntraits; g++) { // first trait for females/all, second for males
+ if (sim.batchMode) {
+ sparams = pSpecies->getSettParams(0, g);
+ }
+ else { // individual variability not (yet) implemented as sex-dependent in GUI
+ sparams = pSpecies->getSettParams(0, 0);
+ }
+ s0 = pRandom->Normal(0.0, sparams.s0SD) / sparams.s0Scale;
+ alpha = pRandom->Normal(0.0, sparams.alphaSSD) / sparams.alphaSScale;
+ beta = pRandom->Normal(0.0, sparams.betaSSD) / sparams.betaSScale;
+
if (gen.trait1Chromosome) {
- pGenome->setGene(gposn++,expr,dist1,gen.alleleSD);
- if (trfr.twinKern)
- {
- pGenome->setGene(gposn++,expr,dist2,gen.alleleSD);
- pGenome->setGene(gposn++,expr,prob1,gen.alleleSD);
- }
+ pGenome->setGene(gposn++, expr, s0, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, alpha, gen.alleleSD);
+ pGenome->setGene(gposn++, expr, beta, gen.alleleSD);
}
else {
- pGenome->setTrait(pSpecies,gposn++,dist1,gen.alleleSD);
- if (trfr.twinKern)
- {
- pGenome->setTrait(pSpecies,gposn++,dist2,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,prob1,gen.alleleSD);
- }
- }
+ pGenome->setTrait(pSpecies, gposn++, s0, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, alpha, gen.alleleSD);
+ pGenome->setTrait(pSpecies, gposn++, beta, gen.alleleSD);
+ }
}
// record phenotypic traits
- if (trfr.twinKern)
- {
- setKernTraits(pSpecies,trfrposn,3,resol,trfr.sexDep);
- }
- else {
- setKernTraits(pSpecies,trfrposn,1,resol,trfr.sexDep);
- }
+ setSettTraits(pSpecies, settposn, 3, sett.sexDep);
}
-}
-//int settposn = 0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setGenes(): settlement genes" << endl;
-#endif
-if (sett.indVar) {
- int settposn = gposn;
- double s0,alpha,beta;
- settParams sparams;
-// settScales scale = pSpecies->getSettScales();
- if (sett.sexDep) { // must be a sexual species
- ntraits = 2;
- }
- else {
- if (dem.repType == 0) { // asexual reproduction
- ntraits = 1;
- }
- else { // sexual reproduction
- ntraits = 1;
- }
- }
- for (int g = 0; g < ntraits; g++) { // first trait for females/all, second for males
- if (sim.batchMode) {
- sparams = pSpecies->getSettParams(0,g);
- }
- else { // individual variability not (yet) implemented as sex-dependent in GUI
- sparams = pSpecies->getSettParams(0,0);
- }
- s0 = pRandom->Normal(0.0,sparams.s0SD) / sparams.s0Scale;
- alpha = pRandom->Normal(0.0,sparams.alphaSSD) / sparams.alphaSScale;
- beta = pRandom->Normal(0.0,sparams.betaSSD) / sparams.betaSScale;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " sparams.s0Mean=" << sparams.s0Mean
-// << " sparams.s0SD=" << sparams.s0SD
-// << " sparams.s0Scale=" << sparams.s0Scale
-// << " s0=" << s0
-// << endl;
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " sparams.alphaSMean=" << sparams.alphaSMean
-// << " sparams.alphaSSD=" << sparams.alphaSSD
-// << " sparams.alphaSScale=" << sparams.alphaSScale
-// << " alpha=" << alpha
-// << endl;
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " g=" << g
-// << " sparams.betaSMean=" << sparams.betaSMean
-// << " sparams.betaSSD=" << sparams.betaSSD
-// << " sparams.betaSScale=" << sparams.betaSScale
-// << " beta=" << beta
-// << endl;
-#endif
- if (gen.trait1Chromosome) {
- pGenome->setGene(gposn++,expr,s0,gen.alleleSD);
- pGenome->setGene(gposn++,expr,alpha,gen.alleleSD);
- pGenome->setGene(gposn++,expr,beta,gen.alleleSD);
- }
- else {
- pGenome->setTrait(pSpecies,gposn++,s0,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,alpha,gen.alleleSD);
- pGenome->setTrait(pSpecies,gposn++,beta,gen.alleleSD);
+ if (!gen.trait1Chromosome) {
+ if (gen.neutralMarkers || pSpecies->getNNeutralLoci() > 0) {
+ pGenome->setNeutralLoci(pSpecies, gen.alleleSD);
}
}
- // record phenotypic traits
- setSettTraits(pSpecies,settposn,3,sett.sexDep);
-}
-
-if (!gen.trait1Chromosome) {
- if (gen.neutralMarkers || pSpecies->getNNeutralLoci() > 0) {
- pGenome->setNeutralLoci(pSpecies,gen.alleleSD);
- }
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " finished"
-// << endl;
-#endif
}
// Inherit genome from parent(s)
-void Individual::setGenes(Species *pSpecies,Individual *mother,Individual *father,
+void Individual::setGenes(Species* pSpecies, Individual* mother, Individual* father,
int resol)
{
-#if RSDEBUG
-//locn currloc = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId
-// << " x=" << currloc.x << " y=" << currloc.y
-//// << " pSpecies=" << pSpecies
-// << " mother=" << mother
-// << " motherID=" << mother->getId()
-// << " father=" << father;
-//if (father != 0) DEBUGLOG << " fatherID=" << father->getId();
-//DEBUGLOG << endl;
-#endif
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
-
-Genome *pFatherGenome;
-if (father == 0) pFatherGenome = 0; else pFatherGenome = father->pGenome;
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
-pGenome = new Genome(pSpecies,mother->pGenome,pFatherGenome);
+ Genome* pFatherGenome;
+ if (father == 0) pFatherGenome = 0; else pFatherGenome = father->pGenome;
-if (emig.indVar) {
- // record emigration traits
- if (father == 0) { // haploid
- if (emig.densDep) {
- setEmigTraits(pSpecies,0,3,0);
- }
- else {
- setEmigTraits(pSpecies,0,1,0);
- }
- }
- else { // diploid
- if (emig.densDep) {
- setEmigTraits(pSpecies,0,3,emig.sexDep);
- }
- else {
- setEmigTraits(pSpecies,0,1,emig.sexDep);
- }
- }
-}
+ pGenome = new Genome(pSpecies, mother->pGenome, pFatherGenome);
-if (trfr.indVar) {
- // record movement model traits
- if (trfr.moveModel) {
- if (trfr.moveType == 1) { // SMS
- trfrSMSTraits s = pSpecies->getSMSTraits();
- if (s.goalType == 2)
- setSMSTraits(pSpecies,trfr.movtTrait[0],4,0);
- else
- setSMSTraits(pSpecies,trfr.movtTrait[0],2,0);
- }
- if (trfr.moveType == 2) { // CRW
- setCRWTraits(pSpecies,trfr.movtTrait[0],2,0);
- }
- }
- else { // kernel
+ if (emig.indVar) {
+ // record emigration traits
if (father == 0) { // haploid
- if (trfr.twinKern)
- {
- setKernTraits(pSpecies,trfr.movtTrait[0],3,resol,0);
+ if (emig.densDep) {
+ setEmigTraits(pSpecies, 0, 3, 0);
}
else {
- setKernTraits(pSpecies,trfr.movtTrait[0],1,resol,0);
+ setEmigTraits(pSpecies, 0, 1, 0);
}
}
else { // diploid
- if (trfr.twinKern)
- {
- setKernTraits(pSpecies,trfr.movtTrait[0],3,resol,trfr.sexDep);
+ if (emig.densDep) {
+ setEmigTraits(pSpecies, 0, 3, emig.sexDep);
}
else {
- setKernTraits(pSpecies,trfr.movtTrait[0],1,resol,trfr.sexDep);
+ setEmigTraits(pSpecies, 0, 1, emig.sexDep);
}
}
}
-}
-if (sett.indVar) {
- // record settlement traits
- if (father == 0) { // haploid
- setSettTraits(pSpecies,sett.settTrait[0],3,0);
- }
- else { // diploid
- setSettTraits(pSpecies,sett.settTrait[0],3,sett.sexDep);
-// setSettTraits(pSpecies,sett.settTrait[0],3,0);
+ if (trfr.indVar) {
+ // record movement model traits
+ if (trfr.moveModel) {
+ if (trfr.moveType == 1) { // SMS
+ trfrSMSTraits s = pSpecies->getSMSTraits();
+ if (s.goalType == 2)
+ setSMSTraits(pSpecies, trfr.movtTrait[0], 4, 0);
+ else
+ setSMSTraits(pSpecies, trfr.movtTrait[0], 2, 0);
+ }
+ if (trfr.moveType == 2) { // CRW
+ setCRWTraits(pSpecies, trfr.movtTrait[0], 2, 0);
+ }
+ }
+ else { // kernel
+ if (father == 0) { // haploid
+ if (trfr.twinKern)
+ {
+ setKernTraits(pSpecies, trfr.movtTrait[0], 3, resol, 0);
+ }
+ else {
+ setKernTraits(pSpecies, trfr.movtTrait[0], 1, resol, 0);
+ }
+ }
+ else { // diploid
+ if (trfr.twinKern)
+ {
+ setKernTraits(pSpecies, trfr.movtTrait[0], 3, resol, trfr.sexDep);
+ }
+ else {
+ setKernTraits(pSpecies, trfr.movtTrait[0], 1, resol, trfr.sexDep);
+ }
+ }
+ }
}
-}
-#if RSDEBUG
-//emigParams e = getEmigTraits(0,1,0);
-//DEBUGLOG << "Individual::setGenes(): indId=" << indId << " finished "
-// << " d0=" << e.d0
-//// << " alpha=" << e.alpha << " beta=" << e.beta
-// << endl;
-#endif
+ if (sett.indVar) {
+ // record settlement traits
+ if (father == 0) { // haploid
+ setSettTraits(pSpecies, sett.settTrait[0], 3, 0);
+ }
+ else { // diploid
+ setSettTraits(pSpecies, sett.settTrait[0], 3, sett.sexDep);
+ }
+ }
}
//---------------------------------------------------------------------------
@@ -491,12 +404,12 @@ if (sett.indVar) {
// Identify whether an individual is a potentially breeding female -
// if so, return her stage, otherwise return 0
int Individual::breedingFem(void) {
-if (sex == 0) {
- if (status == 0 || status == 4 || status == 5) return stage;
+ if (sex == 0) {
+ if (status == 0 || status == 4 || status == 5) return stage;
+ else return 0;
+ }
else return 0;
}
-else return 0;
-}
int Individual::getId(void) { return indId; }
@@ -505,617 +418,428 @@ int Individual::getSex(void) { return sex; }
int Individual::getStatus(void) { return status; }
indStats Individual::getStats(void) {
-indStats s;
-s.stage = stage; s.sex = sex; s.age = age; s.status = status; s.fallow = fallow;
-s.isDeveloping = isDeveloping;
-return s;
+ indStats s;
+ s.stage = stage; s.sex = sex; s.age = age; s.status = status; s.fallow = fallow;
+ s.isDeveloping = isDeveloping;
+ return s;
}
Cell* Individual::getLocn(const short option) {
-if (option == 0) { // return previous location
- return pPrevCell;
-}
-else { // return current location
- return pCurrCell;
-}
+ if (option == 0) { // return previous location
+ return pPrevCell;
+ }
+ else { // return current location
+ return pCurrCell;
+ }
}
Patch* Individual::getNatalPatch(void) { return pNatalPatch; }
void Individual::setYearSteps(int t) {
-if (path != 0 && t >= 0) {
- if (t >= 0) path->year = t;
- else path->year = 666;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setYearSteps(): indId=" << indId
-// << " t=" << t << " path->year=" << path->year
-// << endl;
-#endif
+ if (path != 0 && t >= 0) {
+ if (t >= 0) path->year = t;
+ else path->year = 666;
+ }
}
pathSteps Individual::getSteps(void) {
-pathSteps s;
-if (path == 0) {
- s.year = 0; s.total = 0; s.out = 0;
-}
-else {
- s.year = path->year; s.total = path->total; s.out = path->out;
-}
-return s;
+ pathSteps s;
+ if (path == 0) {
+ s.year = 0; s.total = 0; s.out = 0;
+ }
+ else {
+ s.year = path->year; s.total = path->total; s.out = path->out;
+ }
+ return s;
}
settlePatch Individual::getSettPatch(void) {
-settlePatch s;
-if (path == 0) {
- s.pSettPatch = 0; s.settleStatus = 0;
-}
-else {
- s.pSettPatch = path->pSettPatch; s.settleStatus = path->settleStatus;
-}
-return s;
+ settlePatch s;
+ if (path == 0) {
+ s.pSettPatch = 0; s.settleStatus = 0;
+ }
+ else {
+ s.pSettPatch = path->pSettPatch; s.settleStatus = path->settleStatus;
+ }
+ return s;
}
void Individual::setSettPatch(const settlePatch s) {
-if (path == 0) {
- path = new pathData;
- path->year = 0; path->total = 0; path->out = 0; path->settleStatus = 0;
+ if (path == 0) {
+ path = new pathData;
+ path->year = 0; path->total = 0; path->out = 0; path->settleStatus = 0;
#if RS_RCPP
- path->pathoutput = 1;
+ path->pathoutput = 1;
#endif
-}
-if (s.settleStatus >= 0 && s.settleStatus <= 2) path->settleStatus = s.settleStatus;
-path->pSettPatch = s.pSettPatch;
+ }
+ if (s.settleStatus >= 0 && s.settleStatus <= 2) path->settleStatus = s.settleStatus;
+ path->pSettPatch = s.pSettPatch;
}
// Set phenotypic emigration traits
-void Individual::setEmigTraits(Species *pSpecies,short emiggenelocn,short nemigtraits,
+void Individual::setEmigTraits(Species* pSpecies, short emiggenelocn, short nemigtraits,
bool sexdep) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::setEmigTraits(): indId=" << indId
-// << " emiggenelocn=" << emiggenelocn << " nemigtraits=" << nemigtraits << " sexdep=" << sexdep
-// << endl;
-#endif
-emigTraits e; e.d0 = e.alpha = e.beta = 0.0;
-if (pGenome != 0) {
- if (pSpecies->has1ChromPerTrait()) {
- if (sexdep) {
- if (nemigtraits == 3) { // emigration is density-dependent
- e.d0 = (float)pGenome->express(emiggenelocn+3*sex,0,0);
- e.alpha = (float)pGenome->express(emiggenelocn+3*sex+1,0,0);
- e.beta = (float)pGenome->express(emiggenelocn+3*sex+2,0,0);
+ emigTraits e; e.d0 = e.alpha = e.beta = 0.0;
+ if (pGenome != 0) {
+ if (pSpecies->has1ChromPerTrait()) {
+ if (sexdep) {
+ if (nemigtraits == 3) { // emigration is density-dependent
+ e.d0 = (float)pGenome->express(emiggenelocn + 3 * sex, 0, 0);
+ e.alpha = (float)pGenome->express(emiggenelocn + 3 * sex + 1, 0, 0);
+ e.beta = (float)pGenome->express(emiggenelocn + 3 * sex + 2, 0, 0);
+ }
+ else {
+ e.d0 = (float)pGenome->express(emiggenelocn + sex, 0, 0);
+ }
}
else {
- e.d0 = (float)pGenome->express(emiggenelocn+sex,0,0);
+ e.d0 = (float)pGenome->express(emiggenelocn, 0, 0);
+ if (nemigtraits == 3) { // emigration is density-dependent
+ e.alpha = (float)pGenome->express(emiggenelocn + 1, 0, 0);
+ e.beta = (float)pGenome->express(emiggenelocn + 2, 0, 0);
+ }
}
}
else {
- e.d0 = (float)pGenome->express(emiggenelocn,0,0);
- if (nemigtraits == 3) { // emigration is density-dependent
- e.alpha = (float)pGenome->express(emiggenelocn+1,0,0);
- e.beta = (float)pGenome->express(emiggenelocn+2,0,0);
- }
- }
- }
- else {
- if (sexdep) {
- if (nemigtraits == 3) { // emigration is density-dependent
- e.d0 = (float)pGenome->express(pSpecies,emiggenelocn+3*sex);
- e.alpha = (float)pGenome->express(pSpecies,emiggenelocn+3*sex+1);
- e.beta = (float)pGenome->express(pSpecies,emiggenelocn+3*sex+2);
+ if (sexdep) {
+ if (nemigtraits == 3) { // emigration is density-dependent
+ e.d0 = (float)pGenome->express(pSpecies, emiggenelocn + 3 * sex);
+ e.alpha = (float)pGenome->express(pSpecies, emiggenelocn + 3 * sex + 1);
+ e.beta = (float)pGenome->express(pSpecies, emiggenelocn + 3 * sex + 2);
+ }
+ else {
+ e.d0 = (float)pGenome->express(pSpecies, emiggenelocn + sex);
+ }
}
else {
- e.d0 = (float)pGenome->express(pSpecies,emiggenelocn+sex);
- }
- }
- else {
- e.d0 = (float)pGenome->express(pSpecies,emiggenelocn);
- if (nemigtraits == 3) { // emigration is density-dependent
- e.alpha = (float)pGenome->express(pSpecies,emiggenelocn+1);
- e.beta = (float)pGenome->express(pSpecies,emiggenelocn+2);
+ e.d0 = (float)pGenome->express(pSpecies, emiggenelocn);
+ if (nemigtraits == 3) { // emigration is density-dependent
+ e.alpha = (float)pGenome->express(pSpecies, emiggenelocn + 1);
+ e.beta = (float)pGenome->express(pSpecies, emiggenelocn + 2);
+ }
}
}
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setEmigTraits(): indId=" << indId
-// << " e.d0=" << e.d0 << " e.alpha=" << e.alpha << " e.beta=" << e.beta
-// << endl;
-#endif
-emigParams eparams;
-if (sexdep) {
- eparams = pSpecies->getEmigParams(0,sex);
-}
-else {
- eparams = pSpecies->getEmigParams(0,0);
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setEmigTraits(): indId=" << indId
-// << " eparams.betaMean=" << eparams.betaMean << " eparams.betaSD=" << eparams.betaSD
-// << " eparams.betaScale=" << eparams.betaScale
-// << endl;
-#endif
-emigtraits = new emigTraits;
-emigtraits->d0 = (float)(e.d0*eparams.d0Scale + eparams.d0Mean);
-emigtraits->alpha = (float)(e.alpha*eparams.alphaScale + eparams.alphaMean);
-emigtraits->beta = (float)(e.beta*eparams.betaScale + eparams.betaMean);
-#if RSDEBUG
-//DEBUGLOG << "Individual::setEmigTraits(): indId=" << indId
-// << " emigtraits->d0=" << emigtraits->d0
-// << " emigtraits->alpha=" << emigtraits->alpha << " emigtraits->beta=" << emigtraits->beta
-// << endl;
-#endif
-if (emigtraits->d0 < 0.0) emigtraits->d0 = 0.0;
-if (emigtraits->d0 > 1.0) emigtraits->d0 = 1.0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setEmigTraits(): indId=" << indId
-// << " emigtraits->d0=" << emigtraits->d0
-// << " emigtraits->alpha=" << emigtraits->alpha << " emigtraits->beta=" << emigtraits->beta
-// << endl;
-#endif
-return;
+ emigParams eparams;
+ if (sexdep) {
+ eparams = pSpecies->getEmigParams(0, sex);
+ }
+ else {
+ eparams = pSpecies->getEmigParams(0, 0);
+ }
+ emigtraits = new emigTraits;
+ emigtraits->d0 = (float)(e.d0 * eparams.d0Scale + eparams.d0Mean);
+ emigtraits->alpha = (float)(e.alpha * eparams.alphaScale + eparams.alphaMean);
+ emigtraits->beta = (float)(e.beta * eparams.betaScale + eparams.betaMean);
+ if (emigtraits->d0 < 0.0) emigtraits->d0 = 0.0;
+ if (emigtraits->d0 > 1.0) emigtraits->d0 = 1.0;
+ return;
}
// Get phenotypic emigration traits
emigTraits Individual::getEmigTraits(void) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getEmigTraits(): indId=" << indId
-// << endl;
-#endif
-emigTraits e; e.d0 = e.alpha = e.beta = 0.0;
-if (emigtraits != 0) {
- e.d0 = emigtraits->d0;
- e.alpha = emigtraits->alpha;
- e.beta = emigtraits->beta;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::getEmigTraits(): indId=" << indId
-// << " e.d0=" << e.d0 << " e.alpha=" << e.alpha << " e.beta=" << e.beta
-// << endl;
-#endif
-
-return e;
+ emigTraits e; e.d0 = e.alpha = e.beta = 0.0;
+ if (emigtraits != 0) {
+ e.d0 = emigtraits->d0;
+ e.alpha = emigtraits->alpha;
+ e.beta = emigtraits->beta;
+ }
+ return e;
}
// Set phenotypic transfer by kernel traits
-void Individual::setKernTraits(Species *pSpecies,short kerngenelocn,short nkerntraits,
- int resol,bool sexdep) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::setKernTraits(): indId=" << indId
-// << " kerngenelocn=" << kerngenelocn << " nkerntraits=" << nkerntraits << " sexdep=" << sexdep
-// << endl;
-#endif
-trfrKernTraits k; k.meanDist1 = k.meanDist2 = k.probKern1 = 0.0;
-if (pGenome != 0) {
- if (pSpecies->has1ChromPerTrait()) {
- if (sexdep) {
- if (nkerntraits == 3) { // twin kernel
- k.meanDist1 = (float)pGenome->express(kerngenelocn+3*sex,0,sex);
- k.meanDist2 = (float)pGenome->express(kerngenelocn+3*sex+1,0,sex);
- k.probKern1 = (float)pGenome->express(kerngenelocn+3*sex+2,0,sex);
+void Individual::setKernTraits(Species* pSpecies, short kerngenelocn, short nkerntraits,
+ int resol, bool sexdep) {
+ trfrKernTraits k; k.meanDist1 = k.meanDist2 = k.probKern1 = 0.0;
+ if (pGenome != 0) {
+ if (pSpecies->has1ChromPerTrait()) {
+ if (sexdep) {
+ if (nkerntraits == 3) { // twin kernel
+ k.meanDist1 = (float)pGenome->express(kerngenelocn + 3 * sex, 0, sex);
+ k.meanDist2 = (float)pGenome->express(kerngenelocn + 3 * sex + 1, 0, sex);
+ k.probKern1 = (float)pGenome->express(kerngenelocn + 3 * sex + 2, 0, sex);
+ }
+ else {
+ k.meanDist1 = (float)pGenome->express(kerngenelocn + sex, 0, sex);
+ }
}
else {
- k.meanDist1 = (float)pGenome->express(kerngenelocn+sex,0,sex);
+ k.meanDist1 = (float)pGenome->express(kerngenelocn, 0, 0);
+ if (nkerntraits == 3) { // twin kernel
+ k.meanDist2 = (float)pGenome->express(kerngenelocn + 1, 0, 0);
+ k.probKern1 = (float)pGenome->express(kerngenelocn + 2, 0, 0);
+ }
}
}
else {
- k.meanDist1 = (float)pGenome->express(kerngenelocn,0,0);
- if (nkerntraits == 3) { // twin kernel
- k.meanDist2 = (float)pGenome->express(kerngenelocn+1,0,0);
- k.probKern1 = (float)pGenome->express(kerngenelocn+2,0,0);
- }
- }
- }
- else {
- if (sexdep) {
- if (nkerntraits == 3) { // twin kernel
- k.meanDist1 = (float)pGenome->express(pSpecies,kerngenelocn+3*sex);
- k.meanDist2 = (float)pGenome->express(pSpecies,kerngenelocn+3*sex+1);
- k.probKern1 = (float)pGenome->express(pSpecies,kerngenelocn+3*sex+2);
+ if (sexdep) {
+ if (nkerntraits == 3) { // twin kernel
+ k.meanDist1 = (float)pGenome->express(pSpecies, kerngenelocn + 3 * sex);
+ k.meanDist2 = (float)pGenome->express(pSpecies, kerngenelocn + 3 * sex + 1);
+ k.probKern1 = (float)pGenome->express(pSpecies, kerngenelocn + 3 * sex + 2);
+ }
+ else {
+ k.meanDist1 = (float)pGenome->express(pSpecies, kerngenelocn + sex);
+ }
}
else {
- k.meanDist1 = (float)pGenome->express(pSpecies,kerngenelocn+sex);
- }
- }
- else {
- k.meanDist1 = (float)pGenome->express(pSpecies,kerngenelocn);
- if (nkerntraits == 3) { // twin kernel
- k.meanDist2 = (float)pGenome->express(pSpecies,kerngenelocn+1);
- k.probKern1 = (float)pGenome->express(pSpecies,kerngenelocn+2);
+ k.meanDist1 = (float)pGenome->express(pSpecies, kerngenelocn);
+ if (nkerntraits == 3) { // twin kernel
+ k.meanDist2 = (float)pGenome->express(pSpecies, kerngenelocn + 1);
+ k.probKern1 = (float)pGenome->express(pSpecies, kerngenelocn + 2);
+ }
}
}
- }
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setKernTraits(): indId=" << indId
-// << " k.meanDist1=" << k.meanDist1 << " k.meanDist2=" << k.meanDist2
-// << " k.probKern1=" << k.probKern1
-// << endl;
-#endif
+ }
-trfrKernParams kparams;
-if (sexdep) {
- kparams = pSpecies->getKernParams(0,sex);
-}
-else {
- kparams = pSpecies->getKernParams(0,0);
-}
-kerntraits = new trfrKernTraits;
-kerntraits->meanDist1 = (float)(k.meanDist1*kparams.dist1Scale + kparams.dist1Mean);
-kerntraits->meanDist2 = (float)(k.meanDist2*kparams.dist2Scale + kparams.dist2Mean);
-kerntraits->probKern1 = (float)(k.probKern1*kparams.PKern1Scale + kparams.PKern1Mean);
-#if RSDEBUG
-//DEBUGLOG << "Individual::setKernTraits(): indId=" << indId
-// << " kerntraits->meanDist1=" << kerntraits->meanDist1
-// << " kerntraits->meanDist2=" << kerntraits->meanDist2
-// << " kerntraits->probKern1=" << kerntraits->probKern1
-// << endl;
-#endif
-if (!pSpecies->useFullKernel()) {
- // kernel mean(s) may not be less than landscape resolution
- if (kerntraits->meanDist1 < resol) kerntraits->meanDist1 = (float)resol;
- if (kerntraits->meanDist2 < resol) kerntraits->meanDist2 = (float)resol;
-}
-if (kerntraits->probKern1 < 0.0) kerntraits->probKern1 = 0.0;
-if (kerntraits->probKern1 > 1.0) kerntraits->probKern1 = 1.0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setKernTraits(): indId=" << indId
-// << " kerntraits->meanDist1=" << kerntraits->meanDist1
-// << " kerntraits->meanDist2=" << kerntraits->meanDist2
-// << " kerntraits->probKern1=" << kerntraits->probKern1
-// << endl;
-#endif
-return;
+ trfrKernParams kparams;
+ if (sexdep) {
+ kparams = pSpecies->getKernParams(0, sex);
+ }
+ else {
+ kparams = pSpecies->getKernParams(0, 0);
+ }
+ kerntraits = new trfrKernTraits;
+ kerntraits->meanDist1 = (float)(k.meanDist1 * kparams.dist1Scale + kparams.dist1Mean);
+ kerntraits->meanDist2 = (float)(k.meanDist2 * kparams.dist2Scale + kparams.dist2Mean);
+ kerntraits->probKern1 = (float)(k.probKern1 * kparams.PKern1Scale + kparams.PKern1Mean);
+ if (!pSpecies->useFullKernel()) {
+ // kernel mean(s) may not be less than landscape resolution
+ if (kerntraits->meanDist1 < resol) kerntraits->meanDist1 = (float)resol;
+ if (kerntraits->meanDist2 < resol) kerntraits->meanDist2 = (float)resol;
+ }
+ if (kerntraits->probKern1 < 0.0) kerntraits->probKern1 = 0.0;
+ if (kerntraits->probKern1 > 1.0) kerntraits->probKern1 = 1.0;
+ return;
}
// Get phenotypic emigration traits
trfrKernTraits Individual::getKernTraits(void) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getKernTraits(): indId=" << indId
-// << endl;
-#endif
-trfrKernTraits k; k.meanDist1 = k.meanDist2 = k.probKern1 = 0.0;
-if (kerntraits != 0) {
- k.meanDist1 = kerntraits->meanDist1;
- k.meanDist2 = kerntraits->meanDist2;
- k.probKern1 = kerntraits->probKern1;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::getKernTraits(): indId=" << indId
-// << " k.meanDist1=" << k.meanDist1 << " k.meanDist2=" << k.meanDist1
-// << " k.probKern1=" << k.probKern1
-// << endl;
-#endif
-
-return k;
+ trfrKernTraits k; k.meanDist1 = k.meanDist2 = k.probKern1 = 0.0;
+ if (kerntraits != 0) {
+ k.meanDist1 = kerntraits->meanDist1;
+ k.meanDist2 = kerntraits->meanDist2;
+ k.probKern1 = kerntraits->probKern1;
+ }
+ return k;
}
// Set phenotypic transfer by SMS traits
-void Individual::setSMSTraits(Species *pSpecies,short SMSgenelocn,short nSMStraits,
- bool sexdep) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSMSTraits(): indId=" << indId
-// << " SMSgenelocn=" << SMSgenelocn << " nSMStraits=" << nSMStraits << " sexdep=" << sexdep
-// << endl;
-#endif
-trfrSMSTraits s = pSpecies->getSMSTraits();
-double dp,gb,alphaDB,betaDB;
-dp = gb = alphaDB = betaDB = 0.0;
-if (pGenome != 0) {
- if (pSpecies->has1ChromPerTrait()) {
- if (sexdep) {
- dp = pGenome->express(SMSgenelocn,0,0);
- gb = pGenome->express(SMSgenelocn+1,0,0);
- if (nSMStraits == 4) {
- alphaDB = pGenome->express(SMSgenelocn+2,0,0);
- betaDB = pGenome->express(SMSgenelocn+3,0,0);
+void Individual::setSMSTraits(Species* pSpecies, short SMSgenelocn, short nSMStraits,
+ bool sexdep) {
+ trfrSMSTraits s = pSpecies->getSMSTraits();
+ double dp, gb, alphaDB, betaDB;
+ dp = gb = alphaDB = betaDB = 0.0;
+ if (pGenome != 0) {
+ if (pSpecies->has1ChromPerTrait()) {
+ if (sexdep) {
+ dp = pGenome->express(SMSgenelocn, 0, 0);
+ gb = pGenome->express(SMSgenelocn + 1, 0, 0);
+ if (nSMStraits == 4) {
+ alphaDB = pGenome->express(SMSgenelocn + 2, 0, 0);
+ betaDB = pGenome->express(SMSgenelocn + 3, 0, 0);
+ }
+ }
+ else {
+ dp = pGenome->express(SMSgenelocn, 0, 0);
+ gb = pGenome->express(SMSgenelocn + 1, 0, 0);
+ if (nSMStraits == 4) {
+ alphaDB = pGenome->express(SMSgenelocn + 2, 0, 0);
+ betaDB = pGenome->express(SMSgenelocn + 3, 0, 0);
+ }
}
}
else {
- dp = pGenome->express(SMSgenelocn,0,0);
- gb = pGenome->express(SMSgenelocn+1,0,0);
- if (nSMStraits == 4) {
- alphaDB = pGenome->express(SMSgenelocn+2,0,0);
- betaDB = pGenome->express(SMSgenelocn+3,0,0);
+ if (sexdep) {
+ dp = pGenome->express(pSpecies, SMSgenelocn);
+ gb = pGenome->express(pSpecies, SMSgenelocn + 1);
+ if (nSMStraits == 4) {
+ alphaDB = pGenome->express(pSpecies, SMSgenelocn + 2);
+ betaDB = pGenome->express(pSpecies, SMSgenelocn + 3);
+ }
+ }
+ else {
+ dp = pGenome->express(pSpecies, SMSgenelocn);
+ gb = pGenome->express(pSpecies, SMSgenelocn + 1);
+ if (nSMStraits == 4) {
+ alphaDB = pGenome->express(pSpecies, SMSgenelocn + 2);
+ betaDB = pGenome->express(pSpecies, SMSgenelocn + 3);
+ }
}
}
}
+ trfrSMSParams smsparams;
+ if (sexdep) {
+ smsparams = pSpecies->getSMSParams(0, 0);
+ }
else {
- if (sexdep) {
- dp = pGenome->express(pSpecies,SMSgenelocn);
- gb = pGenome->express(pSpecies,SMSgenelocn+1);
- if (nSMStraits == 4) {
- alphaDB = pGenome->express(pSpecies,SMSgenelocn+2);
- betaDB = pGenome->express(pSpecies,SMSgenelocn+3);
- }
- }
- else {
- dp = pGenome->express(pSpecies,SMSgenelocn);
- gb = pGenome->express(pSpecies,SMSgenelocn+1);
- if (nSMStraits == 4) {
- alphaDB = pGenome->express(pSpecies,SMSgenelocn+2);
- betaDB = pGenome->express(pSpecies,SMSgenelocn+3);
- }
- }
+ smsparams = pSpecies->getSMSParams(0, 0);
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSMSTraits(): indId=" << indId
-// << " dp=" << dp << " gb=" << gb
-// << " alphaDB=" << alphaDB << " betaDB=" << betaDB
-// << endl;
-#endif
-
-trfrSMSParams smsparams;
-if (sexdep) {
- smsparams = pSpecies->getSMSParams(0,0);
-}
-else {
- smsparams = pSpecies->getSMSParams(0,0);
-}
-smsData->dp = (float)(dp*smsparams.dpScale + smsparams.dpMean);
-smsData->gb = (float)(gb*smsparams.gbScale + smsparams.gbMean);
-if (s.goalType == 2) {
- smsData->alphaDB = (float)(alphaDB*smsparams.alphaDBScale + smsparams.alphaDBMean);
- smsData->betaDB = (int)(betaDB*smsparams.betaDBScale + smsparams.betaDBMean + 0.5);
-}
-else {
- smsData->alphaDB = s.alphaDB;
- smsData->betaDB = s.betaDB;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSMSTraits() 1111: indId=" << indId
-// << " smsData->dp=" << smsData->dp << " smsData->gb=" << smsData->gb
-// << " smsData->alphaDB=" << smsData->alphaDB << " smsData->betaDB=" << smsData->betaDB
-// << endl;
-#endif
-if (smsData->dp < 1.0) smsData->dp = 1.0;
-if (smsData->gb < 1.0) smsData->gb = 1.0;
-if (smsData->alphaDB <= 0.0) smsData->alphaDB = 0.000001f;
-if (smsData->betaDB < 1) smsData->betaDB = 1;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSMSTraits() 2222: indId=" << indId
-// << " smsData->dp=" << smsData->dp << " smsData->gb=" << smsData->gb
-// << " smsData->alphaDB=" << smsData->alphaDB << " smsData->betaDB=" << smsData->betaDB
-// << endl;
-#endif
-return;
+ smsData->dp = (float)(dp * smsparams.dpScale + smsparams.dpMean);
+ smsData->gb = (float)(gb * smsparams.gbScale + smsparams.gbMean);
+ if (s.goalType == 2) {
+ smsData->alphaDB = (float)(alphaDB * smsparams.alphaDBScale + smsparams.alphaDBMean);
+ smsData->betaDB = (int)(betaDB * smsparams.betaDBScale + smsparams.betaDBMean + 0.5);
+ }
+ else {
+ smsData->alphaDB = s.alphaDB;
+ smsData->betaDB = s.betaDB;
+ }
+ if (smsData->dp < 1.0) smsData->dp = 1.0;
+ if (smsData->gb < 1.0) smsData->gb = 1.0;
+ if (smsData->alphaDB <= 0.0) smsData->alphaDB = 0.000001f;
+ if (smsData->betaDB < 1) smsData->betaDB = 1;
+ return;
}
// Get phenotypic transfer by SMS traits
trfrSMSTraits Individual::getSMSTraits(void) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getSMSTraits(): indId=" << indId << " smsData=" << smsData
-// << endl;
-#endif
-trfrSMSTraits s; s.dp = s.gb = s.alphaDB = 1.0; s.betaDB = 1;
-if (smsData != 0) {
- s.dp = smsData->dp; s.gb = smsData->gb;
- s.alphaDB = smsData->alphaDB; s.betaDB = smsData->betaDB;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::getSMSTraits(): indId=" << indId
-// << " s.dp=" << s.dp << " s.gb=" << s.gb
-// << " s.alphaDB=" << s.alphaDB << " s.betaDB=" << s.betaDB
-// << endl;
-#endif
-return s;
+ trfrSMSTraits s; s.dp = s.gb = s.alphaDB = 1.0; s.betaDB = 1;
+ if (smsData != 0) {
+ s.dp = smsData->dp; s.gb = smsData->gb;
+ s.alphaDB = smsData->alphaDB; s.betaDB = smsData->betaDB;
+ }
+ return s;
}
// Set phenotypic transfer by CRW traits
-void Individual::setCRWTraits(Species *pSpecies,short CRWgenelocn,short nCRWtraits,
+void Individual::setCRWTraits(Species* pSpecies, short CRWgenelocn, short nCRWtraits,
bool sexdep) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::setCRWTraits(): indId=" << indId
-// << " CRWgenelocn=" << CRWgenelocn << " nCRWtraits=" << nCRWtraits << " sexdep=" << sexdep
-// << endl;
-#endif
-trfrCRWTraits c; c.stepLength = c.rho = 0.0;
-if (pGenome != 0) {
- if (pSpecies->has1ChromPerTrait()) {
- if (sexdep) {
- c.stepLength = (float)pGenome->express(CRWgenelocn+sex,0,sex);
- c.rho = (float)pGenome->express(CRWgenelocn+2+sex,0,sex);
+ trfrCRWTraits c; c.stepLength = c.rho = 0.0;
+ if (pGenome != 0) {
+ if (pSpecies->has1ChromPerTrait()) {
+ if (sexdep) {
+ c.stepLength = (float)pGenome->express(CRWgenelocn + sex, 0, sex);
+ c.rho = (float)pGenome->express(CRWgenelocn + 2 + sex, 0, sex);
+ }
+ else {
+ c.stepLength = (float)pGenome->express(CRWgenelocn, 0, 0);
+ c.rho = (float)pGenome->express(CRWgenelocn + 1, 0, 0);
+ }
}
else {
- c.stepLength = (float)pGenome->express(CRWgenelocn,0,0);
- c.rho = (float)pGenome->express(CRWgenelocn+1,0,0);
+ if (sexdep) {
+ c.stepLength = (float)pGenome->express(pSpecies, CRWgenelocn + sex);
+ c.rho = (float)pGenome->express(pSpecies, CRWgenelocn + 2 + sex);
+ }
+ else {
+ c.stepLength = (float)pGenome->express(pSpecies, CRWgenelocn);
+ c.rho = (float)pGenome->express(pSpecies, CRWgenelocn + 1);
+ }
}
}
+
+ trfrCRWParams cparams;
+ if (sexdep) {
+ cparams = pSpecies->getCRWParams(0, sex);
+ }
else {
- if (sexdep) {
- c.stepLength = (float)pGenome->express(pSpecies,CRWgenelocn+sex);
- c.rho = (float)pGenome->express(pSpecies,CRWgenelocn+2+sex);
- }
- else {
- c.stepLength = (float)pGenome->express(pSpecies,CRWgenelocn);
- c.rho = (float)pGenome->express(pSpecies,CRWgenelocn+1);
- }
+ cparams = pSpecies->getCRWParams(0, 0);
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setCRWTraits(): indId=" << indId
-// << " c.stepLength=" << c.stepLength << " c.rho=" << c.rho
-// << endl;
-#endif
-
-trfrCRWParams cparams;
-if (sexdep) {
- cparams = pSpecies->getCRWParams(0,sex);
-}
-else {
- cparams = pSpecies->getCRWParams(0,0);
-}
-crw->stepL = (float)(c.stepLength*cparams.stepLScale + cparams.stepLgthMean);
-crw->rho = (float)(c.rho*cparams.rhoScale + cparams.rhoMean);
-#if RSDEBUG
-//DEBUGLOG << "Individual::setCRWTraits(): indId=" << indId
-// << " crw->stepL=" << crw->stepL << " crw->rho=" << crw->rho
-// << endl;
-#endif
-if (crw->stepL < 1.0) crw->stepL = 1.0;
-if (crw->rho < 0.0) crw->rho = 0.0;
-if (crw->rho > 0.999) crw->rho = 0.999f;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setCRWTraits(): indId=" << indId
-// << " crw->stepL=" << crw->stepL << " crw->rho=" << crw->rho
-// << endl;
-#endif
-return;
+ crw->stepL = (float)(c.stepLength * cparams.stepLScale + cparams.stepLgthMean);
+ crw->rho = (float)(c.rho * cparams.rhoScale + cparams.rhoMean);
+ if (crw->stepL < 1.0) crw->stepL = 1.0;
+ if (crw->rho < 0.0) crw->rho = 0.0;
+ if (crw->rho > 0.999) crw->rho = 0.999f;
+ return;
}
// Get phenotypic transfer by CRW traits
trfrCRWTraits Individual::getCRWTraits(void) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getCRWTraits(): indId=" << indId
-// << endl;
-#endif
-trfrCRWTraits c; c.stepLength = c.rho = 0.0;
-if (crw != 0) {
- c.stepLength = crw->stepL;
- c.rho = crw->rho;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::getCRWTraits(): indId=" << indId
-// << " c.stepLength=" << c.stepLength << " c.rho=" << c.rho
-// << endl;
-#endif
-
-return c;
-
+ trfrCRWTraits c; c.stepLength = c.rho = 0.0;
+ if (crw != 0) {
+ c.stepLength = crw->stepL;
+ c.rho = crw->rho;
+ }
+ return c;
}
// Set phenotypic settlement traits
-void Individual::setSettTraits(Species *pSpecies,short settgenelocn,short nsetttraits,
+void Individual::setSettTraits(Species* pSpecies, short settgenelocn, short nsetttraits,
bool sexdep) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSettTraits(): indId=" << indId << " sex=" << sex
-// << " settgenelocn=" << settgenelocn << " nsetttraits=" << nsetttraits << " sexdep=" << sexdep
-// << endl;
-#endif
-//simParams sim = paramsSim->getSim();
-settleTraits s; s.s0 = s.alpha = s.beta = 0.0;
-if (pGenome != 0) {
- if (pSpecies->has1ChromPerTrait()) {
- if (sexdep) {
- s.s0 = (float)pGenome->express(settgenelocn+3*sex,0,0);
- s.alpha = (float)pGenome->express(settgenelocn+3*sex+1,0,0);
- s.beta = (float)pGenome->express(settgenelocn+3*sex+2,0,0);
+ settleTraits s; s.s0 = s.alpha = s.beta = 0.0;
+ if (pGenome != 0) {
+ if (pSpecies->has1ChromPerTrait()) {
+ if (sexdep) {
+ s.s0 = (float)pGenome->express(settgenelocn + 3 * sex, 0, 0);
+ s.alpha = (float)pGenome->express(settgenelocn + 3 * sex + 1, 0, 0);
+ s.beta = (float)pGenome->express(settgenelocn + 3 * sex + 2, 0, 0);
+ }
+ else {
+ s.s0 = (float)pGenome->express(settgenelocn, 0, 0);
+ s.alpha = (float)pGenome->express(settgenelocn + 1, 0, 0);
+ s.beta = (float)pGenome->express(settgenelocn + 2, 0, 0);
+ }
}
else {
- s.s0 = (float)pGenome->express(settgenelocn,0,0);
- s.alpha = (float)pGenome->express(settgenelocn+1,0,0);
- s.beta = (float)pGenome->express(settgenelocn+2,0,0);
+ if (sexdep) {
+ s.s0 = (float)pGenome->express(pSpecies, settgenelocn + 3 * sex);
+ s.alpha = (float)pGenome->express(pSpecies, settgenelocn + 3 * sex + 1);
+ s.beta = (float)pGenome->express(pSpecies, settgenelocn + 3 * sex + 2);
+ }
+ else {
+ s.s0 = (float)pGenome->express(pSpecies, settgenelocn);
+ s.alpha = (float)pGenome->express(pSpecies, settgenelocn + 1);
+ s.beta = (float)pGenome->express(pSpecies, settgenelocn + 2);
+ }
+
}
}
- else {
- if (sexdep) {
- s.s0 = (float)pGenome->express(pSpecies,settgenelocn+3*sex);
- s.alpha = (float)pGenome->express(pSpecies,settgenelocn+3*sex+1);
- s.beta = (float)pGenome->express(pSpecies,settgenelocn+3*sex+2);
- }
- else {
- s.s0 = (float)pGenome->express(pSpecies,settgenelocn);
- s.alpha = (float)pGenome->express(pSpecies,settgenelocn+1);
- s.beta = (float)pGenome->express(pSpecies,settgenelocn+2);
- }
- }
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSettTraits(): indId=" << indId
-// << " s.s0=" << s.s0 << " s.alpha=" << s.alpha << " s.beta=" << s.beta
-// << endl;
-#endif
-
-settParams sparams;
-if (sexdep) {
- sparams = pSpecies->getSettParams(0,sex);
-}
-else {
- sparams = pSpecies->getSettParams(0,0);
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSettTraits(): indId=" << indId
-// << " sparams.s0Mean=" << sparams.s0Mean << " sparams.s0SD=" << sparams.s0SD
-// << " sparams.s0Scale=" << sparams.s0Scale
-// << endl;
-#endif
-setttraits = new settleTraits;
-setttraits->s0 = (float)(s.s0*sparams.s0Scale + sparams.s0Mean);
-setttraits->alpha = (float)(s.alpha*sparams.alphaSScale + sparams.alphaSMean);
-setttraits->beta = (float)(s.beta*sparams.betaSScale + sparams.betaSMean);
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSettTraits(): indId=" << indId
-// << " setttraits->s0=" << setttraits->s0
-// << " setttraits->alpha=" << setttraits->alpha << " setttraits->beta=" << setttraits->beta
-// << endl;
-#endif
-if (setttraits->s0 < 0.0) setttraits->s0 = 0.0;
-if (setttraits->s0 > 1.0) setttraits->s0 = 1.0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::setSettTraits(): indId=" << indId
-// << " setttraits->s0=" << setttraits->s0
-// << " setttraits->alpha=" << setttraits->alpha << " setttraits->beta=" << setttraits->beta
-// << endl;
-#endif
-return;
+ settParams sparams;
+ if (sexdep) {
+ sparams = pSpecies->getSettParams(0, sex);
+ }
+ else {
+ sparams = pSpecies->getSettParams(0, 0);
+ }
+ setttraits = new settleTraits;
+ setttraits->s0 = (float)(s.s0 * sparams.s0Scale + sparams.s0Mean);
+ setttraits->alpha = (float)(s.alpha * sparams.alphaSScale + sparams.alphaSMean);
+ setttraits->beta = (float)(s.beta * sparams.betaSScale + sparams.betaSMean);
+ if (setttraits->s0 < 0.0) setttraits->s0 = 0.0;
+ if (setttraits->s0 > 1.0) setttraits->s0 = 1.0;
+ return;
}
// Get phenotypic settlement traits
settleTraits Individual::getSettTraits(void) {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getSettTraits(): indId=" << indId
-// << endl;
-#endif
-settleTraits s; s.s0 = s.alpha = s.beta = 0.0;
-if (setttraits != 0) {
- s.s0 = setttraits->s0;
- s.alpha = setttraits->alpha;
- s.beta = setttraits->beta;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::getSettTraits(): indId=" << indId
-// << " s.s0=" << s.s0 << " s.alpha=" << s.alpha << " s.beta=" << s.beta
-// << endl;
-#endif
+ settleTraits s; s.s0 = s.alpha = s.beta = 0.0;
+ if (setttraits != 0) {
+ s.s0 = setttraits->s0;
+ s.alpha = setttraits->alpha;
+ s.beta = setttraits->beta;
+ }
-return s;
+ return s;
}
-/*
-locus Individual::getAlleles(int g) {
-locus l; l.allele[0] = l.allele[1] = 0.0;
-if (pGenome != 0) l = pGenome->getAlleles(g);
-return l;
-}
-*/
void Individual::setStatus(short s) {
-if (s >= 0 && s <= 9) status = s;
-status = s;
+ if (s >= 0 && s <= 9) status = s;
+ status = s;
}
void Individual::developing(void) {
-isDeveloping = true;
+ isDeveloping = true;
}
void Individual::develop(void) {
-stage++; isDeveloping = false;
+ stage++; isDeveloping = false;
}
void Individual::ageIncrement(short maxage) {
-if (status < 6) { // alive
- age++;
- if (age > maxage) status = 9; // exceeds max. age - dies
- else {
- if (path != 0) path->year = 0; // reset annual step count for movement models
- if (status == 3) // waiting to continue dispersal
- status = 1;
+ if (status < 6) { // alive
+ age++;
+ if (age > maxage) status = 9; // exceeds max. age - dies
+ else {
+ if (path != 0) path->year = 0; // reset annual step count for movement models
+ if (status == 3) // waiting to continue dispersal
+ status = 1;
+ }
}
}
-}
void Individual::incFallow(void) { fallow++; }
@@ -1123,551 +847,406 @@ void Individual::resetFallow(void) { fallow = 0; }
//---------------------------------------------------------------------------
// Move to a specified neighbouring cell
-void Individual::moveto(Cell *newCell) {
-// check that location is indeed a neighbour of the current cell
-locn currloc = pCurrCell->getLocn();
-locn newloc = newCell->getLocn();
-double d = sqrt(((double)currloc.x-(double)newloc.x)*((double)currloc.x-(double)newloc.x)
- + ((double)currloc.y-(double)newloc.y)*((double)currloc.y-(double)newloc.y));
-if (d >= 1.0 && d < 1.5) { // ok
- pCurrCell = newCell; status = 5;
-}
+void Individual::moveto(Cell* newCell) {
+ // check that location is indeed a neighbour of the current cell
+ locn currloc = pCurrCell->getLocn();
+ locn newloc = newCell->getLocn();
+ double d = sqrt(((double)currloc.x - (double)newloc.x) * ((double)currloc.x - (double)newloc.x)
+ + ((double)currloc.y - (double)newloc.y) * ((double)currloc.y - (double)newloc.y));
+ if (d >= 1.0 && d < 1.5) { // ok
+ pCurrCell = newCell; status = 5;
+ }
}
//---------------------------------------------------------------------------
// Move to a new cell by sampling a dispersal distance from a single or double
// negative exponential kernel
// Returns 1 if still dispersing (including having found a potential patch), otherwise 0
-int Individual::moveKernel(Landscape *pLandscape,Species *pSpecies,
- const short repType,const bool absorbing)
+int Individual::moveKernel(Landscape* pLandscape, Species* pSpecies,
+ const short repType, const bool absorbing)
{
-intptr patch;
-int patchNum = 0;
-int newX = 0,newY = 0;
-int dispersing = 1;
-double xrand,yrand,meandist,dist,r1,rndangle,nx,ny;
-float localK;
-trfrKernTraits kern;
-Cell* pCell;
-Patch* pPatch;
-locn loc = pCurrCell->getLocn();
-
-landData land = pLandscape->getLandData();
-
-bool usefullkernel = pSpecies->useFullKernel();
-trfrRules trfr = pSpecies->getTrfr();
-settleRules sett = pSpecies->getSettRules(stage,sex);
-
-pCell = NULL;
-pPatch = NULL;
-
-if (trfr.indVar) { // get individual's kernel parameters
- kern.meanDist1 = kern.meanDist2 = kern.probKern1 = 0.0;
-// kparams = pSpecies->getKernParams(stage,sex);
- if (pGenome != 0) {
- kern.meanDist1 = kerntraits->meanDist1;
- if (trfr.twinKern)
- {
- kern.meanDist2 = kerntraits->meanDist2;
- kern.probKern1 = kerntraits->probKern1;
- }
- }
-}
-else { // get kernel parameters for the species
- if (trfr.sexDep) {
- if (trfr.stgDep) {
- kern = pSpecies->getKernTraits(stage,sex);
- }
- else {
- kern = pSpecies->getKernTraits(0,sex);
+ intptr patch;
+ int patchNum = 0;
+ int newX = 0, newY = 0;
+ int dispersing = 1;
+ double xrand, yrand, meandist, dist, r1, rndangle, nx, ny;
+ float localK;
+ trfrKernTraits kern;
+ Cell* pCell;
+ Patch* pPatch;
+ locn loc = pCurrCell->getLocn();
+
+ landData land = pLandscape->getLandData();
+
+ bool usefullkernel = pSpecies->useFullKernel();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleRules sett = pSpecies->getSettRules(stage, sex);
+
+ pCell = NULL;
+ pPatch = NULL;
+
+ if (trfr.indVar) { // get individual's kernel parameters
+ kern.meanDist1 = kern.meanDist2 = kern.probKern1 = 0.0;
+ if (pGenome != 0) {
+ kern.meanDist1 = kerntraits->meanDist1;
+ if (trfr.twinKern)
+ {
+ kern.meanDist2 = kerntraits->meanDist2;
+ kern.probKern1 = kerntraits->probKern1;
+ }
}
}
- else {
- if (trfr.stgDep) {
- kern = pSpecies->getKernTraits(stage,0);
+ else { // get kernel parameters for the species
+ if (trfr.sexDep) {
+ if (trfr.stgDep) {
+ kern = pSpecies->getKernTraits(stage, sex);
+ }
+ else {
+ kern = pSpecies->getKernTraits(0, sex);
+ }
}
else {
- kern = pSpecies->getKernTraits(0,0);
+ if (trfr.stgDep) {
+ kern = pSpecies->getKernTraits(stage, 0);
+ }
+ else {
+ kern = pSpecies->getKernTraits(0, 0);
+ }
}
}
-}
-#if RSDEBUG
-//Patch *startPatch = (Patch*)startpatch;
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId << " x=" << loc.x << " y=" << loc.y
-//// << " natalPatch = " << natalPatch
-//// << " startpatch = " << startpatch << " patchNum = " << startPatch->getPatchNum()
-// << " kern.meanDist1=" << kern.meanDist1;
-//if (trfr.twinKern) {
-// DEBUGLOG << " meanDist2=" << kern.meanDist2 << " probKern1=" << kern.probKern1;
-//}
-//DEBUGLOG << endl;
-#endif
-// scale the appropriate kernel mean to the cell size
-if (trfr.twinKern)
-{
- if (pRandom->Bernoulli(kern.probKern1))
- meandist = kern.meanDist1 / (float)land.resol;
+ // scale the appropriate kernel mean to the cell size
+ if (trfr.twinKern)
+ {
+ if (pRandom->Bernoulli(kern.probKern1))
+ meandist = kern.meanDist1 / (float)land.resol;
+ else
+ meandist = kern.meanDist2 / (float)land.resol;
+ }
else
- meandist = kern.meanDist2 / (float)land.resol;
-}
-else
- meandist = kern.meanDist1 / (float)land.resol;
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId << " meandist=" << meandist << endl;
-#endif
-// scaled mean may not be less than 1 unless emigration derives from the kernel
-// (i.e. the 'use full kernel' option is applied)
-if (!usefullkernel && meandist < 1.0) meandist = 1.0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId << " meandist=" << meandist << endl;
-#endif
+ meandist = kern.meanDist1 / (float)land.resol;
-#if RSDEBUG
-//Patch *startPatch = (Patch*)startpatch;
-//DEBUGLOG << "Individual::moveKernel(): indId = " << indId << " x = " << x << " y = " << y
-// << " natalPatch = " << natalPatch
-//// << " startpatch = " << startpatch << " patchNum = " << startPatch->getPatchNum()
-// << " meanDist1 = " << kern.meanDist1;
-//if (trfr.twinKern) {
-// DEBUGLOG << " probKern1 = " << kern.probKern1 << " meanDist2 = " << kern.meanDist2;
-//}
-//DEBUGLOG << " meandist = " << meandist << endl;
-#endif
+ // scaled mean may not be less than 1 unless emigration derives from the kernel
+ // (i.e. the 'use full kernel' option is applied)
+ if (!usefullkernel && meandist < 1.0) meandist = 1.0;
-int loopsteps = 0; // new counter to prevent infinite loop added 14/8/15
-do {
+ int loopsteps = 0; // new counter to prevent infinite loop added 14/8/15
do {
do {
- // randomise the cell within the patch, provided that the individual is still in
- // its natal cell (i.e. not waiting in the matrix)
- // this is because, if the patch is very large, the individual is near the centre
- // and the (single) kernel mean is (not much more than) the cell size, an infinite
- // loop could otherwise result, as the individual never reaches the patch edge
- // (in a cell-based model, this has no effect, other than as a processing overhead)
- if (status == 1) {
- pCell = pNatalPatch->getRandomCell();
- if (pCell != 0) {
- loc = pCell->getLocn();
+ do {
+ // randomise the cell within the patch, provided that the individual is still in
+ // its natal cell (i.e. not waiting in the matrix)
+ // this is because, if the patch is very large, the individual is near the centre
+ // and the (single) kernel mean is (not much more than) the cell size, an infinite
+ // loop could otherwise result, as the individual never reaches the patch edge
+ // (in a cell-based model, this has no effect, other than as a processing overhead)
+ if (status == 1) {
+ pCell = pNatalPatch->getRandomCell();
+ if (pCell != 0) {
+ loc = pCell->getLocn();
+ }
}
- }
- // randomise the position of the individual inside the cell
- xrand = (double)loc.x + pRandom->Random()*0.999;
- yrand = (double)loc.y + pRandom->Random()*0.999;
-
- r1 = 0.0000001 + pRandom->Random()*(1.0-0.0000001);
-// dist = (-1.0*meandist)*std::log(r1);
- dist = (-1.0*meandist)*log(r1); // for LINUX_CLUSTER
-
- rndangle = pRandom->Random() * 2.0 * PI;
- nx = xrand + dist * sin(rndangle);
- ny = yrand + dist * cos(rndangle);
- if (nx < 0.0) newX = -1; else newX = (int)nx;
- if (ny < 0.0) newY = -1; else newY = (int)ny;
-#if RSDEBUG
- if (path != 0) (path->year)++;
-#endif
- loopsteps++;
+ // randomise the position of the individual inside the cell
+ xrand = (double)loc.x + pRandom->Random() * 0.999;
+ yrand = (double)loc.y + pRandom->Random() * 0.999;
+
+ r1 = 0.0000001 + pRandom->Random() * (1.0 - 0.0000001);
+ // dist = (-1.0*meandist)*std::log(r1);
+ dist = (-1.0 * meandist) * log(r1); // for LINUX_CLUSTER
+
+ rndangle = pRandom->Random() * 2.0 * PI;
+ nx = xrand + dist * sin(rndangle);
+ ny = yrand + dist * cos(rndangle);
+ if (nx < 0.0) newX = -1; else newX = (int)nx;
+ if (ny < 0.0) newY = -1; else newY = (int)ny;
#if RSDEBUG
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId << " status=" << status
-// << " loopsteps=" << loopsteps << " newX=" << newX << " newY=" << newY
-// << " loc.x=" << loc.x << " loc.y=" << loc.y
-// << endl;
+ if (path != 0) (path->year)++;
#endif
- } while (loopsteps < 1000 &&
+ loopsteps++;
+ } while (loopsteps < 1000 &&
((!absorbing && (newX < land.minX || newX > land.maxX
- || newY < land.minY || newY > land.maxY))
- || (!usefullkernel && newX == loc.x && newY == loc.y))
+ || newY < land.minY || newY > land.maxY))
+ || (!usefullkernel && newX == loc.x && newY == loc.y))
);
- if (loopsteps < 1000) {
- if (newX < land.minX || newX > land.maxX
+ if (loopsteps < 1000) {
+ if (newX < land.minX || newX > land.maxX
|| newY < land.minY || newY > land.maxY) { // beyond absorbing boundary
- pCell = 0;
- patch = 0;
- patchNum = -1;
- }
- else {
- pCell = pLandscape->findCell(newX,newY);
- if (pCell == 0) { // no-data cell
+ pCell = 0;
patch = 0;
patchNum = -1;
}
else {
- patch = pCell->getPatch();
- if (patch == 0) { // matrix
- pPatch = 0;
- patchNum = 0;
+ pCell = pLandscape->findCell(newX, newY);
+ if (pCell == 0) { // no-data cell
+ patch = 0;
+ patchNum = -1;
}
else {
- pPatch = (Patch*)patch;
- patchNum = pPatch->getPatchNum();
+ patch = pCell->getPatch();
+ if (patch == 0) { // matrix
+ pPatch = 0;
+ patchNum = 0;
+ }
+ else {
+ pPatch = (Patch*)patch;
+ patchNum = pPatch->getPatchNum();
+ }
}
}
}
- }
- else {
- patch = 0;
- patchNum = -1;
- }
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId << " status=" << status
-// << " loopsteps=" << loopsteps << " newX=" << newX << " newY=" << newY
-// << " pCell=" << pCell << " patch=" << patch << " patchNum=" << patchNum
-// << endl;
-#endif
- } while (!absorbing && patchNum < 0 && loopsteps < 1000); // in a no-data region
-}
-while (!usefullkernel && pPatch == pNatalPatch && loopsteps < 1000); // still in the original (natal) patch
+ else {
+ patch = 0;
+ patchNum = -1;
+ }
+ } while (!absorbing && patchNum < 0 && loopsteps < 1000); // in a no-data region
+ } while (!usefullkernel && pPatch == pNatalPatch && loopsteps < 1000); // still in the original (natal) patch
-if (loopsteps < 1000) {
- if (pCell == 0) { // beyond absorbing boundary or in no-data cell
- pCurrCell = 0;
- status = 6;
- dispersing = 0;
- }
- else {
- pCurrCell = pCell;
- if (pPatch == 0) localK = 0.0; // matrix
- else localK = pPatch->getK();
- if (patchNum > 0 && localK > 0.0) { // found a new patch
- status = 2; // record as potential settler
+ if (loopsteps < 1000) {
+ if (pCell == 0) { // beyond absorbing boundary or in no-data cell
+ pCurrCell = 0;
+ status = 6;
+ dispersing = 0;
}
else {
- dispersing = 0;
- // can wait in matrix if population is stage structured ...
- if (pSpecies->stageStructured()) {
- // ... and wait option is applied ...
- if (sett.wait) { // ... it is
- status = 3; // waiting
+ pCurrCell = pCell;
+ if (pPatch == 0) localK = 0.0; // matrix
+ else localK = pPatch->getK();
+ if (patchNum > 0 && localK > 0.0) { // found a new patch
+ status = 2; // record as potential settler
+ }
+ else {
+ dispersing = 0;
+ // can wait in matrix if population is stage structured ...
+ if (pSpecies->stageStructured()) {
+ // ... and wait option is applied ...
+ if (sett.wait) { // ... it is
+ status = 3; // waiting
+ }
+ else // ... it is not
+ status = 6; // dies (unless there is a suitable neighbouring cell)
}
- else // ... it is not
+ else
status = 6; // dies (unless there is a suitable neighbouring cell)
}
- else
- status = 6; // dies (unless there is a suitable neighbouring cell)
}
}
-}
-else {
- status = 6;
- dispersing = 0;
-}
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveKernel(): indId=" << indId
-// << " newX=" << newX << " newY=" << newY
-// << " patch=" << patch
-// << " patchNum=" << patchNum << " status=" << status;
-//DEBUGLOG << endl;
-#endif
-
-// apply dispersal-related mortality, which may be distance-dependent
-dist *= (float)land.resol; // re-scale distance moved to landscape scale
-if (status < 7) {
- double dispmort;
- trfrMortParams mort = pSpecies->getMortParams();
- if (trfr.distMort) {
- dispmort = 1.0 / (1.0 + exp(-(dist - mort.mortBeta)*mort.mortAlpha));
- }
else {
- dispmort = mort.fixedMort;
- }
- if (pRandom->Bernoulli(dispmort)) {
- status = 7; // dies
+ status = 6;
dispersing = 0;
}
-}
-return dispersing;
+ // apply dispersal-related mortality, which may be distance-dependent
+ dist *= (float)land.resol; // re-scale distance moved to landscape scale
+ if (status < 7) {
+ double dispmort;
+ trfrMortParams mort = pSpecies->getMortParams();
+ if (trfr.distMort) {
+ dispmort = 1.0 / (1.0 + exp(-(dist - mort.mortBeta) * mort.mortAlpha));
+ }
+ else {
+ dispmort = mort.fixedMort;
+ }
+ if (pRandom->Bernoulli(dispmort)) {
+ status = 7; // dies
+ dispersing = 0;
+ }
+ }
+
+ return dispersing;
}
//---------------------------------------------------------------------------
// Make a single movement step according to a mechanistic movement model
// Returns 1 if still dispersing (including having found a potential patch), otherwise 0
-int Individual::moveStep(Landscape *pLandscape,Species *pSpecies,
- const short landIx,const bool absorbing)
+int Individual::moveStep(Landscape* pLandscape, Species* pSpecies,
+ const short landIx, const bool absorbing)
{
-if (status != 1) return 0; // not currently dispersing
-
-intptr patch;
-int patchNum;
-int newX,newY;
-locn loc;
-int dispersing = 1;
-double xcnew,ycnew;
-double angle;
-double mortprob,rho,steplen;
-movedata move;
-Patch* pPatch = 0;
-bool absorbed = false;
-//int popsize;
-
-landData land = pLandscape->getLandData();
-simParams sim = paramsSim->getSim();
-
-trfrRules trfr = pSpecies->getTrfr();
-trfrCRWTraits movt = pSpecies->getCRWTraits();
-settleSteps settsteps = pSpecies->getSteps(stage,sex);
-
-patch = pCurrCell->getPatch();
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveStep() AAAA: indId=" << indId
-// << " pCurrCell=" << pCurrCell << " patch=" << patch
-// << endl;
-#endif
+ if (status != 1) return 0; // not currently dispersing
+
+ intptr patch;
+ int patchNum;
+ int newX, newY;
+ locn loc;
+ int dispersing = 1;
+ double xcnew, ycnew;
+ double angle;
+ double mortprob, rho, steplen;
+ movedata move;
+ Patch* pPatch = 0;
+ bool absorbed = false;
+
+ landData land = pLandscape->getLandData();
+ simParams sim = paramsSim->getSim();
+
+ trfrRules trfr = pSpecies->getTrfr();
+ trfrCRWTraits movt = pSpecies->getCRWTraits();
+ settleSteps settsteps = pSpecies->getSteps(stage, sex);
+
+ patch = pCurrCell->getPatch();
-if (patch == 0) { // matrix
- pPatch = 0;
- patchNum = 0;
-}
-else {
- pPatch = (Patch*)patch;
- patchNum = pPatch->getPatchNum();
-}
-// apply step-dependent mortality risk ...
-if (trfr.habMort)
-{ // habitat-dependent
- int h = pCurrCell->getHabIndex(landIx);
- if (h < 0) { // no-data cell - should not occur, but if it does, individual dies
- mortprob = 1.0;
- }
- else mortprob = pSpecies->getHabMort(h);
-#if RSDEBUG
-//locn temploc = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::moveStep(): x=" << temploc.x << " y=" << temploc.x
-// << " landIx=" << landIx << " h=" << h << " mortprob=" << mortprob
-// << endl;
-#endif
-}
-else mortprob = movt.stepMort;
-// ... unless individual has not yet left natal patch in emigration year
-if (pPatch == pNatalPatch && path->out == 0 && path->year == path->total) {
- mortprob = 0.0;
-}
-#if RSDEBUG
-locn loc0,loc1,loc2;
-//loc0 = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::moveStep() BBBB: indId=" << indId << " status=" << status
-// << " path->year=" << path->year << " path->out=" << path->out
-// << " settleStatus=" << path->settleStatus
-// << " x=" << loc0.x << " y=" << loc0.y
-//// << " patch=" << patch
-// << " pPatch=" << pPatch
-// << " patchNum=" << patchNum;
-//// << " natalPatch=" << natalPatch;
-////if (crw != 0) {
-//// DEBUGLOG << " xc=" << crw->xc << " yc=" << crw->yc;
-//// DEBUGLOG << " rho=" << movt.rho << " stepLength=" << movt.stepLength;
-////}
-//DEBUGLOG << endl;
-#endif
-if (pRandom->Bernoulli(mortprob)) { // individual dies
- status = 7;
- dispersing = 0;
-}
-else { // take a step
- (path->year)++;
- (path->total)++;
-// if (pPatch != pNatalPatch || path->out > 0) (path->out)++;
- if (patch == 0 || pPatch == 0 || patchNum == 0) { // not in a patch
- if (path != 0) path->settleStatus = 0; // reset path settlement status
- (path->out)++;
+ if (patch == 0) { // matrix
+ pPatch = 0;
+ patchNum = 0;
}
- loc = pCurrCell->getLocn();
- newX = loc.x; newY = loc.y;
-
-
- switch (trfr.moveType) {
-
- case 1: // SMS
-#if RSDEBUG
-//loc1 = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::moveStep() FFFF: indId=" << indId << " status=" << status
-//// << " path->year=" << path->year
-// << " path->season=" << path->season
-// << " x=" << loc1.x << " y=" << loc1.y
-// << " smsData->goalType=" << smsData->goalType
-// << " goal.x=" << smsData->goal.x
-// << " goal.y=" << smsData->goal.y
-// << endl;
-#endif
- move = smsMove(pLandscape,pSpecies,landIx,pPatch==pNatalPatch,trfr.indVar,absorbing);
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveStep() GGGG: indId=" << indId << " status=" << status
-// << " move.dist=" << move.dist
-// << endl;
-#endif
- if (move.dist < 0.0) {
- // either INTERNAL ERROR CONDITION - INDIVIDUAL IS IN NO-DATA SQUARE
- // or individual has crossed absorbing boundary ...
- // ... individual dies
- status = 6;
- dispersing = 0;
+ else {
+ pPatch = (Patch*)patch;
+ patchNum = pPatch->getPatchNum();
+ }
+ // apply step-dependent mortality risk ...
+ if (trfr.habMort)
+ { // habitat-dependent
+ int h = pCurrCell->getHabIndex(landIx);
+ if (h < 0) { // no-data cell - should not occur, but if it does, individual dies
+ mortprob = 1.0;
+ }
+ else mortprob = pSpecies->getHabMort(h);
+ }
+ else mortprob = movt.stepMort;
+ // ... unless individual has not yet left natal patch in emigration year
+ if (pPatch == pNatalPatch && path->out == 0 && path->year == path->total) {
+ mortprob = 0.0;
+ }
+ if (pRandom->Bernoulli(mortprob)) { // individual dies
+ status = 7;
+ dispersing = 0;
+ }
+ else { // take a step
+ (path->year)++;
+ (path->total)++;
+ if (patch == 0 || pPatch == 0 || patchNum == 0) { // not in a patch
+ if (path != 0) path->settleStatus = 0; // reset path settlement status
+ (path->out)++;
}
- else {
-#if RSDEBUG
-//loc1 = pCurrCell->getLocn();
-//DEBUGLOG << "Individual::moveStep() HHHH: indId=" << indId << " status=" << status
-// << " path->year=" << path->year
-// << " x=" << loc1.x << " y=" << loc1.y
-//// << " smsData = " << smsData
-// << endl;
-#endif
+ loc = pCurrCell->getLocn();
+ newX = loc.x; newY = loc.y;
+
- // WOULD IT BE MORE EFFICIENT FOR smsMove TO RETURN A POINTER TO THE NEW CELL? ...
+ switch (trfr.moveType) {
- patch = pCurrCell->getPatch();
- //int patchnum;
- if (patch == 0) {
- pPatch = 0;
- //patchnum = 0;
+ case 1: // SMS
+ move = smsMove(pLandscape, pSpecies, landIx, pPatch == pNatalPatch, trfr.indVar, absorbing);
+ if (move.dist < 0.0) {
+ // either INTERNAL ERROR CONDITION - INDIVIDUAL IS IN NO-DATA SQUARE
+ // or individual has crossed absorbing boundary ...
+ // ... individual dies
+ status = 6;
+ dispersing = 0;
}
else {
- pPatch = (Patch*)patch;
- //patchnum = pPatch->getPatchNum();
- }
- if (sim.saveVisits && pPatch != pNatalPatch) {
- pCurrCell->incrVisits();
+
+ // WOULD IT BE MORE EFFICIENT FOR smsMove TO RETURN A POINTER TO THE NEW CELL? ...
+
+ patch = pCurrCell->getPatch();
+ if (patch == 0) {
+ pPatch = 0;
+ }
+ else {
+ pPatch = (Patch*)patch;
+ }
+ if (sim.saveVisits && pPatch != pNatalPatch) {
+ pCurrCell->incrVisits();
+ }
}
- }
- break;
+ break;
- case 2: // CRW
- if (trfr.indVar) {
- if (crw != 0) {
- movt.stepLength = crw->stepL;
- movt.rho = crw->rho;
+ case 2: // CRW
+ if (trfr.indVar) {
+ if (crw != 0) {
+ movt.stepLength = crw->stepL;
+ movt.rho = crw->rho;
+ }
}
- }
- steplen = movt.stepLength; if (steplen < 0.2*land.resol) steplen = 0.2*land.resol;
- rho = movt.rho; if (rho > 0.99) rho = 0.99;
- if (pPatch == pNatalPatch) {
- rho = 0.99; // to promote leaving natal patch
- path->out = 0;
- }
- if (movt.straigtenPath && path->settleStatus > 0) {
- // individual is in a patch and has already determined whether to settle
- rho = 0.99; // to promote leaving the patch
- path->out = 0;
- }
- int loopsteps = 0; // new counter to prevent infinite loop added 14/8/15
- do {
+ steplen = movt.stepLength; if (steplen < 0.2 * land.resol) steplen = 0.2 * land.resol;
+ rho = movt.rho; if (rho > 0.99) rho = 0.99;
+ if (pPatch == pNatalPatch) {
+ rho = 0.99; // to promote leaving natal patch
+ path->out = 0;
+ }
+ if (movt.straigtenPath && path->settleStatus > 0) {
+ // individual is in a patch and has already determined whether to settle
+ rho = 0.99; // to promote leaving the patch
+ path->out = 0;
+ }
+ int loopsteps = 0; // new counter to prevent infinite loop added 14/8/15
do {
- // new direction
- if (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY
- || pCurrCell == 0) {
- // individual has tried to go out-of-bounds or into no-data area
- // allow random move to prevent repeated similar move
- angle = wrpcauchy(crw->prevdrn,0.0);
+ do {
+ // new direction
+ if (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY
+ || pCurrCell == 0) {
+ // individual has tried to go out-of-bounds or into no-data area
+ // allow random move to prevent repeated similar move
+ angle = wrpcauchy(crw->prevdrn, 0.0);
+ }
+ else
+ angle = wrpcauchy(crw->prevdrn, rho);
+ // new continuous cell coordinates
+ xcnew = crw->xc + sin(angle) * steplen / (float)land.resol;
+ ycnew = crw->yc + cos(angle) * steplen / (float)land.resol;
+ if (xcnew < 0.0) newX = -1; else newX = (int)xcnew;
+ if (ycnew < 0.0) newY = -1; else newY = (int)ycnew;
+ loopsteps++;
+ } while (!absorbing && loopsteps < 1000 &&
+ (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY));
+ if (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY)
+ pCurrCell = 0;
+ else
+ pCurrCell = pLandscape->findCell(newX, newY);
+ if (pCurrCell == 0) { // no-data cell or beyond absorbing boundary
+ patch = 0;
+ if (absorbing) absorbed = true;
}
else
- angle = wrpcauchy(crw->prevdrn,rho);
- // new continuous cell coordinates
- xcnew = crw->xc + sin(angle) * steplen/(float)land.resol;
- ycnew = crw->yc + cos(angle) * steplen/(float)land.resol;
- if (xcnew < 0.0) newX = -1; else newX = (int)xcnew;
- if (ycnew < 0.0) newY = -1; else newY = (int)ycnew;
- loopsteps++;
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveStep(): indId=" << indId
-// << " xc=" << crw->xc << " yc=" << crw->yc << " pCurrCell=" << pCurrCell
-// << " steps=" << path->year << " loopsteps=" << loopsteps
-// << " steplen=" << steplen << " rho=" << rho << " angle=" << angle
-// << " xcnew=" << xcnew << " ycnew=" << ycnew << " newX=" << newX << " newY=" << newY << endl;
-#endif
- }
- while (!absorbing && loopsteps < 1000 &&
- (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY));
- if (newX < land.minX || newX > land.maxX || newY < land.minY || newY > land.maxY)
- pCurrCell = 0;
- else
- pCurrCell = pLandscape->findCell(newX,newY);
- if (pCurrCell == 0) { // no-data cell or beyond absorbing boundary
- patch = 0;
- if (absorbing) absorbed = true;
- }
- else
- patch = pCurrCell->getPatch();
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveStep(): indId=" << indId
-// << " loopsteps=" << loopsteps << " absorbed=" << absorbed
-// << " pCurrCell=" << pCurrCell << " patch=" << patch << endl;
-#endif
- } while (!absorbing && pCurrCell == 0 && loopsteps < 1000);
- crw->prevdrn = (float)angle;
- crw->xc = (float)xcnew; crw->yc = (float)ycnew;
- if (absorbed) { // beyond absorbing boundary or in no-data square
- status = 6;
- dispersing = 0;
- pCurrCell = 0;
- }
- else {
- if (loopsteps >= 1000) { // unable to make a move
- // INTERNAL ERROR CONDITION - INDIVIDUAL IS IN NO-DATA SQUARE
- // NEED TO TAKE SOME FORM OF INFORMATIVE ACTION ...
- // ... individual dies as it cannot move
+ patch = pCurrCell->getPatch();
+ } while (!absorbing && pCurrCell == 0 && loopsteps < 1000);
+ crw->prevdrn = (float)angle;
+ crw->xc = (float)xcnew; crw->yc = (float)ycnew;
+ if (absorbed) { // beyond absorbing boundary or in no-data square
status = 6;
dispersing = 0;
- // current cell will be invalid (zero), so set back to previous cell
- pCurrCell = pPrevCell;
+ pCurrCell = 0;
}
- }
-#if RSDEBUG
-//DEBUGLOG << "Individual::moveStep(): indId=" << indId
-// << " status=" << status
-// << " pCurrCell=" << pCurrCell << " patch=" << patch << endl;
-#endif
- break;
+ else {
+ if (loopsteps >= 1000) { // unable to make a move
+ // INTERNAL ERROR CONDITION - INDIVIDUAL IS IN NO-DATA SQUARE
+ // NEED TO TAKE SOME FORM OF INFORMATIVE ACTION ...
+ // ... individual dies as it cannot move
+ status = 6;
+ dispersing = 0;
+ // current cell will be invalid (zero), so set back to previous cell
+ pCurrCell = pPrevCell;
+ }
+ }
+ break;
- } // end of switch (trfr.moveType)
+ } // end of switch (trfr.moveType)
-#if RSDEBUG
-//locn loc2;
-//if (pCurrCell > 0) {
-// loc2 = pCurrCell->getLocn();
-//}
-//else {
-// loc2.x = -9999; loc2.y = -9999;
-//}
-//DEBUGLOG << "Individual::moveStep() ZZZZ: indId=" << indId
-// << " status=" << status
-// << " path->total=" << path->total
-// << " x=" << loc2.x << " y=" << loc2.y
-// << " patch=" << patch;
-//if (patch > 0) {
-// pPatch = (Patch*)patch;
-// DEBUGLOG << " patchNum=" << pPatch->getPatchNum()
-// << " getK()=" << pPatch->getK()
-// << " popn=" << pPatch->getPopn((int)pSpecies);
-//}
-// DEBUGLOG << endl;
-#endif
- if (patch > 0 // not no-data area or matrix
- && path->total >= settsteps.minSteps) {
- pPatch = (Patch*)patch;
- if (pPatch != pNatalPatch)
- {
- // determine whether the new patch is potentially suitable
- if (pPatch->getK() > 0.0)
- { // patch is suitable
+ if (patch > 0 // not no-data area or matrix
+ && path->total >= settsteps.minSteps) {
+ pPatch = (Patch*)patch;
+ if (pPatch != pNatalPatch)
+ {
+ // determine whether the new patch is potentially suitable
+ if (pPatch->getK() > 0.0)
+ { // patch is suitable
status = 2;
+ }
}
}
- }
- if (status != 2 && status != 6) { // suitable patch not found, not already dead
- if (path->year >= settsteps.maxStepsYr) {
- status = 3; // waits until next year
- }
- if (path->total >= settsteps.maxSteps) {
- status = 6; // dies
- dispersing = 0;
+ if (status != 2 && status != 6) { // suitable patch not found, not already dead
+ if (path->year >= settsteps.maxStepsYr) {
+ status = 3; // waits until next year
+ }
+ if (path->total >= settsteps.maxSteps) {
+ status = 6; // dies
+ dispersing = 0;
+ }
}
- }
-} // end of single movement step
+ } // end of single movement step
-return dispersing;
+ return dispersing;
}
@@ -1676,696 +1255,478 @@ return dispersing;
// Functions to implement the SMS algorithm
// Move to a neighbouring cell according to the SMS algorithm
-movedata Individual::smsMove(Landscape *pLand,Species *pSpecies,
- const short landIx,const bool natalPatch,const bool indvar,const bool absorbing)
+movedata Individual::smsMove(Landscape* pLand, Species* pSpecies,
+ const short landIx, const bool natalPatch, const bool indvar, const bool absorbing)
{
-array3x3d nbr; // to hold weights/costs/probs of moving to neighbouring cells
-array3x3d goal; // to hold weights for moving towards a goal location
-array3x3f hab; // to hold weights for habitat (includes percep range)
-int x2,y2; // x index from 0=W to 2=E, y index from 0=N to 2=S
-int newX = 0,newY = 0;
-Cell *pCell;
-Cell *pNewCell = NULL;
-double sum_nbrs = 0.0;
-movedata move;
-int cellcost,newcellcost;
-locn current;
-
-//if (write_out) {
-// out<findCell(x,y);
-if (pCurrCell == 0)
-{
-// x,y is a NODATA square - this should not occur here
-// return a negative distance to indicate an error
- move.dist = -69.0; move.cost = 0.0;
- return move;
-}
-
-#if RSDEBUG
-//DEBUGLOG << "Individual::smsMove(): this=" << this << endl;
-#endif
+ array3x3d nbr; // to hold weights/costs/probs of moving to neighbouring cells
+ array3x3d goal; // to hold weights for moving towards a goal location
+ array3x3f hab; // to hold weights for habitat (includes percep range)
+ int x2, y2; // x index from 0=W to 2=E, y index from 0=N to 2=S
+ int newX = 0, newY = 0;
+ Cell* pCell;
+ Cell* pNewCell = NULL;
+ double sum_nbrs = 0.0;
+ movedata move;
+ int cellcost, newcellcost;
+ locn current;
+
+ if (pCurrCell == 0)
+ {
+ // x,y is a NODATA square - this should not occur here
+ // return a negative distance to indicate an error
+ move.dist = -69.0; move.cost = 0.0;
+ return move;
+ }
-landData land = pLand->getLandData();
-trfrSMSTraits movt = pSpecies->getSMSTraits();
-current = pCurrCell->getLocn();
-
-//get weights for directional persistence....
-//if ((path->out > 0 && path->out < 10 && path->out < 2*movt.pr)
-if ((path->out > 0 && path->out <= (movt.pr+1))
-|| natalPatch
-|| (movt.straigtenPath && path->settleStatus > 0)) {
- // inflate directional persistence to promote leaving the patch
- if (indvar) nbr = getSimDir(current.x,current.y,10.0f*smsData->dp);
- else nbr = getSimDir(current.x,current.y,10.0f*movt.dp);
-}
-else {
- if (indvar) nbr = getSimDir(current.x,current.y,smsData->dp);
- else nbr = getSimDir(current.x,current.y,movt.dp);
-}
-if (natalPatch || path->settleStatus > 0) path->out = 0;
-//if (natalPatch) path->out = 0;
-#if RSDEBUG
-//DEBUGLOG << "Individual::smsMove() 0000: nbr matrix" << endl;
-//for (y2 = 2; y2 > -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) DEBUGLOG << nbr.cell[x2][y2] << " ";
-// DEBUGLOG << endl;
-//}
-#endif
-//if (write_out) {
-// out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) DEBUGLOG << hab.cell[x2][y2] << " ";
-// DEBUGLOG << endl;
-//}
-#endif
- pCurrCell->setEffCosts(hab);
-}
-else { // they have already been calculated - no action required
-// if (write_out) {
-// out<<"*** using previous effective costs ***"< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) {
-// out< -1; y2--) {
- for (x2 = 0; x2 < 3; x2++) {
- if(x2 == 1 && y2 == 1) nbr.cell[x2][y2] = 0.0;
- else {
- if(x2 == 1 || y2 == 1) //not diagonal
- nbr.cell[x2][y2] = nbr.cell[x2][y2]*goal.cell[x2][y2]*hab.cell[x2][y2];
- else // diagonal
- nbr.cell[x2][y2] = (float)SQRT2*nbr.cell[x2][y2]*goal.cell[x2][y2]*hab.cell[x2][y2];
- }
-// if (write_out) {
-// out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) DEBUGLOG << nbr.cell[x2][y2] << " ";
-// DEBUGLOG << endl;
-//}
-#endif
+ if (natalPatch || path->settleStatus > 0) path->out = 0;
-// determine reciprocal of effective cost for the 8 neighbours
-//if (write_out) out<<"reciprocal weighted effective costs:"< -1; y2--) {
- for (x2 = 0; x2 < 3; x2++) {
- if (nbr.cell[x2][y2] > 0.0) nbr.cell[x2][y2] = 1.0f/nbr.cell[x2][y2];
-// if (write_out) {
-// out<year == path->total) { // first year of dispersal - use no. of steps outside natal patch
+ nsteps = path->out;
+ }
+ else { // use total no. of steps
+ nsteps = path->total;
+ }
+ if (indvar) {
+ double exp_arg = -((double)nsteps - (double)smsData->betaDB) * (-smsData->alphaDB);
+ if (exp_arg > 100.0) exp_arg = 100.0; // to prevent exp() overflow error
+ gb = 1.0 + (smsData->gb - 1.0) / (1.0 + exp(exp_arg));
+ }
+ else {
+ double exp_arg = -((double)nsteps - (double)movt.betaDB) * (-movt.alphaDB);
+ if (exp_arg > 100.0) exp_arg = 100.0; // to prevent exp() overflow error
+ gb = 1.0 + (movt.gb - 1.0) / (1.0 + exp(exp_arg));
+ }
}
-// if (write_out) out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) {
-// temp.cell[x2][y2] = nbr.cell[x2][y2];
-// if (current.x == 488 && current.y == 422) {
-// pCell = pLand->findCell((current.x+x2-1),(current.y+y2-1));
-// DEBUGLOG << "Individual::smsMove(): this=" << this
-// << " IN THE PROBLEM CELL"
-// << " y=" << current.y << " x=" << current.x
-// << " y2=" << y2 << " x2=" << x2
-// << " pCell=" << pCell;
-// if (pCell != 0) DEBUGLOG << " pCell->getCost=" << pCell->getCost();
-// DEBUGLOG << endl;
-// }
-// }
-//}
-#endif
+ hab = pCurrCell->getEffCosts();
+
+ if (hab.cell[0][0] < 0.0) { // costs have not already been calculated
+ hab = getHabMatrix(pLand, pSpecies, current.x, current.y, movt.pr, movt.prMethod,
+ landIx, absorbing);
+ pCurrCell->setEffCosts(hab);
+ }
+ else {
+ // they have already been calculated - no action required
+ }
-for (y2 = 2; y2 > -1; y2--) {
- for (x2 = 0; x2 < 3; x2++) {
- if (!absorbing) {
- if ((current.y+y2-1) < land.minY || (current.y+y2-1) > land.maxY
- || (current.x+x2-1) < land.minX || (current.x+x2-1) > land.maxX)
- // cell is beyond current landscape limits
- nbr.cell[x2][y2] = 0.0;
- else { // check if no-data cell
- pCell = pLand->findCell((current.x+x2-1),(current.y+y2-1));
- if (pCell == 0) nbr.cell[x2][y2] = 0.0; // no-data cell
+ // determine weighted effective cost for the 8 neighbours
+ // multiply directional persistence, goal bias and habitat habitat-dependent weights
+ for (y2 = 2; y2 > -1; y2--) {
+ for (x2 = 0; x2 < 3; x2++) {
+ if (x2 == 1 && y2 == 1) nbr.cell[x2][y2] = 0.0;
+ else {
+ if (x2 == 1 || y2 == 1) //not diagonal
+ nbr.cell[x2][y2] = nbr.cell[x2][y2] * goal.cell[x2][y2] * hab.cell[x2][y2];
+ else // diagonal
+ nbr.cell[x2][y2] = (float)SQRT2 * nbr.cell[x2][y2] * goal.cell[x2][y2] * hab.cell[x2][y2];
}
}
-#if RSDEBUG
-//DEBUGLOG << "Individual::smsMove(): this=" << this
-// << " y=" << current.y << " x=" << current.x
-// << " y2=" << y2 << " x2=" << x2
-// << " pCell=" << pCell
-// << endl;
-#endif
-// if (write_out) {
-// out< 0.0) { // should always be the case, but safest to check...
+ // determine reciprocal of effective cost for the 8 neighbours
for (y2 = 2; y2 > -1; y2--) {
for (x2 = 0; x2 < 3; x2++) {
- nbr.cell[x2][y2] = nbr.cell[x2][y2]/(float)sum_nbrs;
-// if (write_out) {
-// out< 0.0) nbr.cell[x2][y2] = 1.0f / nbr.cell[x2][y2];
}
-// if (write_out) out< -1; y2--) {
-// for (x2 = 0; x2 < 3; x2++) DEBUGLOG << nbr.cell[x2][y2] << " ";
-// DEBUGLOG << endl;
-//}
-#endif
-// set up cell selection probabilities
-//if (write_out) out<<"rnd = "< land.maxX
- || newY < land.minY || newY > land.maxY)));
- if (loopsteps >= 1000) pNewCell = 0;
- else {
- if (newX < land.minX || newX > land.maxX
- || newY < land.minY || newY > land.maxY) {
- pNewCell = 0;
+ }
+
+ // set up cell selection probabilities
+ double cumulative[9];
+ int j = 0;
+ cumulative[0] = nbr.cell[0][0];
+ for (y2 = 0; y2 < 3; y2++) {
+ for (x2 = 0; x2 < 3; x2++) {
+ if (j != 0) cumulative[j] = cumulative[j - 1] + nbr.cell[x2][y2];
+ j++;
}
- pNewCell = pLand->findCell(newX,newY);
}
-}
-while (!absorbing && pNewCell == 0 && loopsteps < 1000); // no-data cell
-#if RSDEBUG
-//DEBUGLOG << "Individual::smsMove() 8888: pNewCell=" << pNewCell
-// << " loopsteps=" << loopsteps
-// << " current.x=" << current.x << " current.y=" << current.y
-// << " newX=" << newX << " newY=" << newY
-// << " land.minX=" << land.minX << " land.minY=" << land.minY
-// << " land.maxX=" << land.maxX << " land.maxY=" << land.maxY
-// << endl;
-#endif
-if (loopsteps >= 1000 || pNewCell == 0) {
- // unable to make a move or crossed absorbing boundary
- // flag individual to die
- move.dist = -123.0;
- if (pNewCell == 0) pCurrCell = pNewCell;
-}
-else {
- newcellcost = pNewCell->getCost();
- move.cost = move.dist*0.5f*((float)cellcost + (float)newcellcost);
- // make the selected move
- if ((short)memory.size() == movt.memSize) {
- memory.pop(); // remove oldest memory element
- }
- memory.push(current); // record previous location in memory
- //if (write_out) out << "queue length is " << memory.size() << endl;
- pCurrCell = pNewCell;
-}
-return move;
+
+ // select direction at random based on cell selection probabilities
+ // landscape boundaries and no-data cells may be reflective or absorbing
+ cellcost = pCurrCell->getCost();
+ int loopsteps = 0; // new counter to prevent infinite loop added 14/8/15
+ do {
+ do {
+ double rnd = pRandom->Random();
+ j = 0;
+ for (y2 = 0; y2 < 3; y2++) {
+ for (x2 = 0; x2 < 3; x2++) {
+ if (rnd < cumulative[j]) {
+ newX = current.x + x2 - 1;
+ newY = current.y + y2 - 1;
+ if (x2 == 1 || y2 == 1) move.dist = (float)(land.resol);
+ else move.dist = (float)(land.resol) * (float)SQRT2;
+ y2 = 999; x2 = 999; //to break out of x2 and y2 loops.
+ }
+ j++;
+ }
+ }
+ loopsteps++;
+ } while (loopsteps < 1000
+ && (!absorbing && (newX < land.minX || newX > land.maxX
+ || newY < land.minY || newY > land.maxY)));
+ if (loopsteps >= 1000) pNewCell = 0;
+ else {
+ if (newX < land.minX || newX > land.maxX
+ || newY < land.minY || newY > land.maxY) {
+ pNewCell = 0;
+ }
+ pNewCell = pLand->findCell(newX, newY);
+ }
+ } while (!absorbing && pNewCell == 0 && loopsteps < 1000); // no-data cell
+ if (loopsteps >= 1000 || pNewCell == 0) {
+ // unable to make a move or crossed absorbing boundary
+ // flag individual to die
+ move.dist = -123.0;
+ if (pNewCell == 0) pCurrCell = pNewCell;
+ }
+ else {
+ newcellcost = pNewCell->getCost();
+ move.cost = move.dist * 0.5f * ((float)cellcost + (float)newcellcost);
+ // make the selected move
+ if ((short)memory.size() == movt.memSize) {
+ memory.pop(); // remove oldest memory element
+ }
+ memory.push(current); // record previous location in memory
+ pCurrCell = pNewCell;
+ }
+ return move;
}
// Weight neighbouring cells on basis of current movement direction
-array3x3d Individual::getSimDir(const int x, const int y, const float dp)
+array3x3d Individual::getSimDir(const int x, const int y, const float dp)
{
-array3x3d d;
-locn prev;
-double theta;
-int xx,yy;
-
-//if (write_out) out<<"step 0"<goal.x) == 0 && (y - smsData->goal.y) == 0) {
- // at goal, set matrix to unity
-// if (write_out) out<<"*** at goal: x,y = "<goal.x) == 0 && (y - smsData->goal.y) == 0) {
+ // at goal, set matrix to unity
+ for (xx = 0; xx < 3; xx++) {
+ for (yy = 0; yy < 3; yy++) {
+ d.cell[xx][yy] = 1.0;
+ }
}
+ return d;
+ }
+ if (goaltype == 1) {
+ // TEMPORARY CODE - GOAL TYPE 1 NOT YET IMPLEMENTED, AS WE HAVE NO MEANS OF
+ // CAPTURING THE GOAL LOCATION OF EACH INDIVIDUAL
+ for (xx = 0; xx < 3; xx++) {
+ for (yy = 0; yy < 3; yy++) {
+ d.cell[xx][yy] = 1.0;
+ }
+ }
+ return d;
}
- return d;
+ else // goaltype == 2
+ theta = atan2(((double)x - (double)smsData->goal.x), ((double)y - (double)smsData->goal.y));
+ d = calcWeightings(gb, (float)theta);
}
- else // goaltype == 2
- theta = atan2(((double)x -(double)smsData->goal.x),((double)y-(double)smsData->goal.y));
-// if (write_out) out<<"goalx,goaly: "< 7.0 * PI / 8.0) { dx = 0; dy = -1; }
-else {
- if (fabs(theta) > 5.0 * PI / 8.0) { dy = -1; if (theta > 0) dx = 1; else dx = -1; }
+ if (fabs(theta) > 7.0 * PI / 8.0) { dx = 0; dy = -1; }
else {
- if (fabs(theta) > 3.0 * PI / 8.0) { dy = 0; if (theta > 0) dx = 1; else dx = -1; }
+ if (fabs(theta) > 5.0 * PI / 8.0) { dy = -1; if (theta > 0) dx = 1; else dx = -1; }
else {
- if (fabs(theta) > PI / 8.0) { dy = 1; if (theta > 0) dx = 1; else dx = -1; }
- else { dy = 1; dx = 0; }
+ if (fabs(theta) > 3.0 * PI / 8.0) { dy = 0; if (theta > 0) dx = 1; else dx = -1; }
+ else {
+ if (fabs(theta) > PI / 8.0) { dy = 1; if (theta > 0) dx = 1; else dx = -1; }
+ else { dy = 1; dx = 0; }
+ }
}
- }
-}
-// if (write_out) out<<"goalx,goaly: "< 1) dx -= 2; yy = dy;
- d.cell[xx+1][yy+1] = (float)i1; d.cell[-xx+1][yy+1] = (float)i1;
- d.cell[xx+1][-yy+1] = (float)i3; d.cell[-xx+1][-yy+1] = (float)i3;
- }
- else { // theta points W or E
- yy = dy+1; if (yy > 1) dy -= 2; xx = dx;
- d.cell[xx+1][yy+1] = (float)i1; d.cell[xx+1][-yy+1] = (float)i1;
- d.cell[-xx+1][yy+1] = (float)i3; d.cell[-xx+1][-yy+1] = (float)i3;
- }
-}
-else { // theta points to an ordinal direction
- d.cell[dx+1][-dy+1] = (float)i2; d.cell[-dx+1][dy+1] = (float)i2;
- xx = dx+1; if (xx > 1) xx -= 2; d.cell[xx+1][dy+1] = (float)i1;
- yy = dy+1; if (yy > 1) yy -= 2; d.cell[dx+1][yy+1] = (float)i1;
- d.cell[-xx+1][-dy+1] = (float)i3; d.cell[-dx+1][-yy+1] = (float)i3;
- }
-
-return d;
+ }
+ d.cell[1][1] = 0; // central cell has zero weighting
+ d.cell[dx + 1][dy + 1] = (float)i0;
+ d.cell[-dx + 1][-dy + 1] = (float)i4;
+ if (dx == 0 || dy == 0) { // theta points to a cardinal direction
+ d.cell[dy + 1][dx + 1] = (float)i2; d.cell[-dy + 1][-dx + 1] = (float)i2;
+ if (dx == 0) { // theta points N or S
+ xx = dx + 1; if (xx > 1) dx -= 2; yy = dy;
+ d.cell[xx + 1][yy + 1] = (float)i1; d.cell[-xx + 1][yy + 1] = (float)i1;
+ d.cell[xx + 1][-yy + 1] = (float)i3; d.cell[-xx + 1][-yy + 1] = (float)i3;
+ }
+ else { // theta points W or E
+ yy = dy + 1; if (yy > 1) dy -= 2; xx = dx;
+ d.cell[xx + 1][yy + 1] = (float)i1; d.cell[xx + 1][-yy + 1] = (float)i1;
+ d.cell[-xx + 1][yy + 1] = (float)i3; d.cell[-xx + 1][-yy + 1] = (float)i3;
+ }
+ }
+ else { // theta points to an ordinal direction
+ d.cell[dx + 1][-dy + 1] = (float)i2; d.cell[-dx + 1][dy + 1] = (float)i2;
+ xx = dx + 1; if (xx > 1) xx -= 2; d.cell[xx + 1][dy + 1] = (float)i1;
+ yy = dy + 1; if (yy > 1) yy -= 2; d.cell[dx + 1][yy + 1] = (float)i1;
+ d.cell[-xx + 1][-dy + 1] = (float)i3; d.cell[-dx + 1][-yy + 1] = (float)i3;
+ }
+
+ return d;
}
// Weight neighbouring cells on basis of (habitat) costs
-array3x3f Individual::getHabMatrix(Landscape *pLand,Species *pSpecies,
- const int x,const int y,const short pr,const short prmethod,const short landIx,
+array3x3f Individual::getHabMatrix(Landscape* pLand, Species* pSpecies,
+ const int x, const int y, const short pr, const short prmethod, const short landIx,
const bool absorbing)
{
-array3x3f w; // array of effective costs to be returned
-int ncells,x4,y4;
-double weight,sumweights;
-// NW and SE corners of effective cost array relative to the current cell (x,y):
-int xmin = 0,ymin = 0,xmax = 0,ymax = 0;
-int cost,nodatacost,h;
-Cell *pCell;
+ array3x3f w; // array of effective costs to be returned
+ int ncells, x4, y4;
+ double weight, sumweights;
+ // NW and SE corners of effective cost array relative to the current cell (x,y):
+ int xmin = 0, ymin = 0, xmax = 0, ymax = 0;
+ int cost, nodatacost, h;
+ Cell* pCell;
-landData land = pLand->getLandData();
-if (absorbing) nodatacost = ABSNODATACOST;
-else nodatacost = NODATACOST;
+ landData land = pLand->getLandData();
+ if (absorbing) nodatacost = ABSNODATACOST;
+ else nodatacost = NODATACOST;
-for (int x2=-1; x2<2; x2++) { // index of relative move in x direction
- for (int y2=-1; y2<2; y2++) { // index of relative move in x direction
+ for (int x2 = -1; x2 < 2; x2++) { // index of relative move in x direction
+ for (int y2 = -1; y2 < 2; y2++) { // index of relative move in x direction
- w.cell[x2+1][y2+1] = 0.0; // initialise costs array to zeroes
+ w.cell[x2 + 1][y2 + 1] = 0.0; // initialise costs array to zeroes
- // set up corners of perceptual range relative to current cell
- if (x2==0 && y2==0) { // current cell - do nothing
- xmin=0; ymin=0; xmax=0; ymax=0;
- }
- else {
- if (x2==0 || y2==0) { // not diagonal (rook move)
- if (x2==0){ // vertical (N-S) move
- //out<<"ROOK N-S: x2 = "< land.maxX) x4 = x+x3-land.maxX-1; else x4 = x+x3; }
- if ((y+y3) < 0) y4 = y+y3+land.maxY+1;
- else { if ((y+y3) > land.maxY) y4 = y+y3-land.maxY-1; else y4 = y+y3; }
-// if (write_out && (x4 < 0 || y4 < 0)) {
-// out<<"ERROR: x "< land.maxX || y4 < 0 || y4 > land.maxY) {
- // unexpected problem - e.g. due to ridiculously large PR
- // treat as a no-data cell
- cost = nodatacost;
- }
- else {
- // add cost of cell to total PR cost
- pCell = pLand->findCell(x4,y4);
- if (pCell == 0) { // no-data cell
+ if (xmin > xmax) { int z = xmax; xmax = xmin; xmin = z; } // swap xmin and xmax
+ if (ymin > ymax) { int z = ymax; ymax = ymin; ymin = z; } // swap ymin and ymax
+
+ // calculate effective mean cost of cells in perceptual range
+ ncells = 0; weight = 0.0; sumweights = 0.0;
+ if (x2 != 0 || y2 != 0) { // not central cell (i.e. current cell)
+ for (int x3 = xmin; x3 <= xmax; x3++) {
+ for (int y3 = ymin; y3 <= ymax; y3++) {
+ // if cell is out of bounds, treat landscape as a torus
+ // for purpose of obtaining a cost,
+ if ((x + x3) < 0) x4 = x + x3 + land.maxX + 1;
+ else { if ((x + x3) > land.maxX) x4 = x + x3 - land.maxX - 1; else x4 = x + x3; }
+ if ((y + y3) < 0) y4 = y + y3 + land.maxY + 1;
+ else { if ((y + y3) > land.maxY) y4 = y + y3 - land.maxY - 1; else y4 = y + y3; }
+ if (x4 < 0 || x4 > land.maxX || y4 < 0 || y4 > land.maxY) {
+ // unexpected problem - e.g. due to ridiculously large PR
+ // treat as a no-data cell
cost = nodatacost;
}
else {
- cost = pCell->getCost();
- if (cost < 0) cost = nodatacost;
+ // add cost of cell to total PR cost
+ pCell = pLand->findCell(x4, y4);
+ if (pCell == 0) { // no-data cell
+ cost = nodatacost;
+ }
else {
- if (cost == 0) { // cost not yet set for the cell
- h = pCell->getHabIndex(landIx);
- cost = pSpecies->getHabCost(h);
-#if RSDEBUG
-//DEBUGLOG << "Individual::getHabMatrix(): x4=" << x4 << " y4=" << y4
-// << " landIx=" << landIx << " h=" << h << " cost=" << cost
-// << endl;
-#endif
- pCell->setCost(cost);
- }
+ cost = pCell->getCost();
+ if (cost < 0) cost = nodatacost;
else {
-#if RSDEBUG
-//DEBUGLOG << "Individual::getHabMatrix(): x4=" << x4 << " y4=" << y4
-// << " cost=" << cost
-// << endl;
-#endif
-
- }
+ if (cost == 0) { // cost not yet set for the cell
+ h = pCell->getHabIndex(landIx);
+ cost = pSpecies->getHabCost(h);
+ pCell->setCost(cost);
+ }
+ else {
+
+ }
+ }
}
}
+ if (prmethod == 1) { // arithmetic mean
+ w.cell[x2 + 1][y2 + 1] += cost;
+ ncells++;
+ }
+ if (prmethod == 2) { // harmonic mean
+ if (cost > 0) {
+ w.cell[x2 + 1][y2 + 1] += (1.0f / (float)cost);
+ ncells++;
+ }
+ }
+ if (prmethod == 3) { // arithmetic mean weighted by inverse distance
+ if (cost > 0) {
+ // NB distance is still given by (x3,y3)
+ weight = 1.0f / (double)sqrt((pow((double)x3, 2) + pow((double)y3, 2)));
+ w.cell[x2 + 1][y2 + 1] += (float)(weight * (double)cost);
+ ncells++; sumweights += weight;
+ }
+ }
+ } //end of y3 loop
+ } //end of x3 loop
+ if (ncells > 0) {
+ if (prmethod == 1) w.cell[x2 + 1][y2 + 1] /= ncells; // arithmetic mean
+ if (prmethod == 2) w.cell[x2 + 1][y2 + 1] = ncells / w.cell[x2 + 1][y2 + 1]; // hyperbolic mean
+ if (prmethod == 3 && sumweights > 0)
+ w.cell[x2 + 1][y2 + 1] /= (float)sumweights; // weighted arithmetic mean
+ }
+ }
+ else { // central cell
+ // record cost if not already recorded
+ // has effect of preparing for storing effective costs for the cell
+ pCell = pLand->findCell(x, y);
+ cost = pCell->getCost();
+ if (cost < 0) cost = nodatacost;
+ else {
+ if (cost == 0) { // cost not yet set for the cell
+ h = pCell->getHabIndex(landIx);
+ cost = pSpecies->getHabCost(h);
+ pCell->setCost(cost);
}
- if (prmethod==1) { // arithmetic mean
- w.cell[x2+1][y2+1] += cost;
- ncells++;
- }
- if (prmethod==2) { // harmonic mean
- if (cost > 0) {
- w.cell[x2+1][y2+1] += (1.0f/(float)cost);
- ncells++;
- }
- }
- if (prmethod==3) { // arithmetic mean weighted by inverse distance
- if (cost>0) {
- // NB distance is still given by (x3,y3)
- weight = 1.0f /(double)sqrt((pow((double)x3,2)+pow((double)y3,2)));
- w.cell[x2+1][y2+1] += (float)(weight*(double)cost);
- ncells++; sumweights += weight;
- }
- }
-// if (write_out2) out2<get_target() > 50) targetseen++;
-// }
-//#endif
- } //end of y3 loop
- } //end of x3 loop
-// if (write_out) out<<"ncells in PR = "<total << "\t" << loc.x << "\t" << loc.y << "\t"
- << status << "\t"
- << endl;
+ << path->total << "\t" << loc.x << "\t" << loc.y << "\t"
+ << status << "\t"
+ << endl;
}
// if not anymore dispersing...
- if(status > 1 && status < 10){
+ if (status > 1 && status < 10) {
prev_loc = pPrevCell->getLocn();
// record only if this is the first step as non-disperser
if (path->pathoutput) {
// if this is also the first step taken at all, record the start cell first
- if(path->total == 1){
+ if (path->total == 1) {
outMovePaths << year << "\t" << indId << "\t"
- << "0\t" << prev_loc.x << "\t" << prev_loc.y << "\t"
- << "0\t" // status at start cell is 0
- << endl;
+ << "0\t" << prev_loc.x << "\t" << prev_loc.y << "\t"
+ << "0\t" // status at start cell is 0
+ << endl;
}
outMovePaths << year << "\t" << indId << "\t"
- << path->total << "\t" << loc.x << "\t" << loc.y << "\t"
- << status << "\t"
- << endl;
+ << path->total << "\t" << loc.x << "\t" << loc.y << "\t"
+ << status << "\t"
+ << endl;
// current cell will be invalid (zero), so set back to previous cell
//pPrevCell = pCurrCell;
path->pathoutput = 0;
@@ -2422,33 +1783,76 @@ void Individual::outMovePath(const int year)
//---------------------------------------------------------------------------
-double wrpcauchy (double location, double rho) {
-double result;
-
-if(rho < 0.0 || rho > 1.0) {
-// ML_ERR_return_NAN;
- result = location;
-}
+double wrpcauchy(double location, double rho) {
+ double result;
-if(rho == 0)
- result = pRandom->Random() * M_2PI;
-else
- if(rho == 1) result = location;
- else {
- result = fmod(cauchy(location, -log(rho)), M_2PI);
+ if (rho < 0.0 || rho > 1.0) {
+ result = location;
}
-return result;
+
+ if (rho == 0)
+ result = pRandom->Random() * M_2PI;
+ else
+ if (rho == 1) result = location;
+ else {
+ result = fmod(cauchy(location, -log(rho)), M_2PI);
+ }
+ return result;
}
double cauchy(double location, double scale) {
-if (scale < 0) return location;
-//return location + scale * tan(M_PI * unif_rand());
-return location + scale * tan(PI * pRandom->Random());
-//return location + scale * tan(M_PI * pRandom->Random());
+ if (scale < 0) return location;
+ return location + scale * tan(PI * pRandom->Random());
}
-//#endif
-//#endif
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
+
+#if RSDEBUG
+
+
+void testIndividual() {
+
+ Patch* pPatch = new Patch(0, 0);
+ int cell_x = 2;
+ int cell_y = 5;
+ int cell_hab = 2;
+ Cell* pCell = new Cell(cell_x, cell_y, (intptr)pPatch, cell_hab);
+
+ // Create an individual
+ short stg = 0;
+ short age = 0;
+ short repInt = 0;
+ float probmale = 0;
+ bool uses_movt_process = true;
+ short moveType = 1;
+ Individual ind(pCell, pPatch, stg, age, repInt, probmale, uses_movt_process, moveType);
+
+ // An individual...
+ {
+ std::vector inds;
+ for (int i = 0; i < 2; i++)
+ {
+ inds.push_back(new Individual(pCell, pPatch, stg, age, repInt, probmale, uses_movt_process, moveType));
+ }
+ }
+
+ // Reproduces
+ // depending on whether it is sexual or not
+ // depending on the stage
+ // depending on the trait inheritance
+
+
+ // Disperses
+ // Emigrates
+ // Transfers
+ // Settles
+
+ // Survives
+
+ // Develops
+
+}
+#endif // RSDEBUG
+
diff --git a/RangeShiftR/src/RScore/Individual.h b/RangeShiftR/src/RScore/Individual.h
index d843d7e..bdc4ecb 100644
--- a/RangeShiftR/src/RScore/Individual.h
+++ b/RangeShiftR/src/RScore/Individual.h
@@ -49,7 +49,6 @@ Last updated: 26 October 2021 by Steve Palmer
#include
using namespace std;
-//#include "mathlib.h"
#include "Parameters.h"
#include "Species.h"
#include "Landscape.h"
@@ -73,7 +72,6 @@ struct pathData { // to hold path data common to SMS and CRW models
short settleStatus; // whether ind may settle in current patch
// 0 = not set, 1 = debarred through density dependence rule
// 2 = OK to settle subject to finding a mate
-// bool leftNatalPatch; // individual has moved out of its natal patch
#if RS_RCPP
short pathoutput;
#endif
@@ -209,13 +207,6 @@ class Individual {
const short, // landscape change index
const bool // absorbing boundaries?
);
- void drawMove( // Visualise paths resulting from movement simulation model
- // NULL for the batch version
- const float, // initial x co-ordinate
- const float, // initial y co-ordinate
- const float, // final x co-ordinate
- const float // final y co-ordinate
- );
movedata smsMove( // Move to a neighbouring cell according to the SMS algorithm
Landscape*, // pointer to Landscape
Species*, // pointer to Species
@@ -313,5 +304,9 @@ extern ofstream DEBUGLOG;
extern ofstream outMovePaths;
#endif
-//---------------------------------------------------------------------------
+#if RSDEBUG
+void testIndividual();
#endif
+
+//---------------------------------------------------------------------------
+#endif // IndividualH
diff --git a/RangeShiftR/src/RScore/Landscape.cpp b/RangeShiftR/src/RScore/Landscape.cpp
index ac9b733..be63ae9 100644
--- a/RangeShiftR/src/RScore/Landscape.cpp
+++ b/RangeShiftR/src/RScore/Landscape.cpp
@@ -1,25 +1,25 @@
/*----------------------------------------------------------------------------
- *
- * 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 .
- *
+ *
--------------------------------------------------------------------------*/
-
-
+
+
//---------------------------------------------------------------------------
#include "Landscape.h"
@@ -40,8 +40,8 @@ ofstream outMovePaths;
InitDist::InitDist(Species *pSp)
{
pSpecies = pSp;
-resol = 0;
-maxX = 0;
+resol = 0;
+maxX = 0;
maxY = 0;
minEast = 0.0;
minNorth = 0.0;
@@ -184,10 +184,8 @@ if (!dfile.is_open()) return 21;
// read landscape data from header records of distribution file
// NB headers of all files have already been compared
-double tmpresol;
dfile >> header >> ncols >> header >> nrows >> header >> minEast >> header >> minNorth
- >> header >> tmpresol >> header >> nodata;
-resol = (int) tmpresol;
+ >> header >> resol >> header >> nodata;
#if RS_RCPP
if (!dfile.good()) {
// corrupt file stream
@@ -263,7 +261,7 @@ minX = minY = 0;
maxX = maxY = 99;
minPct = maxPct = propSuit = hurst = 0.0;
maxCells = 100;
-gpix = 1.0;
+gpix = 1.0;
pix = (int)gpix;
minEast = minNorth = 0.0;
cells = 0;
@@ -931,14 +929,14 @@ case 2: // habitat quality
}
-Patch* Landscape::newPatch(int num)
+Patch* Landscape::newPatch(int num)
{
int npatches = (int)patches.size();
patches.push_back(new Patch(num,num));
return patches[npatches];
}
-Patch* Landscape::newPatch(int seqnum,int num)
+Patch* Landscape::newPatch(int seqnum,int num)
{
int npatches = (int)patches.size();
patches.push_back(new Patch(seqnum,num));
@@ -1181,14 +1179,14 @@ for(int y = dimY-1; y >= 0; y--){
habIndexed = true;
}
-void Landscape::setEnvGradient(Species *pSpecies,bool initial)
+void Landscape::setEnvGradient(Species *pSpecies,bool initial)
{
float dist_from_opt,dev;
float habK;
//int hab;
double envval;
// gradient parameters
-envGradParams grad = paramsGrad->getGradient();
+envGradParams grad = paramsGrad->getGradient();
#if RSDEBUG
//DEBUGLOG << "Landscape::setEnvGradient(): grad.opt_y = " << grad.opt_y
// << " grad.grad_inc = " << grad.grad_inc << " grad.factor " << grad.factor
@@ -1271,7 +1269,7 @@ for(int y = dimY-1; y >= 0; y--){
// << " env.std= " << env.std << " env.ac= " << env.ac << " randpart= " << randpart
// << endl;
#endif
- cells[y][x]->updateEps((float)env.ac,randpart);
+ cells[y][x]->updateEps((float)env.ac,randpart);
}
}
}
@@ -1345,7 +1343,7 @@ wstring header;
#else
string header;
int ncols,nrows,habnodata,costnodata,pchnodata;
-costnodata = 0;
+costnodata = 0;
pchnodata = 0;
#endif
int h = 0,p = 0,c = 0, pchseq = 0;
@@ -1962,7 +1960,7 @@ return initialise;
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();
}
@@ -2037,7 +2035,7 @@ initcells.clear();
// Read landscape file(s)
// Returns error code or zero if read correctly
-int Landscape::readLandscape(int fileNum,string habfile,string pchfile,string costfile)
+int Landscape::readLandscape(int fileNum,string habfile,string pchfile,string costfile)
{
// fileNum == 0 for (first) habitat file and optional patch file
// fileNum > 0 for subsequent habitat files under the %cover option
@@ -2052,7 +2050,7 @@ int pchnodata = 0;
int ncols,nrows;
float hfloat,pfloat;
Patch *pPatch;
-simParams sim = paramsSim->getSim();
+simParams sim = paramsSim->getSim();
if (fileNum < 0) return 19;
@@ -2076,7 +2074,7 @@ if(landraster.utf) {
}
#endif
if (!hfile.is_open()) return 11;
-if (fileNum == 0) {
+if (fileNum == 0) {
if (patchModel) {
#if !RS_RCPP || RSWIN64
pfile.open(pchfile.c_str());
@@ -2096,10 +2094,8 @@ if (fileNum == 0) {
// read landscape data from header records of habitat file
// NB headers of all files have already been compared
-double tmpresol;
hfile >> header >> ncols >> header >> nrows >> header >> minEast >> header >> minNorth
- >> header >> tmpresol >> header >> habnodata;
-resol = (int) tmpresol;
+ >> header >> resol >> header >> habnodata;
#if RS_RCPP
if (!hfile.good()) {
@@ -2126,7 +2122,7 @@ if (fileNum == 0) {
if (fileNum == 0) {
if (patchModel) {
for (int i = 0; i < 5; i++) pfile >> header >> pfloat;
- pfile >> header >> pchnodata;
+ pfile >> header >> pchnodata;
}
#if RS_RCPP
if (!pfile.good()) {
@@ -2247,8 +2243,8 @@ case 0: // raster with habitat codes - 100% habitat each cell
else {
if (existsPatch(p)) {
pPatch = findPatch(p);
- addNewCellToPatch(pPatch,x,y,h);
-// addNewCellToPatch(findPatch(p),x,y,h);
+ addNewCellToPatch(pPatch,x,y,h);
+// addNewCellToPatch(findPatch(p),x,y,h);
}
else {
pPatch = newPatch(seq++,p);
@@ -2645,7 +2641,7 @@ for (int y = maxYcost - 1; y > -1; y--){
if ( hc < 1 && hc != NODATACost ) {
#if RSDEBUG
#if BATCH
-// DEBUGLOG << "Landscape::readCosts(): x=" << x << " y=" << y
+// DEBUGLOG << "Landscape::readCosts(): x=" << x << " y=" << y
// << " fcost=" << fcost << " hc=" << hc
// << endl;
#endif
@@ -2723,9 +2719,7 @@ DebugGUI(("CheckRasterFile(): header=" + header + " r.yllcorner=" + Float2Str(r.
).c_str());
#endif
if (header != "yllcorner" && header != "YLLCORNER") r.errors++;
- double tmpcellsize;
- infile >> header >> tmpcellsize;
- r.cellsize = (int) tmpcellsize;
+ infile >> header >> r.cellsize;
#if RSDEBUG
DebugGUI(("CheckRasterFile(): header=" + header + " r.cellsize=" + Int2Str(r.cellsize)
).c_str());
@@ -2882,8 +2876,8 @@ for (int i = 0; i < npatches; i++) {
emigrants[i] += connectMatrix[i][j];
immigrants[j] += connectMatrix[i][j];
if (connectMatrix[i][j] > 0) {
- outConnMat << rep << "\t" << yr
- << "\t" << patchnum0 << "\t" << patchnum1
+ outConnMat << rep << "\t" << yr
+ << "\t" << patchnum0 << "\t" << patchnum1
<< "\t" << connectMatrix[i][j] << endl;
}
}
@@ -2894,11 +2888,11 @@ for (int i = 0; i < npatches; i++) {
for (int i = 0; i < npatches; i++) {
patchnum0 = patches[i]->getPatchNum();
if (patchnum0 != 0) {
- if (patches[i]->getK() > 0.0)
+ if (patches[i]->getK() > 0.0)
{ // suitable patch
- outConnMat << rep << "\t" << yr
+ outConnMat << rep << "\t" << yr
<< "\t" << patchnum0 << "\t-999\t" << emigrants[i] << endl;
- outConnMat << rep << "\t" << yr
+ outConnMat << rep << "\t" << yr
<< "\t-999\t" << patchnum0 << "\t" << immigrants[i] << endl;
}
}
diff --git a/RangeShiftR/src/RScore/Main.cpp b/RangeShiftR/src/RScore/Main.cpp
new file mode 100644
index 0000000..42f783b
--- /dev/null
+++ b/RangeShiftR/src/RScore/Main.cpp
@@ -0,0 +1,95 @@
+/*----------------------------------------------------------------------------
+ *
+ * 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 .
+ *
+ --------------------------------------------------------------------------*/
+
+#if LINUX_CLUSTER || R_CMD
+#include
+#else
+#include
+#endif
+
+#include
+#include
+#include
+#include
+#include "Individual.h"
+#include "Community.h"
+#include "RSrandom.h"
+#include "Utils.h"
+#include "Parameters.h"
+#include "Landscape.h"
+#include "Species.h"
+#include "SubCommunity.h"
+
+using namespace std;
+
+void run_unit_tests() {
+ cout << "******* Unit test output *******" << endl;
+ testRSrandom();
+ testIndividual();
+ cout << endl << "************************" << endl;
+}
+
+// Global vars
+string habmapname, patchmapname, distnmapname;
+string costmapname, genfilename;
+string landFile;
+paramGrad* paramsGrad;
+paramStoch* paramsStoch;
+paramInit* paramsInit;
+paramSim* paramsSim;
+RSrandom* pRandom;
+ofstream DEBUGLOG;
+ofstream MUTNLOG;
+vector hfnames;
+Species* pSpecies;
+Community* pComm;
+void DebugGUI(string msg) {
+ // nothing
+}
+void MemoLine(string msg) {
+ /// nothing
+}
+traitCanvas SetupTraitCanvas(void) {
+ traitCanvas tcanv;
+ for (int i = 0; i < NTRAITS; i++) { tcanv.pcanvas[i] = 0; }
+ return tcanv;
+}
+void Landscape::setLandMap(void) { }
+void Landscape::drawLandscape(int rep, int yr, int landnum) { }
+void Community::viewOccSuit(int year, double mn, double se) { }
+void Community::draw(int rep, int yr, int gen, int landNum) { }
+
+#if LINUX_CLUSTER || RS_RCPP
+int main(int argc, char* argv[])
+#else
+int _tmain(int argc, _TCHAR* argv[])
+#endif
+{
+#ifdef NDEBUG
+ cout << "This code is only for running tests and not meant to run in release." << endl;
+ return 1;
+# else
+ assert(0.1 > 0.0); // assert does run correctly
+ run_unit_tests();
+ cout << "All tests have completed." << endl;
+ return 0; // if tests succeed, we are happy
+# endif // NDEBUG
+}
diff --git a/RangeShiftR/src/RScore/Model.cpp b/RangeShiftR/src/RScore/Model.cpp
index 9f26886..64b5d87 100644
--- a/RangeShiftR/src/RScore/Model.cpp
+++ b/RangeShiftR/src/RScore/Model.cpp
@@ -152,17 +152,10 @@ DEBUGLOG << endl << "RunModel(): generating new landscape ..." << endl;
DEBUGLOG << "RunModel(): finished resetting landscape" << endl << endl;
#endif
pLandscape->generatePatches();
-//#if VCL
if (v.viewLand || sim.saveMaps) {
pLandscape->setLandMap();
pLandscape->drawLandscape(rep,0,ppLand.landNum);
}
-//#endif
-//#if BATCH
-// if (sim.saveMaps) {
-// pLandscape->drawLandscape(rep,0,ppLand.landNum);
-// }
-//#endif
#if RSDEBUG
DEBUGLOG << endl << "RunModel(): finished generating patches" << endl;
#endif
@@ -313,12 +306,8 @@ DEBUGLOG << "RunModel(): completed updating carrying capacity" << endl;
DEBUGLOG << "RunModel(): completed initialisation, rep=" << rep
<< " pSpecies=" << pSpecies << endl;
#endif
-#if BATCH
-#if RS_RCPP && !R_CMD
+#if BATCH && RS_RCPP && !R_CMD
Rcpp::Rcout << "RunModel(): completed initialisation " << endl;
-#else
- cout << "RunModel(): completed initialisation " << endl;
-#endif
#endif
// open a new individuals file for each replicate
@@ -926,7 +915,7 @@ return errorfolder;
//For outputs and population visualisations pre-reproduction
void PreReproductionOutput(Landscape *pLand,Community *pComm,int rep,int yr,int gen)
{
-#if RSDEBUG || VCL
+#if RSDEBUG
landParams ppLand = pLand->getLandParams();
#endif
simParams sim = paramsSim->getSim();
@@ -1341,22 +1330,6 @@ if (dem.stageStruct){
outPar << endl;
}
}
-#if VCL
- else {
-
- // NOTE: TO PREVENT COMPILING FOR BATCH MODE, THIS CODE NEEDS TO BE INCLUDED IN COMPILER
- // CONDITIONAL BLOCK AS SHOWN
-
-// outPar << "Row count: " << frmSpecies->transMatrix->RowCount << endl;
-// outPar << "Col count: " << frmSpecies->transMatrix->ColCount << endl;
- for (int i = 1; i < frmSpecies->transMatrix->RowCount; i++) {
- for (int j = 1; j < frmSpecies->transMatrix->ColCount; j++) {
- outPar << frmSpecies->transMatrix->Cells[j][i].ToDouble() << "\t";
- }
- outPar << endl;
- }
- }
-#endif
outPar << endl;
#endif
*/
diff --git a/RangeShiftR/src/RScore/Model.h b/RangeShiftR/src/RScore/Model.h
index 4acf37a..5bd02bd 100644
--- a/RangeShiftR/src/RScore/Model.h
+++ b/RangeShiftR/src/RScore/Model.h
@@ -49,9 +49,9 @@ Last updated: 26 October 2021 by Steve Palmer
#include
#include
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
@@ -75,12 +75,12 @@ extern ofstream DEBUGLOG;
#if RS_RCPP && !R_CMD
Rcpp::List RunModel(
Landscape*, // pointer to Landscape
- int // sequential simulation number (always 0 for VCL version)
+ int // sequential simulation number
);
#else
int RunModel(
Landscape*, // pointer to Landscape
- int // sequential simulation number (always 0 for VCL version)
+ int // sequential simulation number
);
#endif // RS_RCPP && !R_CMD
bool CheckDirectory(void);
@@ -125,11 +125,11 @@ extern Community *pComm;
const bool batchMode = true;
extern string landFile;
extern vector hfnames;
-extern string habmapname; // see FormLand.cpp (VCL) OR Main.cpp (batch)
-extern string patchmapname; // see FormLand.cpp (VCL) OR Main.cpp (batch)
-extern string distnmapname; // see FormLand.cpp (VCL) OR Main.cpp (batch)
-extern string costmapname; // see FormMove.cpp (VCL) OR Main.cpp (batch)
-extern string genfilename; // see FormGenetics.cpp (VCL) OR Main.cpp (batch)
+extern string habmapname; // see Main.cpp (batch)
+extern string patchmapname; // see Main.cpp (batch)
+extern string distnmapname; // see Main.cpp (batch)
+extern string costmapname; // see Main.cpp (batch)
+extern string genfilename; // see Main.cpp (batch)
extern RSrandom *pRandom;
// these functions to have different version for GUI and batch applications ...
diff --git a/RangeShiftR/src/RScore/Parameters.h b/RangeShiftR/src/RScore/Parameters.h
index d44cf14..b029491 100644
--- a/RangeShiftR/src/RScore/Parameters.h
+++ b/RangeShiftR/src/RScore/Parameters.h
@@ -60,9 +60,9 @@ Last updated: 25 June 2021 by Steve Palmer
#include
#include
using namespace std;
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
diff --git a/RangeShiftR/src/RScore/Patch.h b/RangeShiftR/src/RScore/Patch.h
index 2bc30e7..2f086d7 100644
--- a/RangeShiftR/src/RScore/Patch.h
+++ b/RangeShiftR/src/RScore/Patch.h
@@ -68,9 +68,9 @@ Last updated: 25 June 2021 by Steve Palmer
#include
using namespace std;
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
diff --git a/RangeShiftR/src/RScore/Population.cpp b/RangeShiftR/src/RScore/Population.cpp
index 05d8633..4af1e84 100644
--- a/RangeShiftR/src/RScore/Population.cpp
+++ b/RangeShiftR/src/RScore/Population.cpp
@@ -1,26 +1,26 @@
/*----------------------------------------------------------------------------
- *
- * 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 .
- *
+ *
--------------------------------------------------------------------------*/
-
-
-//---------------------------------------------------------------------------
+
+
+ //---------------------------------------------------------------------------
#include "Population.h"
//---------------------------------------------------------------------------
@@ -30,665 +30,442 @@ ofstream outInds;
//---------------------------------------------------------------------------
-Population::Population(void) {
-nSexes = nStages = 0;
-pPatch = NULL;
-pSpecies = NULL;
-return;
+Population::Population(void) {
+ nSexes = nStages = 0;
+ pPatch = NULL;
+ pSpecies = NULL;
+ return;
}
-Population::Population(Species *pSp,Patch *pPch,int ninds,int resol)
+Population::Population(Species* pSp, Patch* pPch, int ninds, int resol)
{
-// constructor for a Population of a specified size
-#if RSDEBUG
-//DEBUGLOG << "Population::Population(): this=" << this
-// << " pPch=" << pPch << " ninds="<< ninds << endl;
-#endif
-
-int n,nindivs,age = 0,minage,maxage,nAges = 0;
-int cumtotal = 0;
-float probmale;
-double ageprob,ageprobsum;
-std::vector ageProb; // for quasi-equilibrium initial age distribution
-Cell *pCell;
+ // constructor for a Population of a specified size
+
+ int n, nindivs, age = 0, minage, maxage, nAges = 0;
+ int cumtotal = 0;
+ float probmale;
+ double ageprob, ageprobsum;
+ std::vector ageProb; // for quasi-equilibrium initial age distribution
+ Cell* pCell;
+
+ if (ninds > 0) {
+ inds.reserve(ninds);
+ juvs.reserve(ninds);
+ }
-if (ninds > 0) {
- inds.reserve(ninds);
- juvs.reserve(ninds);
-}
+ pSpecies = pSp;
+ pPatch = pPch;
+ // record the new population in the patch
+ patchPopn pp;
+ pp.pSp = (intptr)pSpecies; pp.pPop = (intptr)this;
+ pPatch->addPopn(pp);
-pSpecies = pSp;
-pPatch = pPch;
-// record the new population in the patch
-patchPopn pp;
-pp.pSp = (intptr)pSpecies; pp.pPop = (intptr)this;
-pPatch->addPopn(pp);
-#if RSDEBUG
-//DEBUGLOG << "Population::Population(): this=" << this
-// << " added population to patch " << endl;
-#endif
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
+ genomeData gen = pSpecies->getGenomeData();
+ initParams init = paramsInit->getInit();
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-//trfrSMSTraits sms = pSpecies->getSMSTraits();
-settleType sett = pSpecies->getSettle();
-genomeData gen = pSpecies->getGenomeData();
-initParams init = paramsInit->getInit();
-
-// determine no. of stages and sexes of species to initialise
-if (dem.stageStruct) {
- nStages = sstruct.nStages;
-}
-else // non-structured population has 2 stages, but user only ever sees stage 1
- nStages = 2;
-if (dem.repType == 0) { nSexes = 1; probmale = 0.0; }
-else { nSexes = 2; probmale = dem.propMales; }
-
-// set up population sub-totals
-for (int stg = 0; stg < NSTAGES; stg++) {
- for (int sex = 0; sex < NSEXES; sex++) {
- nInds[stg][sex] = 0;
+ // determine no. of stages and sexes of species to initialise
+ if (dem.stageStruct) {
+ nStages = sstruct.nStages;
+ }
+ else // non-structured population has 2 stages, but user only ever sees stage 1
+ nStages = 2;
+ if (dem.repType == 0) { nSexes = 1; probmale = 0.0; }
+ else { nSexes = 2; probmale = dem.propMales; }
+
+ // set up population sub-totals
+ for (int stg = 0; stg < NSTAGES; stg++) {
+ for (int sex = 0; sex < NSEXES; sex++) {
+ nInds[stg][sex] = 0;
+ }
}
-}
-// set up local copy of minimum age table
-short minAge[NSTAGES][NSEXES];
-for (int stg = 0; stg < nStages; stg++) {
- for (int sex = 0; sex < nSexes; sex++) {
- if (dem.stageStruct) {
- if (dem.repType == 1) { // simple sexual model
- // both sexes use minimum ages recorded for females
- minAge[stg][sex] = pSpecies->getMinAge(stg,0);
+ // set up local copy of minimum age table
+ short minAge[NSTAGES][NSEXES];
+ for (int stg = 0; stg < nStages; stg++) {
+ for (int sex = 0; sex < nSexes; sex++) {
+ if (dem.stageStruct) {
+ if (dem.repType == 1) { // simple sexual model
+ // both sexes use minimum ages recorded for females
+ minAge[stg][sex] = pSpecies->getMinAge(stg, 0);
+ }
+ else {
+ minAge[stg][sex] = pSpecies->getMinAge(stg, sex);
+ }
}
- else {
- minAge[stg][sex] = pSpecies->getMinAge(stg,sex);
+ else { // non-structured population
+ minAge[stg][sex] = 0;
}
}
- else { // non-structured population
- minAge[stg][sex] = 0;
- }
-#if RSDEBUG
-//DEBUGLOG << "Population::Population(): 1111 "
-// << " minAge[" << stg << "][" << sex << "]=" << minAge[stg][sex]
-// << endl;
-#endif
}
-}
-// individuals of new population must be >= stage 1
-for (int stg = 1; stg < nStages; stg++) {
- if (dem.stageStruct) { // allocate to stages according to initialisation conditions
- // final stage is treated separately to ensure that correct total
- // no. of individuals is created
- if (stg == nStages-1) {
- n = ninds - cumtotal;
+ // individuals of new population must be >= stage 1
+ for (int stg = 1; stg < nStages; stg++) {
+ if (dem.stageStruct) { // allocate to stages according to initialisation conditions
+ // final stage is treated separately to ensure that correct total
+ // no. of individuals is created
+ if (stg == nStages - 1) {
+ n = ninds - cumtotal;
+ }
+ else {
+ n = (int)(ninds * paramsInit->getProp(stg) + 0.5);
+ cumtotal += n;
+ }
}
- else {
- n = (int)(ninds * paramsInit->getProp(stg) + 0.5);
- cumtotal += n;
+ else { // non-structured - all individuals go into stage 1
+ n = ninds;
}
- }
- else { // non-structured - all individuals go into stage 1
- n = ninds;
- }
-// for (int sex = 0; sex < nSexes; sex++) {
-// if (n < nSexes) n = nSexes; // to ensure at least one individual of each age is created
-// subPops.push_back(new SubPop(loc,stg,sex,n/nSexes));
-// }
- // establish initial age distribution
- minage = maxage = stg;
- if (dem.stageStruct) {
- // allow for stage-dependent minimum ages (use whichever sex is greater)
- if (minAge[stg][0] > 0 && minage < minAge[stg][0]) minage = minAge[stg][0];
- if (nSexes == 2 && minAge[stg][1] > 0 && minage < minAge[stg][1]) minage = minAge[stg][1];
- // allow for specified age distribution
- if (init.initAge != 0) { // not lowest age
- if (stg == nStages-1) maxage = sstruct.maxAge; // final stage
- else { // all other stages - use female max age, as sex of individuals is not predetermined
- maxage = minAge[stg+1][0] - 1;
- }
- if (maxage < minage) maxage = minage;
- nAges = maxage - minage + 1;
- if (init.initAge == 2) { // quasi-equilibrium distribution
- double psurv = (double)pSpecies->getSurv(stg,0); // use female survival for the stage
- ageProb.clear();
- ageprobsum = 0.0;
- ageprob = 1.0;
- for (int i = 0; i < nAges; i++) {
- ageProb.push_back(ageprob); ageprobsum += ageprob; ageprob *= psurv;
+ // establish initial age distribution
+ minage = maxage = stg;
+ if (dem.stageStruct) {
+ // allow for stage-dependent minimum ages (use whichever sex is greater)
+ if (minAge[stg][0] > 0 && minage < minAge[stg][0]) minage = minAge[stg][0];
+ if (nSexes == 2 && minAge[stg][1] > 0 && minage < minAge[stg][1]) minage = minAge[stg][1];
+ // allow for specified age distribution
+ if (init.initAge != 0) { // not lowest age
+ if (stg == nStages - 1) maxage = sstruct.maxAge; // final stage
+ else { // all other stages - use female max age, as sex of individuals is not predetermined
+ maxage = minAge[stg + 1][0] - 1;
}
- for (int i = 0; i < nAges; i++) {
- ageProb[i] /= ageprobsum;
- if (i > 0) ageProb[i] += ageProb[i-1]; // to give cumulative probability
+ if (maxage < minage) maxage = minage;
+ nAges = maxage - minage + 1;
+ if (init.initAge == 2) { // quasi-equilibrium distribution
+ double psurv = (double)pSpecies->getSurv(stg, 0); // use female survival for the stage
+ ageProb.clear();
+ ageprobsum = 0.0;
+ ageprob = 1.0;
+ for (int i = 0; i < nAges; i++) {
+ ageProb.push_back(ageprob); ageprobsum += ageprob; ageprob *= psurv;
+ }
+ for (int i = 0; i < nAges; i++) {
+ ageProb[i] /= ageprobsum;
+ if (i > 0) ageProb[i] += ageProb[i - 1]; // to give cumulative probability
+ }
}
}
}
- }
-#if RSDEBUG
-//DEBUGLOG << "Population::Population(): this=" << this
-// << " n=" << n << " stg=" << stg << " minage=" << minage << " maxage=" << maxage
-// << endl;
-#endif
- // create individuals
- int sex;
- nindivs = (int)inds.size();
- for (int i = 0; i < n; i++) {
- pCell = pPatch->getRandomCell();
- if (dem.stageStruct) {
- switch (init.initAge) {
- case 0: // lowest possible age
- age = minage;
- break;
- case 1: // randomised
- if (maxage > minage) age = pRandom->IRandom(minage,maxage);
- else age = minage;
- break;
- case 2: // quasi-equilibrium
- if (nAges > 1) {
- double rrr = pRandom->Random();
- int ageclass = 0;
- while (rrr > ageProb[ageclass]) ageclass++;
- age = minage + ageclass;
+ // create individuals
+ int sex;
+ nindivs = (int)inds.size();
+ for (int i = 0; i < n; i++) {
+ pCell = pPatch->getRandomCell();
+ if (dem.stageStruct) {
+ switch (init.initAge) {
+ case 0: // lowest possible age
+ age = minage;
+ break;
+ case 1: // randomised
+ if (maxage > minage) age = pRandom->IRandom(minage, maxage);
+ else age = minage;
+ break;
+ case 2: // quasi-equilibrium
+ if (nAges > 1) {
+ double rrr = pRandom->Random();
+ int ageclass = 0;
+ while (rrr > ageProb[ageclass]) ageclass++;
+ age = minage + ageclass;
+ }
+ else age = minage;
+ break;
}
- else age = minage;
- break;
}
- }
- else age = stg;
+ else age = stg;
#if RSDEBUG
- // NOTE: CURRENTLY SETTING ALL INDIVIDUALS TO RECORD NO. OF STEPS ...
- inds.push_back(new Individual(pCell,pPatch,stg,age,sstruct.repInterval,
- probmale,true,trfr.moveType));
+ // NOTE: CURRENTLY SETTING ALL INDIVIDUALS TO RECORD NO. OF STEPS ...
+ inds.push_back(new Individual(pCell, pPatch, stg, age, sstruct.repInterval,
+ probmale, true, trfr.moveType));
#else
- inds.push_back(new Individual(pCell,pPatch,stg,age,sstruct.repInterval,
- probmale,trfr.moveModel,trfr.moveType));
-#endif
- sex = inds[nindivs+i]->getSex();
- if (emig.indVar || trfr.indVar || sett.indVar || gen.neutralMarkers)
- {
- // individual variation - set up genetics
- inds[nindivs+i]->setGenes(pSpecies,resol);
+ inds.push_back(new Individual(pCell, pPatch, stg, age, sstruct.repInterval,
+ probmale, trfr.moveModel, trfr.moveType));
+#endif
+ sex = inds[nindivs + i]->getSex();
+ if (emig.indVar || trfr.indVar || sett.indVar || gen.neutralMarkers)
+ {
+ // individual variation - set up genetics
+ inds[nindivs + i]->setGenes(pSpecies, resol);
+ }
+ nInds[stg][sex]++;
}
- nInds[stg][sex]++;
}
}
-#if RSDEBUG
-//DEBUGLOG << "Population::Population(): this=" << this
-// << " finished " << endl;
-#endif
-}
Population::~Population(void) {
-int ninds = (int)inds.size();
-for (int i = 0; i < ninds; i++) {
- if (inds[i] != NULL) delete inds[i];
-}
-inds.clear();
-int njuvs = (int)juvs.size();
-for (int i = 0; i < njuvs; i++) {
- if (juvs[i] != NULL) delete juvs[i];
-}
-juvs.clear();
-}
-
-traitsums Population::getTraits(Species *pSpecies) {
-int g;
-traitsums ts;
-for (int i = 0; i < NSEXES; i++) {
- ts.ninds[i] = 0;
- ts.sumD0[i] = ts.ssqD0[i] = 0.0;
- ts.sumAlpha[i] = ts.ssqAlpha[i] = 0.0; ts.sumBeta[i] = ts.ssqBeta[i] = 0.0;
- ts.sumDist1[i] = ts.ssqDist1[i] = 0.0; ts.sumDist2[i] = ts.ssqDist2[i] = 0.0;
- ts.sumProp1[i] = ts.ssqProp1[i] = 0.0;
- ts.sumDP[i] = ts.ssqDP[i] = 0.0;
- ts.sumGB[i] = ts.ssqGB[i] = 0.0;
- ts.sumAlphaDB[i] = ts.ssqAlphaDB[i] = 0.0;
- ts.sumBetaDB[i] = ts.ssqBetaDB[i] = 0.0;
- ts.sumStepL[i] = ts.ssqStepL[i] = 0.0; ts.sumRho[i] = ts.ssqRho[i] = 0.0;
- ts.sumS0[i] = ts.ssqS0[i] = 0.0;
- ts.sumAlphaS[i] = ts.ssqAlphaS[i] = 0.0; ts.sumBetaS[i] = ts.ssqBetaS[i] = 0.0;
-}
-//locus loc;
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ if (inds[i] != NULL) delete inds[i];
+ }
+ inds.clear();
+ int njuvs = (int)juvs.size();
+ for (int i = 0; i < njuvs; i++) {
+ if (juvs[i] != NULL) delete juvs[i];
+ }
+ juvs.clear();
+}
+
+traitsums Population::getTraits(Species* pSpecies) {
+ int g;
+ traitsums ts;
+ for (int i = 0; i < NSEXES; i++) {
+ ts.ninds[i] = 0;
+ ts.sumD0[i] = ts.ssqD0[i] = 0.0;
+ ts.sumAlpha[i] = ts.ssqAlpha[i] = 0.0; ts.sumBeta[i] = ts.ssqBeta[i] = 0.0;
+ ts.sumDist1[i] = ts.ssqDist1[i] = 0.0; ts.sumDist2[i] = ts.ssqDist2[i] = 0.0;
+ ts.sumProp1[i] = ts.ssqProp1[i] = 0.0;
+ ts.sumDP[i] = ts.ssqDP[i] = 0.0;
+ ts.sumGB[i] = ts.ssqGB[i] = 0.0;
+ ts.sumAlphaDB[i] = ts.ssqAlphaDB[i] = 0.0;
+ ts.sumBetaDB[i] = ts.ssqBetaDB[i] = 0.0;
+ ts.sumStepL[i] = ts.ssqStepL[i] = 0.0; ts.sumRho[i] = ts.ssqRho[i] = 0.0;
+ ts.sumS0[i] = ts.ssqS0[i] = 0.0;
+ ts.sumAlphaS[i] = ts.ssqAlphaS[i] = 0.0; ts.sumBetaS[i] = ts.ssqBetaS[i] = 0.0;
+ }
-demogrParams dem = pSpecies->getDemogr();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
+ demogrParams dem = pSpecies->getDemogr();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
-int ninds = (int)inds.size();
-#if RSDEBUG
-//DEBUGLOG << "Population::getTraits(): ninds = " << ts.ninds[0]
-//// << " nalleles = "<< nalleles
-//// << " nemiggenes = " << nemiggenes << " ntrfrgenes = " << ntrfrgenes
-// << endl;
-#endif
-for (int i = 0; i < ninds; i++) {
- int sex = inds[i]->getSex();
- if (emig.sexDep || trfr.sexDep || sett.sexDep) g = sex; else g = 0;
- ts.ninds[g] += 1;
- // emigration traits
- emigTraits e = inds[i]->getEmigTraits();
- if (emig.sexDep) g = sex; else g = 0;
- ts.sumD0[g] += e.d0; ts.ssqD0[g] += e.d0 * e.d0;
- ts.sumAlpha[g] += e.alpha; ts.ssqAlpha[g] += e.alpha * e.alpha;
- ts.sumBeta[g] += e.beta; ts.ssqBeta[g] += e.beta * e.beta;
- // transfer traits
- trfrKernTraits k = inds[i]->getKernTraits();
- if (trfr.sexDep) g = sex; else g = 0;
- ts.sumDist1[g] += k.meanDist1; ts.ssqDist1[g] += k.meanDist1 * k.meanDist1;
- ts.sumDist2[g] += k.meanDist2; ts.ssqDist2[g] += k.meanDist2 * k.meanDist2;
- ts.sumProp1[g] += k.probKern1; ts.ssqProp1[g] += k.probKern1 * k.probKern1;
- trfrSMSTraits sms = inds[i]->getSMSTraits();
- g = 0; // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT
- ts.sumDP[g] += sms.dp; ts.ssqDP[g] += sms.dp * sms.dp;
- ts.sumGB[g] += sms.gb; ts.ssqGB[g] += sms.gb * sms.gb;
- ts.sumAlphaDB[g] += sms.alphaDB; ts.ssqAlphaDB[g] += sms.alphaDB * sms.alphaDB;
- ts.sumBetaDB[g] += sms.betaDB; ts.ssqBetaDB[g] += sms.betaDB * sms.betaDB;
-#if RSDEBUG
-//DEBUGLOG << "Population::getTraits():"
-// << " i=" << i << " g=" << g
-// << " sms.dp= " << sms.dp << " sms.gb= " << sms.gb
-// << " ts.sumDP[g]= " << ts.sumDP[g] << " ts.ssqDP[g]= " << ts.ssqDP[g]
-// << " ts.sumGB[g]= " << ts.sumGB[g] << " ts.ssqGB[g]= " << ts.ssqGB[g]
-// << endl;
-#endif
- trfrCRWTraits c = inds[i]->getCRWTraits();
- g = 0; // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT
- ts.sumStepL[g] += c.stepLength; ts.ssqStepL[g] += c.stepLength * c.stepLength;
- ts.sumRho[g] += c.rho; ts.ssqRho[g] += c.rho * c.rho;
- // settlement traits
- settleTraits s = inds[i]->getSettTraits();
- if (sett.sexDep) g = sex; else g = 0;
-// g = 0; // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT
- ts.sumS0[g] += s.s0; ts.ssqS0[g] += s.s0 * s.s0;
- ts.sumAlphaS[g] += s.alpha; ts.ssqAlphaS[g] += s.alpha * s.alpha;
- ts.sumBetaS[g] += s.beta; ts.ssqBetaS[g] += s.beta * s.beta;
-#if RSDEBUG
-//DEBUGLOG << "Population::getTraits():"
-// << " i=" << i << " g=" << g << " a=" << a
-// << " e.d0= " << e.d0 << " e.alpha= " << e.alpha << " e.beta= " << e.beta
-// << " mnd0= " << emigTraits[g]->mnD0 << " mnAlpha= " << emigTraits[g]->mnAlpha << " mnBeta= " << emigTraits[g]->mnBeta
-// << " sqd0= " << emigTraits[g]->sqD0 << " sqAlpha= " << emigTraits[g]->sqAlpha << " sqBeta= " << emigTraits[g]->sqBeta
-// << endl;
-#endif
-}
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ int sex = inds[i]->getSex();
+ if (emig.sexDep || trfr.sexDep || sett.sexDep) g = sex; else g = 0;
+ ts.ninds[g] += 1;
+ // emigration traits
+ emigTraits e = inds[i]->getEmigTraits();
+ if (emig.sexDep) g = sex; else g = 0;
+ ts.sumD0[g] += e.d0; ts.ssqD0[g] += e.d0 * e.d0;
+ ts.sumAlpha[g] += e.alpha; ts.ssqAlpha[g] += e.alpha * e.alpha;
+ ts.sumBeta[g] += e.beta; ts.ssqBeta[g] += e.beta * e.beta;
+ // transfer traits
+ trfrKernTraits k = inds[i]->getKernTraits();
+ if (trfr.sexDep) g = sex; else g = 0;
+ ts.sumDist1[g] += k.meanDist1; ts.ssqDist1[g] += k.meanDist1 * k.meanDist1;
+ ts.sumDist2[g] += k.meanDist2; ts.ssqDist2[g] += k.meanDist2 * k.meanDist2;
+ ts.sumProp1[g] += k.probKern1; ts.ssqProp1[g] += k.probKern1 * k.probKern1;
+ trfrSMSTraits sms = inds[i]->getSMSTraits();
+ g = 0; // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT
+ ts.sumDP[g] += sms.dp; ts.ssqDP[g] += sms.dp * sms.dp;
+ ts.sumGB[g] += sms.gb; ts.ssqGB[g] += sms.gb * sms.gb;
+ ts.sumAlphaDB[g] += sms.alphaDB; ts.ssqAlphaDB[g] += sms.alphaDB * sms.alphaDB;
+ ts.sumBetaDB[g] += sms.betaDB; ts.ssqBetaDB[g] += sms.betaDB * sms.betaDB;
+ trfrCRWTraits c = inds[i]->getCRWTraits();
+ g = 0; // CURRENTLY INDIVIDUAL VARIATION CANNOT BE SEX-DEPENDENT
+ ts.sumStepL[g] += c.stepLength; ts.ssqStepL[g] += c.stepLength * c.stepLength;
+ ts.sumRho[g] += c.rho; ts.ssqRho[g] += c.rho * c.rho;
+ // settlement traits
+ settleTraits s = inds[i]->getSettTraits();
+ if (sett.sexDep) g = sex; else g = 0;
+ ts.sumS0[g] += s.s0; ts.ssqS0[g] += s.s0 * s.s0;
+ ts.sumAlphaS[g] += s.alpha; ts.ssqAlphaS[g] += s.alpha * s.alpha;
+ ts.sumBetaS[g] += s.beta; ts.ssqBetaS[g] += s.beta * s.beta;
+ }
-return ts;
+ return ts;
}
int Population::getNInds(void) { return (int)inds.size(); }
-popStats Population::getStats(void)
+popStats Population::getStats(void)
{
-popStats p;
-int ninds;
-float fec;
-bool breeders[2]; breeders[0] = breeders[1] = false;
-demogrParams dem = pSpecies->getDemogr();
-p.pSpecies = pSpecies;
-p.pPatch = pPatch;
-p.spNum = pSpecies->getSpNum();
-p.nInds = (int)inds.size();
-p.nNonJuvs = p.nAdults = 0;
-p.breeding = false;
-#if RSDEBUG
-//DEBUGLOG << "Population::getStats(): this=" << this
-//// << " p.pSpecies=" << p.pSpecies << " p.spNum=" << p.spNum
-// << " p.pPatch=" << p.pPatch << " patchNum=" << p.pPatch->getPatchNum()
-// << " nStages=" << nStages << " nSexes=" << nSexes << " p.nInds=" << p.nInds
-// << endl;
-#endif
-for (int stg = 1; stg < nStages; stg++) {
- for (int sex = 0; sex < nSexes; sex++) {
- ninds = nInds[stg][sex];
- p.nNonJuvs += ninds;
-#if RSDEBUG
-//DEBUGLOG << "Population::getStats(): this=" << this
-// << " stg=" << stg << " sex=" << sex
-// << " nInds[stg][sex]=" << nInds[stg][sex] << " p.nNonJuvs=" << p.nNonJuvs
-// << endl;
-#endif
- if (ninds > 0) {
- if (pSpecies->stageStructured()) {
- if (dem.repType == 2) fec = pSpecies->getFec(stg,sex);
- else fec = pSpecies->getFec(stg,0);
- if (fec > 0.0) { breeders[sex] = true; p.nAdults += ninds; }
+ popStats p;
+ int ninds;
+ float fec;
+ bool breeders[2]; breeders[0] = breeders[1] = false;
+ demogrParams dem = pSpecies->getDemogr();
+ p.pSpecies = pSpecies;
+ p.pPatch = pPatch;
+ p.spNum = pSpecies->getSpNum();
+ p.nInds = (int)inds.size();
+ p.nNonJuvs = p.nAdults = 0;
+ p.breeding = false;
+ for (int stg = 1; stg < nStages; stg++) {
+ for (int sex = 0; sex < nSexes; sex++) {
+ ninds = nInds[stg][sex];
+ p.nNonJuvs += ninds;
+
+ if (ninds > 0) {
+ if (pSpecies->stageStructured()) {
+ if (dem.repType == 2) fec = pSpecies->getFec(stg, sex);
+ else fec = pSpecies->getFec(stg, 0);
+ if (fec > 0.0) { breeders[sex] = true; p.nAdults += ninds; }
+ }
+ else breeders[sex] = true;
}
- else breeders[sex] = true;
}
}
-}
-// is there a breeding population present?
-if (nSexes == 1) {
- p.breeding = breeders[0];
-}
-else {
- if (breeders[0] && breeders[1]) p.breeding = true;
-}
-#if RSDEBUG
-//DEBUGLOG << "Population::getStats(): this=" << this
-// << " p.nInds=" << p.nInds << " p.nAdults=" << p.nAdults << " p.nNonJuvs=" << p.nNonJuvs
-// << " breeders[0]=" << breeders[0] << " breeders[1]=" << breeders[1]
-// << " p.breeding=" << p.breeding
-// << endl;
-#endif
-return p;
+ // is there a breeding population present?
+ if (nSexes == 1) {
+ p.breeding = breeders[0];
+ }
+ else {
+ if (breeders[0] && breeders[1]) p.breeding = true;
+ }
+ return p;
}
Species* Population::getSpecies(void) { return pSpecies; }
int Population::totalPop(void) {
-int t = 0;
-for (int stg = 0; stg < nStages; stg++) {
- for (int sex = 0; sex < nSexes; sex++) {
- t += nInds[stg][sex];
-#if RSDEBUG
-//DEBUGLOG << "Population::totalPop(): this=" << this
-// << " stg=" << stg << " sex=" << sex
-// << " nInds[stg][sex]=" << nInds[stg][sex] << " t=" << t
-// << endl;
-#endif
+ int t = 0;
+ for (int stg = 0; stg < nStages; stg++) {
+ for (int sex = 0; sex < nSexes; sex++) {
+ t += nInds[stg][sex];
+ }
}
-}
-return t;
+ return t;
}
int Population::stagePop(int stg) {
-int t = 0;
-if (stg < 0 || stg >= nStages) return t;
-for (int sex = 0; sex < nSexes; sex++) {
- t += nInds[stg][sex];
-}
-return t;
+ int t = 0;
+ if (stg < 0 || stg >= nStages) return t;
+ for (int sex = 0; sex < nSexes; sex++) {
+ t += nInds[stg][sex];
+ }
+ return t;
}
//---------------------------------------------------------------------------
// Remove all Individuals
void Population::extirpate(void) {
-int ninds = (int)inds.size();
-for (int i = 0; i < ninds; i++) {
- if (inds[i] != NULL) delete inds[i];
-}
-inds.clear();
-int njuvs = (int)juvs.size();
-for (int i = 0; i < njuvs; i++) {
- if (juvs[i] != NULL) delete juvs[i];
-}
-juvs.clear();
-for (int sex = 0; sex < nSexes; sex++) {
- for (int stg = 0; stg < nStages; stg++) {
- nInds[stg][sex] = 0;
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ if (inds[i] != NULL) delete inds[i];
+ }
+ inds.clear();
+ int njuvs = (int)juvs.size();
+ for (int i = 0; i < njuvs; i++) {
+ if (juvs[i] != NULL) delete juvs[i];
+ }
+ juvs.clear();
+ for (int sex = 0; sex < nSexes; sex++) {
+ for (int stg = 0; stg < nStages; stg++) {
+ nInds[stg][sex] = 0;
+ }
}
-}
}
//---------------------------------------------------------------------------
// Produce juveniles and hold them in the juvs vector
-void Population::reproduction(const float localK,const float envval,const int resol)
+void Population::reproduction(const float localK, const float envval, const int resol)
{
-// get population size at start of reproduction
-int ninds = (int)inds.size();
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): this=" << this
-//#if BUTTERFLYDISP
-// << " option=" << option
-//#endif // BUTTERFLYDISP
-//#if RS_CONTAIN
-// << " hab=" << hab
-//#endif // RS_CONTAIN
-// << " ninds=" << ninds
-// << endl;
-#endif // RSDEBUG
-if (ninds == 0) return;
-
-int nsexes,stage,sex,njuvs,nj,nmales,nfemales;
-Cell *pCell;
-indStats ind;
-double expected;
-bool skipbreeding;
-
-//envGradParams grad = paramsGrad->getGradient();
-envStochParams env = paramsStoch->getStoch();
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
-genomeData gen = pSpecies->getGenomeData();
-simView v = paramsSim->getViews();
-
-if (dem.repType == 0) nsexes = 1; else nsexes = 2;
+ // get population size at start of reproduction
+ int ninds = (int)inds.size();
+ if (ninds == 0) return;
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): this=" << this
-//#if RS_CONTAIN
-// << " hab=" << hab
-//#else
-// << " pSpecies=" << pSpecies
-// << " localK=" << localK << " envval=" << envval << " resol=" << resol
-//#endif // RS_CONTAIN
-// << " sstruct.nStages=" << sstruct.nStages << " nsexes=" << nsexes << " ninds=" << ninds
-// << endl;
-#endif
+ int nsexes, stage, sex, njuvs, nj, nmales, nfemales;
+ Cell* pCell;
+ indStats ind;
+ double expected;
+ bool skipbreeding;
-// set up local copy of species fecundity table
-float fec[NSTAGES][NSEXES];
-for (int stg = 0; stg < sstruct.nStages; stg++) {
- for (int sex = 0; sex < nsexes; sex++) {
- if (dem.stageStruct) {
- if (dem.repType == 1) { // simple sexual model
- // both sexes use fecundity recorded for females
- fec[stg][sex] = pSpecies->getFec(stg,0);
+ envStochParams env = paramsStoch->getStoch();
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
+ genomeData gen = pSpecies->getGenomeData();
+ simView v = paramsSim->getViews();
+
+ if (dem.repType == 0) nsexes = 1; else nsexes = 2;
+
+ // set up local copy of species fecundity table
+ float fec[NSTAGES][NSEXES];
+ for (int stg = 0; stg < sstruct.nStages; stg++) {
+ for (int sex = 0; sex < nsexes; sex++) {
+ if (dem.stageStruct) {
+ if (dem.repType == 1) { // simple sexual model
+ // both sexes use fecundity recorded for females
+ fec[stg][sex] = pSpecies->getFec(stg, 0);
+ }
+ else fec[stg][sex] = pSpecies->getFec(stg, sex);
+ }
+ else { // non-structured population
+ if (stg == 1) fec[stg][sex] = dem.lambda; // adults
+ else fec[stg][sex] = 0.0; // juveniles
}
- else
- fec[stg][sex] = pSpecies->getFec(stg,sex);
-// if (sex == 0 && fec[stg][sex] > dem.lambda) dem.lambda = fec[stg][sex];
- }
- else { // non-structured population
- if (stg == 1) fec[stg][sex] = dem.lambda; // adults
- else fec[stg][sex] = 0.0; // juveniles
}
-#if RSDEBUG
-//if (ninds > 0) {
-//DEBUGLOG << "Population::reproduction(): fec[" << stg << "][" << sex << "] = " << fec[stg][sex]
-// << endl;
-//}
-#endif
}
-}
-if (dem.stageStruct) {
-#if RSDEBUG
-//if (ninds > 0) {
-// DEBUGLOG << "Population::reproduction(): ninds=" << ninds << " localK=" << localK
-// << " effect of density dependence:" << endl;
-//}
-#endif
- // apply environmental effects and density dependence
- // to all non-zero female non-juvenile stages
- for (int stg = 1; stg < nStages; stg++) {
- if (fec[stg][0] > 0.0) {
- // apply any effect of environmental gradient and/or stochasticty
- fec[stg][0] *= envval;
- if (env.stoch && !env.inK) {
- // fecundity (at low density) is constrained to lie between limits specified
- // for the species
- float limit;
- limit = pSpecies->getMinMax(0);
- if (fec[stg][0] < limit) fec[stg][0] = limit;
- limit = pSpecies->getMinMax(1);
- if (fec[stg][0] > limit) fec[stg][0] = limit;
- }
- if (sstruct.fecDens) { // apply density dependence
- float effect = 0.0;
- if (sstruct.fecStageDens) { // stage-specific density dependence
- // NOTE: matrix entries represent effect of ROW on COLUMN
- // AND males precede females
- float weight = 0.0;
- for (int effstg = 0; effstg < nStages; effstg++) {
- for (int effsex = 0; effsex < nSexes; effsex++) {
- if (dem.repType == 2) {
- if (effsex == 0) weight = pSpecies->getDDwtFec(2*stg+1,2*effstg+1);
- else weight = pSpecies->getDDwtFec(2*stg+1,2*effstg);
- }
- else {
- weight = pSpecies->getDDwtFec(stg,effstg);
+ if (dem.stageStruct) {
+ // apply environmental effects and density dependence
+ // to all non-zero female non-juvenile stages
+ for (int stg = 1; stg < nStages; stg++) {
+ if (fec[stg][0] > 0.0) {
+ // apply any effect of environmental gradient and/or stochasticty
+ fec[stg][0] *= envval;
+ if (env.stoch && !env.inK) {
+ // fecundity (at low density) is constrained to lie between limits specified
+ // for the species
+ float limit;
+ limit = pSpecies->getMinMax(0);
+ if (fec[stg][0] < limit) fec[stg][0] = limit;
+ limit = pSpecies->getMinMax(1);
+ if (fec[stg][0] > limit) fec[stg][0] = limit;
+ }
+ if (sstruct.fecDens) { // apply density dependence
+ float effect = 0.0;
+ if (sstruct.fecStageDens) { // stage-specific density dependence
+ // NOTE: matrix entries represent effect of ROW on COLUMN
+ // AND males precede females
+ float weight = 0.0;
+ for (int effstg = 0; effstg < nStages; effstg++) {
+ for (int effsex = 0; effsex < nSexes; effsex++) {
+ if (dem.repType == 2) {
+ if (effsex == 0) weight = pSpecies->getDDwtFec(2 * stg + 1, 2 * effstg + 1);
+ else weight = pSpecies->getDDwtFec(2 * stg + 1, 2 * effstg);
+ }
+ else {
+ weight = pSpecies->getDDwtFec(stg, effstg);
+ }
+ effect += (float)nInds[effstg][effsex] * weight;
}
- effect += (float)nInds[effstg][effsex] * weight;
-#if RSDEBUG
-//if (ninds > 0) {
-// DEBUGLOG << " effstg=" << effstg << " effsex=" << effsex << " nInds=" << nInds[effstg][effsex];
-// DEBUGLOG << " weight=" << weight << " effect=" << effect
-// << endl;
-//}
-#endif
}
}
+ else // not stage-specific
+ effect = (float)totalPop();
+ if (localK > 0.0) fec[stg][0] *= exp(-effect / localK);
}
- else // not stage-specific
- effect = (float)totalPop();
- if (localK > 0.0) fec[stg][0] *= exp(-effect/localK);
-#if RSDEBUG
-//if (ninds > 0) {
-// DEBUGLOG << " eff popn=" << effect << " exponential=" << exp(-effect/localK);
-// DEBUGLOG << " fec[" << stg << "][0]=" << fec[stg][0]
-// << endl;
-//}
-#endif
}
}
}
-}
-else { // non-structured - set fecundity for adult females only
- // apply any effect of environmental gradient and/or stochasticty
- fec[1][0] *= envval;
- if (env.stoch && !env.inK) {
- // fecundity (at low density) is constrained to lie between limits specified
- // for the species
- float limit;
- limit = pSpecies->getMinMax(0);
- if (fec[1][0] < limit) fec[1][0] = limit;
- limit = pSpecies->getMinMax(1);
- if (fec[1][0] > limit) fec[1][0] = limit;
- }
- // apply density dependence
- if (localK > 0.0) {
-//#if GOBYMODEL
-// ddeffect[1] = (float)ninds/localK;
-//#else
- if (dem.repType == 1 || dem.repType == 2) { // sexual model
- // apply factor of 2 (as in manual, eqn. 6)
- fec[1][0] *= 2.0;
+ else { // non-structured - set fecundity for adult females only
+ // apply any effect of environmental gradient and/or stochasticty
+ fec[1][0] *= envval;
+ if (env.stoch && !env.inK) {
+ // fecundity (at low density) is constrained to lie between limits specified
+ // for the species
+ float limit;
+ limit = pSpecies->getMinMax(0);
+ if (fec[1][0] < limit) fec[1][0] = limit;
+ limit = pSpecies->getMinMax(1);
+ if (fec[1][0] > limit) fec[1][0] = limit;
}
- fec[1][0] /= (1.0f + fabs(dem.lambda-1.0f)*pow(((float)ninds/localK),dem.bc));
-//#endif
- }
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): dem.lambda=" << dem.lambda << " ninds=" << ninds
-// << " localK=" << localK << " dem.bc=" << dem.bc << " fec[1][0]=" << fec[1][0]
-// << endl;
-#endif
-}
-
-double propBreed;
-Individual *father;
-std::vector fathers;
-
-switch (dem.repType) {
-
-case 0: // asexual model
- for (int i = 0; i < ninds; i++) {
- stage = inds[i]->breedingFem();
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction():"
-// << " i=" << i << " ID=" << inds[i]->getId() << " stage=" << stage
-// << endl;
-#endif
- if (stage > 0) { // female of breeding age
- if (dem.stageStruct) {
- // determine whether she must miss current breeding attempt
- ind = inds[i]->getStats();
- if (ind.fallow >= sstruct.repInterval) {
- if (pRandom->Bernoulli(sstruct.probRep)) skipbreeding = false;
- else skipbreeding = true;
- }
- else skipbreeding = true; // cannot breed this time
- }
- else skipbreeding = false; // not structured - always breed
- if (skipbreeding) {
- inds[i]->incFallow();
- }
- else { // attempt to breed
- inds[i]->resetFallow();
- expected = fec[stage][0];
- if (expected <= 0.0) njuvs = 0;
- else njuvs = pRandom->Poisson(expected);
- nj = (int)juvs.size();
- pCell = pPatch->getRandomCell();
- for (int j = 0; j < njuvs; j++) {
-#if RSDEBUG
- // NOTE: CURRENTLY SETTING ALL INDIVIDUALS TO RECORD NO. OF STEPS ...
- juvs.push_back(new Individual(pCell,pPatch,0,0,0,0.0,true,trfr.moveType));
-#else
- juvs.push_back(new Individual(pCell,pPatch,0,0,0,0.0,trfr.moveModel,trfr.moveType));
-#endif
- nInds[0][0]++;
- if (emig.indVar || trfr.indVar || sett.indVar || gen.neutralMarkers)
- {
- // juv inherits genome from parent (mother)
- juvs[nj+j]->setGenes(pSpecies,inds[i],0,resol);
- }
- }
+ // apply density dependence
+ if (localK > 0.0) {
+ if (dem.repType == 1 || dem.repType == 2) { // sexual model
+ // apply factor of 2 (as in manual, eqn. 6)
+ fec[1][0] *= 2.0;
}
+ fec[1][0] /= (1.0f + fabs(dem.lambda - 1.0f) * pow(((float)ninds / localK), dem.bc));
}
}
- break;
-case 1: // simple sexual model
-case 2: // complex sexual model
- // count breeding females and males
- // add breeding males to list of potential fathers
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): case 1:"
-// << " fec[1][0]=" << fec[1][0] << " fec[1][1]=" << fec[1][1]
-// << endl;
-#endif
- nfemales = nmales = 0;
- for (int i = 0; i < ninds; i++) {
- ind = inds[i]->getStats();
- if (ind.sex == 0 && fec[ind.stage][0] > 0.0) nfemales++;
- if (ind.sex == 1 && fec[ind.stage][1] > 0.0) {
- fathers.push_back(inds[i]);
- nmales++;
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): i=" << i << " nmales=" << nmales
-// << " inds[i]=" << inds[i] << endl;
-#endif
- }
- }
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): breeding nfemales=" << nfemales
-// << " breeding nmales=" << nmales << endl;
-#endif
- if (nfemales > 0 && nmales > 0)
- { // population can breed
- if (dem.repType == 2) { // complex sexual model
- // calculate proportion of eligible females which breed
- propBreed = (2.0*dem.harem*nmales)/(nfemales+dem.harem*nmales);
- if (propBreed > 1.0) propBreed = 1.0;
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): harem=" << dem.harem
-// << " nfemales=" << nfemales << " nmales=" << nmales << " propBreed=" << propBreed
-// << endl;
-#endif
- }
- else propBreed = 1.0;
+ double propBreed;
+ Individual* father;
+ std::vector fathers;
+
+ switch (dem.repType) {
+
+ case 0: // asexual model
for (int i = 0; i < ninds; i++) {
stage = inds[i]->breedingFem();
- if (stage > 0 && fec[stage][0] > 0.0) { // (potential) breeding female
+ if (stage > 0) { // female of breeding age
if (dem.stageStruct) {
// determine whether she must miss current breeding attempt
ind = inds[i]->getStats();
@@ -704,685 +481,568 @@ case 2: // complex sexual model
}
else { // attempt to breed
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 (pRandom->Bernoulli(propBreed)) {
- expected = fec[stage][0]; // breeds
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): THIS LINE SHOULD NOT APPEAR FOR GOBY MODEL"
-// << " expected=" << expected
-// << endl;
-#endif
- }
- else expected = 0.0; // fails to breed
+ expected = fec[stage][0];
if (expected <= 0.0) njuvs = 0;
else njuvs = pRandom->Poisson(expected);
+ nj = (int)juvs.size();
+ pCell = pPatch->getRandomCell();
+ for (int j = 0; j < njuvs; j++) {
#if RSDEBUG
-//DEBUGLOG << "Population::reproduction():"
-// << " i " << i << " ID=" << inds[i]->getId() << " stage=" << stage
-// << " expected=" << expected << " njuvs=" << njuvs << endl;
+ // NOTE: CURRENTLY SETTING ALL INDIVIDUALS TO RECORD NO. OF STEPS ...
+ juvs.push_back(new Individual(pCell, pPatch, 0, 0, 0, 0.0, true, trfr.moveType));
+#else
+ juvs.push_back(new Individual(pCell, pPatch, 0, 0, 0, 0.0, trfr.moveModel, trfr.moveType));
#endif
- if (njuvs > 0)
- {
- nj = (int)juvs.size();
+ nInds[0][0]++;
+ if (emig.indVar || trfr.indVar || sett.indVar || gen.neutralMarkers)
+ {
+ // juv inherits genome from parent (mother)
+ juvs[nj + j]->setGenes(pSpecies, inds[i], 0, resol);
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case 1: // simple sexual model
+ case 2: // complex sexual model
+ // count breeding females and males
+ // add breeding males to list of potential fathers
+
+ nfemales = nmales = 0;
+ for (int i = 0; i < ninds; i++) {
+ ind = inds[i]->getStats();
+ if (ind.sex == 0 && fec[ind.stage][0] > 0.0) nfemales++;
+ if (ind.sex == 1 && fec[ind.stage][1] > 0.0) {
+ fathers.push_back(inds[i]);
+ nmales++;
+ }
+ }
+ if (nfemales > 0 && nmales > 0)
+ { // population can breed
+ if (dem.repType == 2) { // complex sexual model
+ // calculate proportion of eligible females which breed
+ propBreed = (2.0 * dem.harem * nmales) / (nfemales + dem.harem * nmales);
+ if (propBreed > 1.0) propBreed = 1.0;
+ }
+ else propBreed = 1.0;
+ for (int i = 0; i < ninds; i++) {
+ stage = inds[i]->breedingFem();
+ if (stage > 0 && fec[stage][0] > 0.0) { // (potential) breeding female
+ if (dem.stageStruct) {
+ // determine whether she must miss current breeding attempt
+ ind = inds[i]->getStats();
+ if (ind.fallow >= sstruct.repInterval) {
+ if (pRandom->Bernoulli(sstruct.probRep)) skipbreeding = false;
+ else skipbreeding = true;
+ }
+ else skipbreeding = true; // cannot breed this time
+ }
+ else skipbreeding = false; // not structured - always breed
+ if (skipbreeding) {
+ inds[i]->incFallow();
+ }
+ else { // attempt to breed
+ 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 (pRandom->Bernoulli(propBreed)) {
+ expected = fec[stage][0]; // breeds
+ }
+ else expected = 0.0; // fails to breed
+ if (expected <= 0.0) njuvs = 0;
+ else njuvs = pRandom->Poisson(expected);
+ if (njuvs > 0)
+ {
+ nj = (int)juvs.size();
// select father at random from breeding males ...
int rrr = 0;
- if (nmales > 1) rrr = pRandom->IRandom(0,nmales-1);
+ if (nmales > 1) rrr = pRandom->IRandom(0, nmales - 1);
father = fathers[rrr];
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): i = " << i << " rrr = " << rrr
-// << " father = " << father << endl;
-#endif
pCell = pPatch->getRandomCell();
for (int j = 0; j < njuvs; j++) {
#if RSDEBUG
// NOTE: CURRENTLY SETTING ALL INDIVIDUALS TO RECORD NO. OF STEPS ...
- juvs.push_back(new Individual(pCell,pPatch,0,0,0,dem.propMales,true,trfr.moveType));
+ juvs.push_back(new Individual(pCell, pPatch, 0, 0, 0, dem.propMales, true, trfr.moveType));
#else
- juvs.push_back(new Individual(pCell,pPatch,0,0,0,dem.propMales,trfr.moveModel,trfr.moveType));
+ juvs.push_back(new Individual(pCell, pPatch, 0, 0, 0, dem.propMales, trfr.moveModel, trfr.moveType));
#endif
- sex = juvs[nj+j]->getSex();
+ sex = juvs[nj + j]->getSex();
nInds[0][sex]++;
if (emig.indVar || trfr.indVar || sett.indVar || gen.neutralMarkers)
{
// juv inherits genome from parents
- juvs[nj+j]->setGenes(pSpecies,inds[i],father,resol);
+ juvs[nj + j]->setGenes(pSpecies, inds[i], father, resol);
}
}
+ }
}
}
}
}
- }
- fathers.clear();
- break;
-
-} // end of switch (dem.repType)
+ fathers.clear();
+ break;
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): before reprodn. " << " inds.size() = " << inds.size()
-// << endl;
-#endif
+ } // end of switch (dem.repType)
// THIS MAY NOT BE CORRECT FOR MULTIPLE SPECIES IF THERE IS SOME FORM OF
// CROSS-SPECIES DENSITY-DEPENDENT FECUNDITY
-
-#if RSDEBUG
-//DEBUGLOG << "Population::reproduction(): after reprodn. this = " << this
-// << " juvs.size() = " << juvs.size() << " inds.size() = " << inds.size()
-// << endl;
-#endif
-
}
// Following reproduction of ALL species, add juveniles to the population prior to dispersal
void Population::fledge(void)
{
-#if RSDEBUG
-//DEBUGLOG << "Population::fledge(): this=" << this
-// << " ninds=" << (int)inds.size()
-// << " njuvs=" << (int)juvs.size()
-// << endl;
-#endif
-demogrParams dem = pSpecies->getDemogr();
+ demogrParams dem = pSpecies->getDemogr();
-if (dem.stageStruct) { // juveniles are added to the individuals vector
- inds.insert(inds.end(),juvs.begin(),juvs.end());
-// nInds += nJuvs; nJuvs = 0;
-}
-else { // all adults die and juveniles replace adults
- int ninds = (int)inds.size();
- for (int i = 0; i < ninds; i++) {
- delete inds[i];
+ if (dem.stageStruct) { // juveniles are added to the individuals vector
+ inds.insert(inds.end(), juvs.begin(), juvs.end());
}
- inds.clear();
- for (int sex = 0; sex < nSexes; sex++) {
- nInds[1][sex] = 0; // set count of adults to zero
+ else { // all adults die and juveniles replace adults
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ delete inds[i];
+ }
+ inds.clear();
+ for (int sex = 0; sex < nSexes; sex++) {
+ nInds[1][sex] = 0; // set count of adults to zero
+ }
+ inds = juvs;
}
- inds = juvs;
-}
-juvs.clear();
+ juvs.clear();
}
// Determine which individuals will disperse
void Population::emigration(float localK)
{
-int nsexes;
-double disp,Pdisp,NK;
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
-emigRules emig = pSpecies->getEmig();
-emigTraits eparams;
-trfrRules trfr = pSpecies->getTrfr();
-indStats ind;
-#if RSDEBUG
-//DEBUGLOG << "Population::emigration(): this=" << this
-// << " nStages=" << sstruct.nStages
-//// << " emig.emigGenes[0]=" << emig.emigGenes[0]
-//// << " emig.emigGenes[1]=" << emig.emigGenes[1]
-// << endl;
-#endif
+ int nsexes;
+ double disp, Pdisp, NK;
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
+ emigRules emig = pSpecies->getEmig();
+ emigTraits eparams;
+ trfrRules trfr = pSpecies->getTrfr();
+ indStats ind;
// to avoid division by zero, assume carrying capacity is at least one individual
// localK can be zero if there is a moving gradient or stochasticity in K
-if (localK < 1.0) localK = 1.0;
-NK = (float)totalPop() / localK;
+ if (localK < 1.0) localK = 1.0;
+ NK = (float)totalPop() / localK;
-int ninds = (int)inds.size();
+ int ninds = (int)inds.size();
-// set up local copy of emigration probability table
-// used when there is no individual variability
-// NB - IT IS DOUBTFUL THIS CONTRIBUTES ANY SUBSTANTIAL TIME SAVING
-if (dem.repType == 0) nsexes = 1; else nsexes = 2;
-double Pemig[NSTAGES][NSEXES];
+ // set up local copy of emigration probability table
+ // used when there is no individual variability
+ // NB - IT IS DOUBTFUL THIS CONTRIBUTES ANY SUBSTANTIAL TIME SAVING
+ if (dem.repType == 0) nsexes = 1; else nsexes = 2;
+ double Pemig[NSTAGES][NSEXES];
-for (int stg = 0; stg < sstruct.nStages; stg++) {
- for (int sex = 0; sex < nsexes; sex++) {
- if (emig.indVar) Pemig[stg][sex] = 0.0;
- else {
- if (emig.densDep) {
- if (emig.sexDep) {
- if (emig.stgDep) {
- eparams = pSpecies->getEmigTraits(stg,sex);
+ for (int stg = 0; stg < sstruct.nStages; stg++) {
+ for (int sex = 0; sex < nsexes; sex++) {
+ if (emig.indVar) Pemig[stg][sex] = 0.0;
+ else {
+ if (emig.densDep) {
+ if (emig.sexDep) {
+ if (emig.stgDep) {
+ eparams = pSpecies->getEmigTraits(stg, sex);
+ }
+ else {
+ eparams = pSpecies->getEmigTraits(0, sex);
+ }
}
- else {
- eparams = pSpecies->getEmigTraits(0,sex);
+ else { // !emig.sexDep
+ if (emig.stgDep) {
+ eparams = pSpecies->getEmigTraits(stg, 0);
+ }
+ else {
+ eparams = pSpecies->getEmigTraits(0, 0);
+ }
}
- }
- else { // !emig.sexDep
- if (emig.stgDep) {
- eparams = pSpecies->getEmigTraits(stg,0);
- }
- else {
- eparams = pSpecies->getEmigTraits(0,0);
- }
- }
- Pemig[stg][sex] = eparams.d0/(1.0+exp(-(NK - eparams.beta)*eparams.alpha));
-#if RSDEBUG
-//if (ppLand.patch_model) {
-// DEBUGLOG << "Population::emigration(): stg=" << stg << " sex=" << sex
-// << " totalPop=" << totalPop() << " localK=" << localK << " NK=" << NK
-// << " d0=" << eparams.d0 << " beta=" << eparams.beta << " alpha=" << eparams.alpha
-// << " Pemig[stg][sex]=" << Pemig[stg][sex]
-// << endl;
-//}
-#endif
- }
- else { // density-independent
- if (emig.sexDep) {
- if (emig.stgDep) {
- Pemig[stg][sex] = pSpecies->getEmigD0(stg,sex);
- }
- else { // !emig.stgDep
- Pemig[stg][sex] = pSpecies->getEmigD0(0,sex);
- }
- }
- else { // !emig.sexDep
- if (emig.stgDep) {
- Pemig[stg][sex] = pSpecies->getEmigD0(stg,0);
- }
- else { // !emig.stgDep
- Pemig[stg][sex] = pSpecies->getEmigD0(0,0);
- }
- }
- }
- } // end of !emig.indVar
-#if RSDEBUG
-//DEBUGLOG << "Population::emigration(): this=" << (int)this
-// << " totalPop()=" << totalPop()
-// << " Pemig[" << stg << "][" << sex << "]="<< Pemig[stg][sex] << endl;
-#endif
- }
-}
-
-//#if GROUPDISP
-//bool newgroup = true;
-//int currentsize = 0;
-//#endif // GROUPDISP
-
-//#if PARTMIGRN
-//double cumprop[7];
-//cumprop[0] = 0.0;
-//for (int i = 1; i < 7; i++) {
-// cumprop[i] = cumprop[i-1] + pSpecies->getPropDispMigrn(i);
-//#if RSDEBUG
-//DEBUGLOG << "Population::emigration(): i=" << i
-// << " cumprop[i]=" << cumprop[i]
-// << endl;
-//#endif
-//}
-//#endif // PARTMIGRN
-//
-
-for (int i = 0; i < ninds; i++) {
- ind = inds[i]->getStats();
- if (ind.status < 1)
- {
- if (emig.indVar) { // individual variability in emigration
- if (dem.stageStruct && ind.stage != emig.emigStage) {
- // emigration may not occur
- Pdisp = 0.0;
- }
- else { // non-structured or individual is in emigration stage
- eparams = inds[i]->getEmigTraits();
- if (emig.densDep) { // density-dependent
- NK = (float)totalPop() / localK;
- Pdisp = eparams.d0/(1.0+exp(-(NK - eparams.beta)*eparams.alpha));
+ Pemig[stg][sex] = eparams.d0 / (1.0 + exp(-(NK - eparams.beta) * eparams.alpha));
}
else { // density-independent
if (emig.sexDep) {
- Pdisp = Pemig[0][ind.sex] + eparams.d0;
+ if (emig.stgDep) {
+ Pemig[stg][sex] = pSpecies->getEmigD0(stg, sex);
+ }
+ else { // !emig.stgDep
+ Pemig[stg][sex] = pSpecies->getEmigD0(0, sex);
+ }
}
- else {
- Pdisp = Pemig[0][0] + eparams.d0;
+ else { // !emig.sexDep
+ if (emig.stgDep) {
+ Pemig[stg][sex] = pSpecies->getEmigD0(stg, 0);
+ }
+ else { // !emig.stgDep
+ Pemig[stg][sex] = pSpecies->getEmigD0(0, 0);
+ }
}
}
- }
- } // end of individual variability
- else { // no individual variability
+ } // end of !emig.indVar
+ }
+ }
- if (emig.densDep) {
- if (emig.sexDep) {
- if (emig.stgDep) {
- Pdisp = Pemig[ind.stage][ind.sex];
- }
- else {
- Pdisp = Pemig[0][ind.sex];
- }
+ for (int i = 0; i < ninds; i++) {
+ ind = inds[i]->getStats();
+ if (ind.status < 1)
+ {
+ if (emig.indVar) { // individual variability in emigration
+ if (dem.stageStruct && ind.stage != emig.emigStage) {
+ // emigration may not occur
+ Pdisp = 0.0;
}
- else { // !emig.sexDep
- if (emig.stgDep) {
- Pdisp = Pemig[ind.stage][0];
+ else { // non-structured or individual is in emigration stage
+ eparams = inds[i]->getEmigTraits();
+ if (emig.densDep) { // density-dependent
+ NK = (float)totalPop() / localK;
+ Pdisp = eparams.d0 / (1.0 + exp(-(NK - eparams.beta) * eparams.alpha));
}
- else {
- Pdisp = Pemig[0][0];
+ else { // density-independent
+ if (emig.sexDep) {
+ Pdisp = Pemig[0][ind.sex] + eparams.d0;
+ }
+ else {
+ Pdisp = Pemig[0][0] + eparams.d0;
+ }
}
}
-#if RSDEBUG
-//if (ppLand.patch_model) {
-// DEBUGLOG << "Population::emigration(): i=" << i << " sex=" << ind.sex << " stage=" << ind.stage
-// << " totalPop=" << totalPop() << " localK=" << localK << " NK=" << NK
-// << " Pdisp=" << Pdisp
-// << endl;
-//}
-#endif
- }
- else { // density-independent
- if (emig.sexDep) {
- if (emig.stgDep) {
- Pdisp = Pemig[ind.stage][ind.sex];
+ } // end of individual variability
+ else { // no individual variability
+
+ if (emig.densDep) {
+ if (emig.sexDep) {
+ if (emig.stgDep) {
+ Pdisp = Pemig[ind.stage][ind.sex];
+ }
+ else {
+ Pdisp = Pemig[0][ind.sex];
+ }
}
- else { // !emig.stgDep
- Pdisp = Pemig[0][ind.sex];
+ else { // !emig.sexDep
+ if (emig.stgDep) {
+ Pdisp = Pemig[ind.stage][0];
+ }
+ else {
+ Pdisp = Pemig[0][0];
+ }
}
}
- else { // !emig.sexDep
- if (emig.stgDep) {
- Pdisp = Pemig[ind.stage][0];
+ else { // density-independent
+ if (emig.sexDep) {
+ if (emig.stgDep) {
+ Pdisp = Pemig[ind.stage][ind.sex];
+ }
+ else { // !emig.stgDep
+ Pdisp = Pemig[0][ind.sex];
+ }
}
- else { // !emig.stgDep
- Pdisp = Pemig[0][0];
+ else { // !emig.sexDep
+ if (emig.stgDep) {
+ Pdisp = Pemig[ind.stage][0];
+ }
+ else { // !emig.stgDep
+ Pdisp = Pemig[0][0];
+ }
}
}
-//#if GROUPDISP
-// if (emig.groupdisp) {
-// if (Pdisp > 0) {
-//
-// }
-//
-// }
-//#endif // GROUPDISP
- }
-
- } // end of no individual variability
- disp = pRandom->Bernoulli(Pdisp);
-#if RSDEBUG
-//DEBUGLOG << "Population::emigration(): i=" << i << " sex=" << ind.sex << " stage=" << ind.stage
-// << " Pdisp=" << Pdisp << " disp=" << disp << endl;
-#endif
+ } // end of no individual variability
- if (disp == 1) { // emigrant
- inds[i]->setStatus(1);
- }
- } // end of if (ind.status < 1) condition
-} // end of for loop
+ disp = pRandom->Bernoulli(Pdisp);
+
+ if (disp == 1) { // emigrant
+ inds[i]->setStatus(1);
+ }
+ } // end of if (ind.status < 1) condition
+ } // end of for loop
}
// All individuals emigrate after patch destruction
void Population::allEmigrate(void) {
-int ninds = (int)inds.size();
-for (int i = 0; i < ninds; i++) {
- inds[i]->setStatus(1);
-}
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ inds[i]->setStatus(1);
+ }
}
// If an Individual has been identified as an emigrant, remove it from the Population
disperser Population::extractDisperser(int ix) {
-disperser d;
-indStats ind = inds[ix]->getStats();
-#if RSDEBUG
-//if (ind.status > 0) {
-// DEBUGLOG << "Population::extractDisperser(): ix = " << ix << " inds[ix] = " << inds[ix]
-// << " indId = " << inds[ix]->getId() << " ind.status = " << ind.status
-// << endl;
-//}
-#endif
-if (ind.status == 1) { // emigrant
- d.pInd = inds[ix]; d.yes = true;
- inds[ix] = 0;
- nInds[ind.stage][ind.sex]--;
-}
-else {
- d.pInd = NULL; d.yes = false;
-}
-return d;
+ disperser d;
+ indStats ind = inds[ix]->getStats();
+ if (ind.status == 1) { // emigrant
+ d.pInd = inds[ix]; d.yes = true;
+ inds[ix] = 0;
+ nInds[ind.stage][ind.sex]--;
+ }
+ else {
+ d.pInd = NULL; d.yes = false;
+ }
+ return d;
}
// For an individual identified as being in the matrix population:
// if it is a settler, return its new location and remove it from the current population
// otherwise, leave it in the matrix population for possible reporting before deletion
disperser Population::extractSettler(int ix) {
-disperser d;
-Cell* pCell;
-//Patch* pPatch;
+ disperser d;
+ Cell* pCell;
-indStats ind = inds[ix]->getStats();
+ indStats ind = inds[ix]->getStats();
-pCell = inds[ix]->getLocn(1);
-#if RSDEBUG
-//DEBUGLOG << "Population::extractSettler(): ix = " << ix << " inds[ix] = " << inds[ix]
-// << " indId = " << inds[ix]->getId() << " ind.status = " << ind.status << endl;
-#endif
-d.pInd = inds[ix]; d.pCell = pCell; d.yes = false;
-if (ind.status == 4 || ind.status == 5) { // settled
- d.yes = true;
- inds[ix] = 0;
- nInds[ind.stage][ind.sex]--;
-}
-return d;
+ pCell = inds[ix]->getLocn(1);
+ d.pInd = inds[ix]; d.pCell = pCell; d.yes = false;
+ if (ind.status == 4 || ind.status == 5) { // settled
+ d.yes = true;
+ inds[ix] = 0;
+ nInds[ind.stage][ind.sex]--;
+ }
+ return d;
}
// Add a specified individual to the new/current dispersal group
// Add a specified individual to the population
-void Population::recruit(Individual *pInd) {
-inds.push_back(pInd);
-indStats ind = pInd->getStats();
-nInds[ind.stage][ind.sex]++;
-#if RSDEBUG
-//DEBUGLOG << "Population::recruit(): patchNum=" << pPatch->getPatchNum()
-// << " indId=" << pInd->getId()
-// << " nInds[" << ind.stage << "][" << ind.sex << "]=" << nInds[ind.stage][ind.sex]
-// << endl;
-#endif
+void Population::recruit(Individual* pInd) {
+ inds.push_back(pInd);
+ indStats ind = pInd->getStats();
+ nInds[ind.stage][ind.sex]++;
}
//---------------------------------------------------------------------------
// Transfer is run for populations in the matrix only
#if RS_RCPP // included also SEASONAL
-int Population::transfer(Landscape *pLandscape,short landIx,short nextseason)
+int Population::transfer(Landscape* pLandscape, short landIx, short nextseason)
#else
-int Population::transfer(Landscape *pLandscape,short landIx)
+int Population::transfer(Landscape* pLandscape, short landIx)
#endif
{
-int ndispersers = 0;
-int disperser;
-short othersex;
-bool mateOK,densdepOK;
-intptr patch,popn;
-int patchnum;
-double localK,popsize,settprob;
-Patch *pPatch = 0;
-Cell *pCell = 0;
-indStats ind;
-Population *pNewPopn = 0;
-locn newloc,nbrloc;
-
-landData ppLand = pLandscape->getLandData();
-short reptype = pSpecies->getRepType();
-trfrRules trfr = pSpecies->getTrfr();
-settleType settletype = pSpecies->getSettle();
-settleRules sett;
-settleTraits settDD;
-settlePatch settle;
-simParams sim = paramsSim->getSim();
-
-// each individual takes one step
-// for dispersal by kernel, this should be the only step taken
-int ninds = (int)inds.size();
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 0000: ninds = " << ninds
-// << " ndispersers = " << ndispersers << endl;
-#endif
-for (int i = 0; i < ninds; i++) {
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 1111: i = " << i << " ID = " << inds[i]->getId()
-// << endl;
-#endif
- if (trfr.moveModel) {
-#if RSDEBUG
-//pCell = inds[i]->getLocn(1);
-//locn loc = pCell->getLocn();
-//DEBUGLOG << "Population::transfer(): 1112: i = " << i << " ID = " << inds[i]->getId()
-// << " before:" << " x = " << loc.x << " y = " << loc.y
-// << endl;
-#endif
- disperser = inds[i]->moveStep(pLandscape,pSpecies,landIx,sim.absorbing);
-#if RSDEBUG
-//pCell = inds[i]->getLocn(1);
-//newloc = pCell->getLocn();
-//DEBUGLOG << "Population::transfer(): 1113: i = " << i << " ID = " << inds[i]->getId()
-// << " after: " << " x = " << newloc.x << " y = " << newloc.y
-// << endl;
-#endif
- }
- else {
- disperser = inds[i]->moveKernel(pLandscape,pSpecies,reptype,sim.absorbing);
- }
- ndispersers += disperser;
- if (disperser) {
- if (reptype > 0)
- { // sexual species - record as potential settler in new patch
- if (inds[i]->getStatus() == 2)
- { // disperser has found a patch
- pCell = inds[i]->getLocn(1);
- patch = pCell->getPatch();
- if (patch != 0) { // not no-data area
- pPatch = (Patch*)patch;
- pPatch->incrPossSettler(pSpecies,inds[i]->getSex());
+ int ndispersers = 0;
+ int disperser;
+ short othersex;
+ bool mateOK, densdepOK;
+ intptr patch, popn;
+ int patchnum;
+ double localK, popsize, settprob;
+ Patch* pPatch = 0;
+ Cell* pCell = 0;
+ indStats ind;
+ Population* pNewPopn = 0;
+ locn newloc, nbrloc;
+
+ landData ppLand = pLandscape->getLandData();
+ short reptype = pSpecies->getRepType();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType settletype = pSpecies->getSettle();
+ settleRules sett;
+ settleTraits settDD;
+ settlePatch settle;
+ simParams sim = paramsSim->getSim();
+
+ // each individual takes one step
+ // for dispersal by kernel, this should be the only step taken
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ if (trfr.moveModel) {
+ disperser = inds[i]->moveStep(pLandscape, pSpecies, landIx, sim.absorbing);
+ }
+ else {
+ disperser = inds[i]->moveKernel(pLandscape, pSpecies, reptype, sim.absorbing);
+ }
+ ndispersers += disperser;
+ if (disperser) {
+ if (reptype > 0)
+ { // sexual species - record as potential settler in new patch
+ if (inds[i]->getStatus() == 2)
+ { // disperser has found a patch
+ pCell = inds[i]->getLocn(1);
+ patch = pCell->getPatch();
+ if (patch != 0) { // not no-data area
+ pPatch = (Patch*)patch;
+ pPatch->incrPossSettler(pSpecies, inds[i]->getSex());
+ }
}
}
}
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 5555: ninds=" << ninds
-// << " ndispersers=" << ndispersers << endl;
-#endif
// each individual which has reached a potential patch decides whether to settle
-for (int i = 0; i < ninds; i++) {
- ind = inds[i]->getStats();
- if (ind.sex == 0) othersex = 1; else othersex = 0;
- if (settletype.stgDep) {
- if (settletype.sexDep) sett = pSpecies->getSettRules(ind.stage,ind.sex);
- else sett = pSpecies->getSettRules(ind.stage,0);
- }
- else {
- if (settletype.sexDep) sett = pSpecies->getSettRules(0,ind.sex);
- else sett = pSpecies->getSettRules(0,0);
- }
- if (ind.status == 2)
- { // awaiting settlement
- pCell = inds[i]->getLocn(1);
- if (pCell == 0) {
- // this condition can occur in a patch-based model at the time of a dynamic landscape
- // change when there is a range restriction in place, since a patch can straddle the
- // range restriction and an individual forced to disperse upon patch removal could
- // start its trajectory beyond the boundary of the restrictyed range - such a model is
- // not good practice, but the condition must be handled by killing the individual conceerned
- ind.status = 6;
+ for (int i = 0; i < ninds; i++) {
+ ind = inds[i]->getStats();
+ if (ind.sex == 0) othersex = 1; else othersex = 0;
+ if (settletype.stgDep) {
+ if (settletype.sexDep) sett = pSpecies->getSettRules(ind.stage, ind.sex);
+ else sett = pSpecies->getSettRules(ind.stage, 0);
}
else {
-
-#if RSDEBUG
-//newloc = pCell->getLocn();
-//DEBUGLOG << "Population::transfer(): 6666: i=" << i << " ID=" << inds[i]->getId()
-// << " sex=" << ind.sex << " status=" << ind.status
-// << " pCell=" << pCell << " x=" << newloc.x << " y=" << newloc.y
-// << " findMate=" << sett.findMate
-//// << " wait=" << sett.wait
-//// << " go2nbrLocn=" << sett.go2nbrLocn
-// << endl;
-#endif
-
- mateOK = false;
- if (sett.findMate) {
- // determine whether at least one individual of the opposite sex is present in the
- // new population
- if (matePresent(pCell,othersex)) mateOK = true;
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 7777: othersex=" << othersex
-// << " this=" << this << " pNewPopn=" << pNewPopn << " popsize=" << popsize << " mateOK=" << mateOK
-// << endl;
-#endif
- }
- else { // no requirement to find a mate
- mateOK = true;
+ if (settletype.sexDep) sett = pSpecies->getSettRules(0, ind.sex);
+ else sett = pSpecies->getSettRules(0, 0);
+ }
+ if (ind.status == 2)
+ { // awaiting settlement
+ pCell = inds[i]->getLocn(1);
+ if (pCell == 0) {
+ // this condition can occur in a patch-based model at the time of a dynamic landscape
+ // change when there is a range restriction in place, since a patch can straddle the
+ // range restriction and an individual forced to disperse upon patch removal could
+ // start its trajectory beyond the boundary of the restrictyed range - such a model is
+ // not good practice, but the condition must be handled by killing the individual conceerned
+ ind.status = 6;
}
+ else {
+ mateOK = false;
+ if (sett.findMate) {
+ // determine whether at least one individual of the opposite sex is present in the
+ // new population
+ if (matePresent(pCell, othersex)) mateOK = true;
+ }
+ else { // no requirement to find a mate
+ mateOK = true;
+ }
- densdepOK = false;
- settle = inds[i]->getSettPatch();
- if (sett.densDep)
- {
- patch = pCell->getPatch();
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 8880: i=" << i << " patch=" << patch
-// << endl;
-#endif
- if (patch != 0) { // not no-data area
- pPatch = (Patch*)patch;
- if (settle.settleStatus == 0
- || settle.pSettPatch != pPatch)
- // note: second condition allows for having moved from one patch to another
- // adjacent one
- {
-// inds[i]->resetPathOut(); // reset steps out of patch to zero
- // determine whether settlement occurs in the (new) patch
- localK = (double)pPatch->getK();
- popn = pPatch->getPopn((intptr)pSpecies);
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 8881: i=" << i << " patchNum=" << pPatch->getPatchNum()
-// << " localK=" << localK << " popn=" << popn << endl;
-#endif
- if (popn == 0) { // population has not been set up in the new patch
- popsize = 0.0;
- }
- else {
- pNewPopn = (Population*)popn;
- popsize = (double)pNewPopn->totalPop();
- }
- if (localK > 0.0) {
- // make settlement decision
- if (settletype.indVar) settDD = inds[i]->getSettTraits();
+ densdepOK = false;
+ settle = inds[i]->getSettPatch();
+ if (sett.densDep)
+ {
+ patch = pCell->getPatch();
+ if (patch != 0) { // not no-data area
+ pPatch = (Patch*)patch;
+ if (settle.settleStatus == 0
+ || settle.pSettPatch != pPatch)
+ // note: second condition allows for having moved from one patch to another
+ // adjacent one
+ {
+ // determine whether settlement occurs in the (new) patch
+ localK = (double)pPatch->getK();
+ popn = pPatch->getPopn((intptr)pSpecies);
+ if (popn == 0) { // population has not been set up in the new patch
+ popsize = 0.0;
+ }
+ else {
+ pNewPopn = (Population*)popn;
+ popsize = (double)pNewPopn->totalPop();
+ }
+ if (localK > 0.0) {
+ // make settlement decision
+ if (settletype.indVar) settDD = inds[i]->getSettTraits();
#if RS_RCPP
- else settDD = pSpecies->getSettTraits(ind.stage,ind.sex);
+ else settDD = pSpecies->getSettTraits(ind.stage, ind.sex);
#else
- else {
- if (settletype.sexDep) {
- if (settletype.stgDep)
- settDD = pSpecies->getSettTraits(ind.stage,ind.sex);
- else
- settDD = pSpecies->getSettTraits(0,ind.sex);
- }
else {
- if (settletype.stgDep)
- settDD = pSpecies->getSettTraits(ind.stage,0);
- else
- settDD = pSpecies->getSettTraits(0,0);
+ if (settletype.sexDep) {
+ if (settletype.stgDep)
+ settDD = pSpecies->getSettTraits(ind.stage, ind.sex);
+ else
+ settDD = pSpecies->getSettTraits(0, ind.sex);
+ }
+ else {
+ if (settletype.stgDep)
+ settDD = pSpecies->getSettTraits(ind.stage, 0);
+ else
+ settDD = pSpecies->getSettTraits(0, 0);
+ }
}
- }
#endif //RS_RCPP
- settprob = settDD.s0 /
- (1.0 + exp(-(popsize/localK - (double)settDD.beta) * (double)settDD.alpha));
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 8888: i=" << i << " ind.stage=" << ind.stage
-// << " this=" << this << " pNewPopn=" << pNewPopn << " popsize=" << popsize
-// << " localK=" << localK << " alpha=" << settDD.alpha << " beta=" << settDD.beta
-// << " settprob=" << settprob
-// << endl;
-#endif
- if (pRandom->Bernoulli(settprob)) { // settlement allowed
- densdepOK = true;
- settle.settleStatus = 2;
- }
- else { // settlement procluded
- settle.settleStatus = 1;
+ settprob = settDD.s0 /
+ (1.0 + exp(-(popsize / localK - (double)settDD.beta) * (double)settDD.alpha));
+
+ if (pRandom->Bernoulli(settprob)) { // settlement allowed
+ densdepOK = true;
+ settle.settleStatus = 2;
+ }
+ else { // settlement procluded
+ settle.settleStatus = 1;
+ }
+ settle.pSettPatch = pPatch;
}
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 8889: i=" << i
-// << " settleStatus=" << settle.settleStatus << " mateOK=" << (int)mateOK;
-//if (settle.settleStatus == 2 && mateOK) {
-// DEBUGLOG << " SETTLES -";
-// if (ind.sex == 1) DEBUGLOG << " MALE "; else DEBUGLOG << " FEMALE ";
-//}
-//DEBUGLOG << endl;
-#endif
- settle.pSettPatch = pPatch;
+ inds[i]->setSettPatch(settle);
}
- inds[i]->setSettPatch(settle);
- }
- else {
- if (settle.settleStatus == 2) { // previously allowed to settle
- densdepOK = true;
+ else {
+ if (settle.settleStatus == 2) { // previously allowed to settle
+ densdepOK = true;
+ }
}
}
}
- }
- else { // no density-dependent settlement
- densdepOK = true;
- settle.settleStatus = 2;
- settle.pSettPatch = pPatch;
- inds[i]->setSettPatch(settle);
- }
+ else { // no density-dependent settlement
+ densdepOK = true;
+ settle.settleStatus = 2;
+ settle.pSettPatch = pPatch;
+ inds[i]->setSettPatch(settle);
+ }
- if (mateOK && densdepOK) { // can recruit to patch
- ind.status = 4;
- ndispersers--;
- }
- else { // does not recruit
- if (trfr.moveModel) {
- ind.status = 1; // continue dispersing, unless ...
- // ... maximum steps has been exceeded
- pathSteps steps = inds[i]->getSteps();
- settleSteps settsteps = pSpecies->getSteps(ind.stage,ind.sex);
- if (steps.year >= settsteps.maxStepsYr) {
- ind.status = 3; // waits until next year
- }
- if (steps.total >= settsteps.maxSteps) {
- ind.status = 6; // dies
- }
+ if (mateOK && densdepOK) { // can recruit to patch
+ ind.status = 4;
+ ndispersers--;
}
- else { // dispersal kernel
- if (sett.wait) {
- ind.status = 3; // wait until next dispersal event
+ else { // does not recruit
+ if (trfr.moveModel) {
+ ind.status = 1; // continue dispersing, unless ...
+ // ... maximum steps has been exceeded
+ pathSteps steps = inds[i]->getSteps();
+ settleSteps settsteps = pSpecies->getSteps(ind.stage, ind.sex);
+ if (steps.year >= settsteps.maxStepsYr) {
+ ind.status = 3; // waits until next year
+ }
+ if (steps.total >= settsteps.maxSteps) {
+ ind.status = 6; // dies
+ }
}
- else {
- ind.status = 6; // (dies unless a neighbouring cell is suitable)
+ else { // dispersal kernel
+ if (sett.wait) {
+ ind.status = 3; // wait until next dispersal event
+ }
+ else {
+ ind.status = 6; // (dies unless a neighbouring cell is suitable)
+ }
+ ndispersers--;
}
- ndispersers--;
}
}
- }
- inds[i]->setStatus(ind.status);
- }
+ inds[i]->setStatus(ind.status);
+ }
#if RS_RCPP
- // write each individuals current movement step and status to paths file
- if (trfr.moveModel && sim.outPaths) {
- if(nextseason >= sim.outStartPaths && nextseason%sim.outIntPaths==0) {
+ // write each individuals current movement step and status to paths file
+ if (trfr.moveModel && sim.outPaths) {
+ if (nextseason >= sim.outStartPaths && nextseason % sim.outIntPaths == 0) {
inds[i]->outMovePath(nextseason);
+ }
}
- }
#endif
- if (!trfr.moveModel && sett.go2nbrLocn && (ind.status == 3 || ind.status == 6))
- {
- // for kernel-based transfer only ...
- // determine whether recruitment to a neighbouring cell is possible
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): neighbour cell search: sett.go2nbrLocn = " << sett.go2nbrLocn
-// << " ind.status = " << ind.status
-// << endl;
-#endif
- pCell = inds[i]->getLocn(1);
- newloc = pCell->getLocn();
- vector nbrlist;
- for (int dx = -1; dx < 2; dx++) {
- for (int dy = -1; dy < 2; dy++) {
- if (dx !=0 || dy != 0) { //cell is not the current cell
- nbrloc.x = newloc.x + dx; nbrloc.y = newloc.y + dy;
- if (nbrloc.x >= 0 && nbrloc.x <= ppLand.maxX
- && nbrloc.y >= 0 && nbrloc.y <= ppLand.maxY) { // within landscape
- // add to list of potential neighbouring cells if suitable, etc.
- pCell = pLandscape->findCell(nbrloc.x,nbrloc.y);
- if (pCell != 0) { // not no-data area
- patch = pCell->getPatch();
- if (patch != 0) { // not no-data area
- pPatch = (Patch*)patch;
- patchnum = pPatch->getPatchNum();
- if (patchnum > 0 && pPatch != inds[i]->getNatalPatch())
- { // not the matrix or natal patch
- if (pPatch->getK() > 0.0)
- { // suitable
- if (sett.findMate) {
- if (matePresent(pCell,othersex)) nbrlist.push_back(pCell);
+ if (!trfr.moveModel && sett.go2nbrLocn && (ind.status == 3 || ind.status == 6))
+ {
+ // for kernel-based transfer only ...
+ // determine whether recruitment to a neighbouring cell is possible
+
+ pCell = inds[i]->getLocn(1);
+ newloc = pCell->getLocn();
+ vector | nbrlist;
+ for (int dx = -1; dx < 2; dx++) {
+ for (int dy = -1; dy < 2; dy++) {
+ if (dx != 0 || dy != 0) { //cell is not the current cell
+ nbrloc.x = newloc.x + dx; nbrloc.y = newloc.y + dy;
+ if (nbrloc.x >= 0 && nbrloc.x <= ppLand.maxX
+ && nbrloc.y >= 0 && nbrloc.y <= ppLand.maxY) { // within landscape
+ // add to list of potential neighbouring cells if suitable, etc.
+ pCell = pLandscape->findCell(nbrloc.x, nbrloc.y);
+ if (pCell != 0) { // not no-data area
+ patch = pCell->getPatch();
+ if (patch != 0) { // not no-data area
+ pPatch = (Patch*)patch;
+ patchnum = pPatch->getPatchNum();
+ if (patchnum > 0 && pPatch != inds[i]->getNatalPatch())
+ { // not the matrix or natal patch
+ if (pPatch->getK() > 0.0)
+ { // suitable
+ if (sett.findMate) {
+ if (matePresent(pCell, othersex)) nbrlist.push_back(pCell);
+ }
+ else
+ nbrlist.push_back(pCell);
}
- else
- nbrlist.push_back(pCell);
}
}
}
@@ -1390,61 +1050,54 @@ for (int i = 0; i < ninds; i++) {
}
}
}
- }
- int listsize = (int)nbrlist.size();
- if (listsize > 0) { // there is at least one suitable neighbouring cell
- if (listsize == 1) {
- inds[i]->moveto(nbrlist[0]);
- }
- else { // select at random from the list
- int rrr = pRandom->IRandom(0,listsize-1);
- inds[i]->moveto(nbrlist[rrr]);
+ int listsize = (int)nbrlist.size();
+ if (listsize > 0) { // there is at least one suitable neighbouring cell
+ if (listsize == 1) {
+ inds[i]->moveto(nbrlist[0]);
+ }
+ else { // select at random from the list
+ int rrr = pRandom->IRandom(0, listsize - 1);
+ inds[i]->moveto(nbrlist[rrr]);
+ }
}
+ // else list empty - do nothing - individual retains its current location and status
}
- // else list empty - do nothing - individual retains its current location and status
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Population::transfer(): 9999: ninds = " << ninds
-// << " ndispersers = " << ndispersers << endl;
-#endif
-
-
-return ndispersers;
+ return ndispersers;
}
// Determine whether there is a potential mate present in a patch which a potential
// settler has reached
-bool Population::matePresent(Cell *pCell,short othersex)
+bool Population::matePresent(Cell* pCell, short othersex)
{
-int patch;
-Patch *pPatch;
-Population *pNewPopn;
-int popsize = 0;
-bool matefound = false;
-
-patch = (int)pCell->getPatch();
-if (patch != 0) {
- pPatch = (Patch*)pCell->getPatch();
- if (pPatch->getPatchNum() > 0) { // not the matrix patch
- if (pPatch->getK() > 0.0)
- { // suitable
- pNewPopn = (Population*)pPatch->getPopn((intptr)pSpecies);
- if (pNewPopn != 0) {
- // count members of other sex already resident in the patch
- for (int stg = 0; stg < nStages; stg++) {
- popsize += pNewPopn->nInds[stg][othersex];
+ int patch;
+ Patch* pPatch;
+ Population* pNewPopn;
+ int popsize = 0;
+ bool matefound = false;
+
+ patch = (int)pCell->getPatch();
+ if (patch != 0) {
+ pPatch = (Patch*)pCell->getPatch();
+ if (pPatch->getPatchNum() > 0) { // not the matrix patch
+ if (pPatch->getK() > 0.0)
+ { // suitable
+ pNewPopn = (Population*)pPatch->getPopn((intptr)pSpecies);
+ if (pNewPopn != 0) {
+ // count members of other sex already resident in the patch
+ for (int stg = 0; stg < nStages; stg++) {
+ popsize += pNewPopn->nInds[stg][othersex];
+ }
+ }
+ if (popsize < 1) {
+ // add any potential settlers of the other sex
+ popsize += pPatch->getPossSettlers(pSpecies, othersex);
}
- }
- if (popsize < 1) {
- // add any potential settlers of the other sex
- popsize += pPatch->getPossSettlers(pSpecies,othersex);
}
}
}
-}
-if (popsize > 0) matefound = true;
-return matefound;
+ if (popsize > 0) matefound = true;
+ return matefound;
}
//---------------------------------------------------------------------------
@@ -1454,794 +1107,565 @@ return matefound;
// FOR MULTIPLE SPECIES, MAY NEED TO SEPARATE OUT THIS IDENTIFICATION STAGE,
// SO THAT IT CAN BE PERFORMED FOR ALL SPECIES BEFORE ANY UPDATING OF POPULATIONS
-void Population::survival0(float localK,short option0,short option1)
+void Population::survival0(float localK, short option0, short option1)
{
-// option0: 0 - stage 0 (juveniles) only
-// 1 - all stages
-// 2 - stage 1 and above (all non-juveniles)
-// option1: 0 - development only (when survival is annual)
-// 1 - development and survival
-// 2 - survival only (when survival is annual)
-
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():"
-// << " pSpecies=" << pSpecies << " this=" << this << " PatchNum=" << pPatch->getPatchNum()
-//#if SEASONAL
-// << " season=" << season
-//#endif // SEASONAL
-// << " localK=" << localK << " option=" << option
-// << endl;
-#endif
+ // option0: 0 - stage 0 (juveniles) only
+ // 1 - all stages
+ // 2 - stage 1 and above (all non-juveniles)
+ // option1: 0 - development only (when survival is annual)
+ // 1 - development and survival
+ // 2 - survival only (when survival is annual)
+
+ densDepParams ddparams = pSpecies->getDensDep();
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
-densDepParams ddparams = pSpecies->getDensDep();
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
-
-// get surrent population size
-int ninds = (int)inds.size();
-if (ninds == 0) return;
-
-// set up local copies of species development and survival tables
-int nsexes;
-if (dem.repType == 0) nsexes = 1; else nsexes = 2;
-float dev[NSTAGES][NSEXES];
-float surv[NSTAGES][NSEXES];
-short minAge[NSTAGES][NSEXES];
-for (int stg = 0; stg < sstruct.nStages; stg++) {
- for (int sex = 0; sex < nsexes; sex++) {
- if (dem.stageStruct) {
- if (dem.repType == 1) { // simple sexual model
- // both sexes use development and survival recorded for females
- dev[stg][sex] = pSpecies->getDev(stg,0);
- surv[stg][sex] = pSpecies->getSurv(stg,0);
- minAge[stg][sex] = pSpecies->getMinAge(stg,0);
- }
- else {
- dev[stg][sex] = pSpecies->getDev(stg,sex);
- surv[stg][sex] = pSpecies->getSurv(stg,sex);
- minAge[stg][sex] = pSpecies->getMinAge(stg,sex);
- }
- if (option1 == 0) surv[stg][sex] = 1.0; // development only - all survive
- if (option1 == 2) dev[stg][sex] = 0.0; // survival only - none develops
- }
- else { // non-structured population
- if (stg == 1) { // adults
- dev[stg][sex] = 0.0; surv[stg][sex] = 0.0; minAge[stg][sex] = 0;
+ // get surrent population size
+ int ninds = (int)inds.size();
+ if (ninds == 0) return;
+
+ // set up local copies of species development and survival tables
+ int nsexes;
+ if (dem.repType == 0) nsexes = 1; else nsexes = 2;
+ float dev[NSTAGES][NSEXES];
+ float surv[NSTAGES][NSEXES];
+ short minAge[NSTAGES][NSEXES];
+ for (int stg = 0; stg < sstruct.nStages; stg++) {
+ for (int sex = 0; sex < nsexes; sex++) {
+ if (dem.stageStruct) {
+ if (dem.repType == 1) { // simple sexual model
+ // both sexes use development and survival recorded for females
+ dev[stg][sex] = pSpecies->getDev(stg, 0);
+ surv[stg][sex] = pSpecies->getSurv(stg, 0);
+ minAge[stg][sex] = pSpecies->getMinAge(stg, 0);
+ }
+ else {
+ dev[stg][sex] = pSpecies->getDev(stg, sex);
+ surv[stg][sex] = pSpecies->getSurv(stg, sex);
+ minAge[stg][sex] = pSpecies->getMinAge(stg, sex);
+ }
+ if (option1 == 0) surv[stg][sex] = 1.0; // development only - all survive
+ if (option1 == 2) dev[stg][sex] = 0.0; // survival only - none develops
}
- else { // juveniles
- dev[stg][sex] = 1.0; surv[stg][sex] = 1.0; minAge[stg][sex] = 0;
+ else { // non-structured population
+ if (stg == 1) { // adults
+ dev[stg][sex] = 0.0; surv[stg][sex] = 0.0; minAge[stg][sex] = 0;
+ }
+ else { // juveniles
+ dev[stg][sex] = 1.0; surv[stg][sex] = 1.0; minAge[stg][sex] = 0;
+ }
}
}
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0(): 1111 "
-// << " dev[" << stg << "][" << sex << "] = " << dev[stg][sex]
-// << " surv[" << stg << "][" << sex << "] = " << surv[stg][sex]
-// << endl;
-#endif
}
-}
-if (dem.stageStruct) {
-#if RSDEBUG
-// DEBUGLOG << "Population::survival0(): 2222 "
-// << " ninds=" << ninds << " localK=" << localK
-// << " effect of density dependence:" << endl;
-// for (int st = 0; st < nStages; st++) {
-// for (int sx = 0; sx < nsexes; sx++) {
-// DEBUGLOG << "st=" << st << " sx=" << sx << " nInds=" << nInds[st][sx] << endl;
-// }
-// }
-#endif
+ if (dem.stageStruct) {
// apply density dependence in development and/or survival probabilities
- for (int stg = 0; stg < nStages; stg++) {
- for (int sex = 0; sex < nsexes; sex++) {
- if (option1 != 2 && sstruct.devDens && stg > 0) {
+ for (int stg = 0; stg < nStages; stg++) {
+ for (int sex = 0; sex < nsexes; sex++) {
+ if (option1 != 2 && sstruct.devDens && stg > 0) {
#if RSDEBUG
-// DEBUGLOG << "DD in DEVELOPMENT for stg=" << stg << " sex=" << sex << endl;
+ // DEBUGLOG << "DD in DEVELOPMENT for stg=" << stg << " sex=" << sex << endl;
#endif
// NB DD in development does NOT apply to juveniles,
// which must develop to stage 1 if they survive
- float effect = 0.0;
- if (sstruct.devStageDens) { // stage-specific density dependence
- // NOTE: matrix entries represent effect of ROW on COLUMN
- // AND males precede females
- float weight = 0.0;
- for (int effstg = 0; effstg < nStages; effstg++) {
- for (int effsex = 0; effsex < nSexes; effsex++) {
- if (dem.repType == 2) {
- int rowincr,colincr;
- if (effsex == 0) rowincr = 1; else rowincr = 0;
- if (sex == 0) colincr = 1; else colincr = 0;
- weight = pSpecies->getDDwtDev(2*stg+colincr,2*effstg+rowincr);
- }
- else {
- weight = pSpecies->getDDwtDev(stg,effstg);
+ float effect = 0.0;
+ if (sstruct.devStageDens) { // stage-specific density dependence
+ // NOTE: matrix entries represent effect of ROW on COLUMN
+ // AND males precede females
+ float weight = 0.0;
+ for (int effstg = 0; effstg < nStages; effstg++) {
+ for (int effsex = 0; effsex < nSexes; effsex++) {
+ if (dem.repType == 2) {
+ int rowincr, colincr;
+ if (effsex == 0) rowincr = 1; else rowincr = 0;
+ if (sex == 0) colincr = 1; else colincr = 0;
+ weight = pSpecies->getDDwtDev(2 * stg + colincr, 2 * effstg + rowincr);
+ }
+ else {
+ weight = pSpecies->getDDwtDev(stg, effstg);
+ }
+ effect += (float)nInds[effstg][effsex] * weight;
}
- effect += (float)nInds[effstg][effsex] * weight;
-#if RSDEBUG
-// DEBUGLOG << " effstg=" << effstg << " effsex=" << effsex;
-// DEBUGLOG << " weight=" << weight << " effect=" << effect
-// << endl;
-#endif
}
}
- }
- else // not stage-specific
- effect = (float)totalPop();
- if (localK > 0.0)
- dev[stg][sex] *= exp(-(ddparams.devCoeff*effect)/localK);
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0(): 2288 " << " effect=" << effect;
-//if (localK > 0.0)
-// DEBUGLOG << " exp=" << exp(-(ddparams.devCoeff*effect)/localK);
-//DEBUGLOG << " dev[" << stg << "][" << sex << "] = " << dev[stg][sex]
-// << endl;
-#endif
- } // end of if (sstruct.devDens && stg > 0)
- if (option1 != 0 && sstruct.survDens) {
-#if RSDEBUG
-// DEBUGLOG << "DD in SURVIVAL for stg=" << stg << " sex=" << sex << endl;
-#endif
- float effect = 0.0;
- if (sstruct.survStageDens) { // stage-specific density dependence
- // NOTE: matrix entries represent effect of ROW on COLUMN
- // AND males precede females
- float weight = 0.0;
- for (int effstg = 0; effstg < nStages; effstg++) {
- for (int effsex = 0; effsex < nSexes; effsex++) {
- if (dem.repType == 2) {
- int rowincr,colincr;
- if (effsex == 0) rowincr = 1; else rowincr = 0;
- if (sex == 0) colincr = 1; else colincr = 0;
- weight = pSpecies->getDDwtSurv(2*stg+colincr,2*effstg+rowincr);
- }
- else {
- weight = pSpecies->getDDwtSurv(stg,effstg);
+ else // not stage-specific
+ effect = (float)totalPop();
+ if (localK > 0.0)
+ dev[stg][sex] *= exp(-(ddparams.devCoeff * effect) / localK);
+ } // end of if (sstruct.devDens && stg > 0)
+ if (option1 != 0 && sstruct.survDens) {
+ float effect = 0.0;
+ if (sstruct.survStageDens) { // stage-specific density dependence
+ // NOTE: matrix entries represent effect of ROW on COLUMN
+ // AND males precede females
+ float weight = 0.0;
+ for (int effstg = 0; effstg < nStages; effstg++) {
+ for (int effsex = 0; effsex < nSexes; effsex++) {
+ if (dem.repType == 2) {
+ int rowincr, colincr;
+ if (effsex == 0) rowincr = 1; else rowincr = 0;
+ if (sex == 0) colincr = 1; else colincr = 0;
+ weight = pSpecies->getDDwtSurv(2 * stg + colincr, 2 * effstg + rowincr);
+ }
+ else {
+ weight = pSpecies->getDDwtSurv(stg, effstg);
+ }
+ effect += (float)nInds[effstg][effsex] * weight;
}
- effect += (float)nInds[effstg][effsex] * weight;
-#if RSDEBUG
-// DEBUGLOG << " effstg=" << effstg << " effsex=" << effsex;
-// DEBUGLOG << " weight=" << weight << " effect=" << effect
-// << endl;
-#endif
}
}
- }
- else // not stage-specific
- effect = (float)totalPop();
- if (localK > 0.0)
- surv[stg][sex] *= exp(-(ddparams.survCoeff*effect)/localK);
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0(): 3333 " << " effect=" << effect;
-//if (localK > 0.0)
-// DEBUGLOG << " exp = " << exp(-(ddparams.survCoeff*effect)/localK);
-//DEBUGLOG << " surv[" << stg << "][" << sex << "] = " << surv[stg][sex]
-// << endl;
-#endif
- } // end of if (sstruct.survDens)
+ else // not stage-specific
+ effect = (float)totalPop();
+ if (localK > 0.0)
+ surv[stg][sex] *= exp(-(ddparams.survCoeff * effect) / localK);
+ } // end of if (sstruct.survDens)
+ }
}
}
-}
-// identify which individuals die or develop
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():" << " ninds " << ninds
-// << endl;
-#endif
-for (int i = 0; i < ninds; i++) {
- indStats ind = inds[i]->getStats();
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():"
-// << " i=" << i << " indId=" << inds[i]->getId()
-// << " stage=" << ind.stage << " status=" << ind.status << " sex=" << ind.sex
-//#if PARTMIGRN
-// << " migrnstatus=" << inds[i]->getMigrnStatus()
-//#endif // PARTMIGRN
-// << endl;
-#endif
- if ((ind.stage == 0 && option0 < 2) || (ind.stage > 0 && option0 > 0)) {
- // condition for processing the stage is met...
- if (ind.status < 6) { // not already doomed
- double probsurv = surv[ind.stage][ind.sex];
- // does the individual survive?
- if (pRandom->Bernoulli(probsurv)) { // survives
- // does the individual develop?
- double probdev = dev[ind.stage][ind.sex];
- if (ind.stage < nStages-1) { // not final stage
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():"
-// << " i=" << i << " indId=" << inds[i]->getId()
-// << " age=" << ind.age << " minAge[stage+1]=" << minAge[ind.stage+1][ind.sex]
-// << " probdev=" << probdev
-// << endl;
-#endif
- if (ind.age >= minAge[ind.stage+1][ind.sex]) { // old enough to enter next stage
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():"
-// << " i=" << i << " indId=" << inds[i]->getId() << " OLD ENOUGH"
-// << endl;
-#endif
- if (pRandom->Bernoulli(probdev)) {
- inds[i]->developing();
+ // identify which individuals die or develop
+ for (int i = 0; i < ninds; i++) {
+ indStats ind = inds[i]->getStats();
+ if ((ind.stage == 0 && option0 < 2) || (ind.stage > 0 && option0 > 0)) {
+ // condition for processing the stage is met...
+ if (ind.status < 6) { // not already doomed
+ double probsurv = surv[ind.stage][ind.sex];
+ // does the individual survive?
+ if (pRandom->Bernoulli(probsurv)) { // survives
+ // does the individual develop?
+ double probdev = dev[ind.stage][ind.sex];
+ if (ind.stage < nStages - 1) { // not final stage
+ if (ind.age >= minAge[ind.stage + 1][ind.sex]) { // old enough to enter next stage
+ if (pRandom->Bernoulli(probdev)) {
+ inds[i]->developing();
+ }
}
}
}
- }
- else { // doomed to die
-#if RSDEBUG
-//DEBUGLOG << "Population::survival0():"
-// << " i=" << i << " indId=" << inds[i]->getId() << " DIES"
-// << endl;
-#endif
- inds[i]->setStatus(8);
+ else { // doomed to die
+ inds[i]->setStatus(8);
+ }
}
}
}
-#if RSDEBUG
-//ind = inds[i]->getStats();
-//DEBUGLOG << "Population::survival0():"
-// << " i = " << i << " ID = " << inds[i]->getId()
-// << " stage = " << ind.stage << " status = " << ind.status
-// << endl;
-#endif
-}
}
// Apply survival changes to the population
void Population::survival1(void)
{
-int ninds = (int)inds.size();
-#if RSDEBUG
-//DEBUGLOG << "Population::survival1(): this=" << this
-// << " patchNum=" << pPatch->getPatchNum() << " ninds=" << ninds
-// << endl;
-#endif
-for (int i = 0; i < ninds; i++) {
- indStats ind = inds[i]->getStats();
-#if RSDEBUG
-//DEBUGLOG << "Population::survival1(): i=" << i
-// << " indId=" << inds[i]->getId() << " stage=" << ind.stage << " sex=" << ind.sex
-// << " isDeveloping=" << ind.isDeveloping << " status=" << ind.status
-// << endl;
-#endif
- if (ind.status > 5) { // doomed to die
- delete inds[i];
- inds[i] = NULL;
- nInds[ind.stage][ind.sex]--;
- }
- else {
- if (ind.isDeveloping) { // develops to next stage
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ indStats ind = inds[i]->getStats();
+ if (ind.status > 5) { // doomed to die
+ delete inds[i];
+ inds[i] = NULL;
nInds[ind.stage][ind.sex]--;
- inds[i]->develop();
- nInds[ind.stage+1][ind.sex]++;
+ }
+ else {
+ if (ind.isDeveloping) { // develops to next stage
+ nInds[ind.stage][ind.sex]--;
+ inds[i]->develop();
+ nInds[ind.stage + 1][ind.sex]++;
+ }
}
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Population::survival1(): this=" << this
-// << " patchNum=" << pPatch->getPatchNum() << " completed individuals loop"
-// << endl;
-#endif
-
-#if RSDEBUG
-//for (int i = 0; i < inds.size(); i++) {
-//DEBUGLOG << "Population::survival1():" << " inds[" << i << "] = " << inds[i] << endl;
-//}
-#endif
// remove pointers to dead individuals
-clean();
-#if RSDEBUG
-//DEBUGLOG << "Population::survival1(): this=" << this
-// << " patchNum=" << pPatch->getPatchNum() << " finished"
-// << endl;
-#endif
-
+ clean();
}
void Population::ageIncrement(void) {
-int ninds = (int)inds.size();
-stageParams sstruct = pSpecies->getStage();
-#if RSDEBUG
-//DEBUGLOG << "Population::ageIncrement():" << " inds.size() = " << inds.size()
-// << endl;
-#endif
-for (int i = 0; i < ninds; i++) {
- inds[i]->ageIncrement(sstruct.maxAge);
-}
+ int ninds = (int)inds.size();
+ stageParams sstruct = pSpecies->getStage();
+ for (int i = 0; i < ninds; i++) {
+ inds[i]->ageIncrement(sstruct.maxAge);
+ }
}
//---------------------------------------------------------------------------
// Remove zero pointers to dead or dispersed individuals
void Population::clean(void)
{
-int ninds = (int)inds.size();
-if (ninds > 0) {
-// sort (inds.begin(), inds.end());
-// reverse (inds.begin(), inds.end());
-//
-// while (inds.size() > 0 && inds[inds.size()-1] == NULL ) {
-// inds.pop_back();
-// }
- // ALTERNATIVE METHOD: AVOIDS SLOW SORTING OF POPULATION
- std::vector survivors; // all surviving individuals
- for (int i = 0; i < ninds; i++) {
- if (inds[i] != NULL) {
- survivors.push_back(inds[i]);
+ int ninds = (int)inds.size();
+ if (ninds > 0) {
+ // ALTERNATIVE METHOD: AVOIDS SLOW SORTING OF POPULATION
+ std::vector survivors; // all surviving individuals
+ for (int i = 0; i < ninds; i++) {
+ if (inds[i] != NULL) {
+ survivors.push_back(inds[i]);
+ }
}
- }
- inds.clear();
- inds = survivors;
+ inds.clear();
+ inds = survivors;
#if RS_RCPP
- shuffle(inds.begin(), inds.end(), pRandom->getRNG() );
+ shuffle(inds.begin(), inds.end(), pRandom->getRNG());
#else
#if !RSDEBUG
- // do not randomise individuals in RSDEBUG mode, as the function uses rand()
- // and therefore the randomisation will differ between identical runs of RS
- shuffle(inds.begin(), inds.end(), pRandom->getRNG() );
+ // do not randomise individuals in RSDEBUG mode, as the function uses rand()
+ // and therefore the randomisation will differ between identical runs of RS
+ shuffle(inds.begin(), inds.end(), pRandom->getRNG());
#endif // !RSDEBUG
#endif // RS_RCPP
-}
+ }
}
//---------------------------------------------------------------------------
// Open population file and write header record
-bool Population::outPopHeaders(int landNr,bool patchModel) {
+bool Population::outPopHeaders(int landNr, bool patchModel) {
-if (landNr == -999) { // close file
- if (outPop.is_open()) outPop.close();
- outPop.clear();
- return true;
-}
+ if (landNr == -999) { // close file
+ if (outPop.is_open()) outPop.close();
+ outPop.clear();
+ return true;
+ }
-string name;
-//landParams ppLand = pLandscape->getLandParams();
-//envStochParams env = paramsStoch->getStoch();
-simParams sim = paramsSim->getSim();
-envGradParams grad = paramsGrad->getGradient();
+ string name;
+ simParams sim = paramsSim->getSim();
+ envGradParams grad = paramsGrad->getGradient();
-// NEED TO REPLACE CONDITIONAL COLUMNS BASED ON ATTRIBUTES OF ONE SPECIES TO COVER
-// ATTRIBUTES OF *ALL* SPECIES AS DETECTED AT MODEL LEVEL
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
+ // NEED TO REPLACE CONDITIONAL COLUMNS BASED ON ATTRIBUTES OF ONE SPECIES TO COVER
+ // ATTRIBUTES OF *ALL* SPECIES AS DETECTED AT MODEL LEVEL
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
-if (sim.batchMode) {
- name = paramsSim->getDir(2)
- + "Batch" + Int2Str(sim.batchNum) + "_"
- + "Sim" + Int2Str(sim.simulation) + "_Land" + Int2Str(landNr) + "_Pop.txt";
-}
-else{
- name = paramsSim->getDir(2) + "Sim" + Int2Str(sim.simulation) +"_Pop.txt";
-}
-outPop.open(name.c_str());
-outPop << "Rep\tYear\tRepSeason";
-if (patchModel) outPop << "\tPatchID\tNcells";
-else outPop << "\tx\ty";
-// determine whether environmental data need be written for populations
-bool writeEnv = false;
-if (grad.gradient) writeEnv = true;
-if (paramsStoch->envStoch()) writeEnv = true;
-if (writeEnv) outPop << "\tEpsilon\tGradient\tLocal_K";
-outPop << "\tSpecies\tNInd";
-#if RSDEBUG
-//DEBUGLOG << "Population::outPopHeaders(): this=" << this
-// << " patchNum=" << pPatch->getPatchNum()
-// << " totalPop()=" << totalPop()
-// << " nStages=" << nStages << " nSexes=" << nSexes
-// << endl;
-#endif
-if (dem.stageStruct) {
- if (dem.repType == 0)
- {
- for (int i = 1; i < sstruct.nStages; i++) outPop << "\tNInd_stage" << i ;
- outPop << "\tNJuvs";
+ if (sim.batchMode) {
+ name = paramsSim->getDir(2)
+ + "Batch" + Int2Str(sim.batchNum) + "_"
+ + "Sim" + Int2Str(sim.simulation) + "_Land" + Int2Str(landNr) + "_Pop.txt";
}
else {
- for (int i = 1; i < sstruct.nStages; i++)
- outPop << "\tNfemales_stage" << i << "\tNmales_stage" << i ;
- outPop << "\tNJuvFemales\tNJuvMales";
+ name = paramsSim->getDir(2) + "Sim" + Int2Str(sim.simulation) + "_Pop.txt";
}
-}
-else {
- if (dem.repType != 0) outPop << "\tNfemales\tNmales";
-}
-outPop << endl;
+ outPop.open(name.c_str());
+ outPop << "Rep\tYear\tRepSeason";
+ if (patchModel) outPop << "\tPatchID\tNcells";
+ else outPop << "\tx\ty";
+ // determine whether environmental data need be written for populations
+ bool writeEnv = false;
+ if (grad.gradient) writeEnv = true;
+ if (paramsStoch->envStoch()) writeEnv = true;
+ if (writeEnv) outPop << "\tEpsilon\tGradient\tLocal_K";
+ outPop << "\tSpecies\tNInd";
+ if (dem.stageStruct) {
+ if (dem.repType == 0)
+ {
+ for (int i = 1; i < sstruct.nStages; i++) outPop << "\tNInd_stage" << i;
+ outPop << "\tNJuvs";
+ }
+ else {
+ for (int i = 1; i < sstruct.nStages; i++)
+ outPop << "\tNfemales_stage" << i << "\tNmales_stage" << i;
+ outPop << "\tNJuvFemales\tNJuvMales";
+ }
+ }
+ else {
+ if (dem.repType != 0) outPop << "\tNfemales\tNmales";
+ }
+ outPop << endl;
-return outPop.is_open();
+ return outPop.is_open();
}
//---------------------------------------------------------------------------
// Write record to population file
-void Population::outPopulation(int rep,int yr,int gen,float eps,
- bool patchModel,bool writeEnv,bool gradK)
+void Population::outPopulation(int rep, int yr, int gen, float eps,
+ bool patchModel, bool writeEnv, bool gradK)
{
-Cell *pCell;
-
-#if RSDEBUG
-//DEBUGLOG << "Population::outPopulations(): this=" << this
-// << " writeEnv " << (int)writeEnv
-// << endl;
-#endif
-
+ Cell* pCell;
// NEED TO REPLACE CONDITIONAL COLUMNS BASED ON ATTRIBUTES OF ONE SPECIES TO COVER
// ATTRIBUTES OF *ALL* SPECIES AS DETECTED AT MODEL LEVEL
-demogrParams dem = pSpecies->getDemogr();
-stageParams sstruct = pSpecies->getStage();
-popStats p;
-
-outPop << rep << "\t" << yr << "\t" << gen;
-if (patchModel) {
- outPop << "\t" << pPatch->getPatchNum();
- outPop << "\t" << pPatch->getNCells();
-}
-else {
- locn loc = pPatch->getCellLocn(0);
- outPop << "\t" << loc.x << "\t" << loc.y;
-}
-if (writeEnv) {
- if (pPatch->getPatchNum() == 0) { // matrix
- outPop << "\t0\t0\t0";
+ demogrParams dem = pSpecies->getDemogr();
+ stageParams sstruct = pSpecies->getStage();
+ popStats p;
+
+ outPop << rep << "\t" << yr << "\t" << gen;
+ if (patchModel) {
+ outPop << "\t" << pPatch->getPatchNum();
+ outPop << "\t" << pPatch->getNCells();
}
else {
- float k = pPatch->getK();
- float envval = 0.0;
- pCell = pPatch->getRandomCell();
- if (pCell != 0) envval = pCell->getEnvVal();
- outPop << "\t" << eps << "\t" << envval << "\t" << k;
+ locn loc = pPatch->getCellLocn(0);
+ outPop << "\t" << loc.x << "\t" << loc.y;
}
-}
-#if RSDEBUG
-//DEBUGLOG << "Population::outPopulation(): this=" << this
-// << " patchNum=" << pPatch->getPatchNum()
-// << " totalPop()=" << totalPop()
-// << " nStages=" << nStages << " nSexes=" << nSexes
-// << endl;
-#endif
-outPop << "\t" << pSpecies->getSpNum();
-if (dem.stageStruct) {
- p = getStats();
- outPop << "\t" << p.nNonJuvs;
- // non-juvenile stage totals from permanent array
- for (int stg = 1; stg < nStages; stg++) {
- for (int sex = 0; sex < nSexes; sex++) {
- outPop << "\t" << nInds[stg][sex];
+ if (writeEnv) {
+ if (pPatch->getPatchNum() == 0) { // matrix
+ outPop << "\t0\t0\t0";
+ }
+ else {
+ float k = pPatch->getK();
+ float envval = 0.0;
+ pCell = pPatch->getRandomCell();
+ if (pCell != 0) envval = pCell->getEnvVal();
+ outPop << "\t" << eps << "\t" << envval << "\t" << k;
}
}
- // juveniles from permanent array
- for (int sex = 0; sex < nSexes; sex++) {
- outPop << "\t" << nInds[0][sex];
- }
-}
-else { // non-structured population
- outPop << "\t" << totalPop();
- if (dem.repType != 0)
- { // sexual model
- outPop << "\t" << nInds[1][0] << "\t" << nInds[1][1];
- }
-}
-outPop << endl;
-
-/*
-#if RS_ABC
-obsdata obs;
-if (abcYear) {
- int nobs = (int)pABCmaster->NObs();
- for (int i = 0; i < nobs; i++) {
- obs = pABCmaster->getObsData(i);
-#if RSDEBUG
-//DEBUGLOG << "Population::outPopulation(): this=" << this << " i=" << i << " yr=" << yr
-// << " obs.year=" << obs.year << " obs.type=" << obs.type << " obs.name=" << obs.name
-// << " obs.x=" << obs.x << " obs.y=" << obs.y
-// << endl;
-#endif
- if (obs.year == yr && obs.type == 2) {
- if (obs.name == "NInds" || obs.name == "Occupied") {
- bool match = false;
- if (patchModel) {
- if (obs.x == pPatch->getPatchNum()) {
- match = true;
-#if RSDEBUG
-//DEBUGLOG << "Population::outPopulation(): i=" << i << " PROCESS Population NInds"
-// << " obs.id=" << obs.id << " obs.value=" << obs.value << " obs.x=" << obs.x
-// << " pPatch->PatchNum()=" << pPatch->getPatchNum()
-// << " totalPop()=" << totalPop() << " p.nNonJuvs=" << p.nNonJuvs
-// << endl;
-#endif
- }
- }
- else {
- locn loc = pPatch->getCentroid();
- if (obs.x == loc.x && obs.y == loc.y) {
- match = true;
-#if RSDEBUG
-DEBUGLOG << "Population::outPopulation(): i=" << i << " PROCESS Population NInds"
- << " obs.id=" << obs.id << " obs.value=" << obs.value << " obs.x="
- << obs.x << " obs.y=" << obs.y << " loc.x=" << loc.x << " loc.y=" << loc.y
- << " totalPop()=" << totalPop() << " p.nNonJuvs=" << p.nNonJuvs
- << endl;
-#endif
- }
- }
- if (match) {
- if (obs.name == "NInds") {
- if (dem.stageStruct)
- pABCmaster->AddNewPred(sim.simulation,obs.id,rep,obs.value,p.nNonJuvs,obs.weight);
- else
- pABCmaster->AddNewPred(sim.simulation,obs.id,rep,obs.value,totalPop(),obs.weight);
- }
- else { // obs.name == "Occupied"
- pABCmaster->AddNewPred(sim.simulation,obs.id,rep,obs.value,p.breeding,obs.weight);
- }
- }
+ outPop << "\t" << pSpecies->getSpNum();
+ if (dem.stageStruct) {
+ p = getStats();
+ outPop << "\t" << p.nNonJuvs;
+ // non-juvenile stage totals from permanent array
+ for (int stg = 1; stg < nStages; stg++) {
+ for (int sex = 0; sex < nSexes; sex++) {
+ outPop << "\t" << nInds[stg][sex];
}
}
+ // juveniles from permanent array
+ for (int sex = 0; sex < nSexes; sex++) {
+ outPop << "\t" << nInds[0][sex];
+ }
}
-}
-#endif // ABC
-*/
+ else { // non-structured population
+ outPop << "\t" << totalPop();
+ if (dem.repType != 0)
+ { // sexual model
+ outPop << "\t" << nInds[1][0] << "\t" << nInds[1][1];
+ }
+ }
+ outPop << endl;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Open individuals file and write header record
-void Population::outIndsHeaders(int rep,int landNr,bool patchModel)
+void Population::outIndsHeaders(int rep, int landNr, bool patchModel)
{
-if (landNr == -999) { // close file
- if (outInds.is_open()) {
- outInds.close(); outInds.clear();
+ if (landNr == -999) { // close file
+ if (outInds.is_open()) {
+ outInds.close(); outInds.clear();
+ }
+ return;
}
- return;
-}
-string name;
-demogrParams dem = pSpecies->getDemogr();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
-simParams sim = paramsSim->getSim();
-
-if (sim.batchMode) {
- name = paramsSim->getDir(2)
- + "Batch" + Int2Str(sim.batchNum) + "_"
- + "Sim" + Int2Str(sim.simulation)
- + "_Land" + Int2Str(landNr) + "_Rep" + Int2Str(rep) + "_Inds.txt";
-}
-else {
- name = paramsSim->getDir(2) + "Sim" + Int2Str(sim.simulation)
- + "_Rep" + Int2Str(rep) +"_Inds.txt";
-}
-outInds.open(name.c_str());
-
-outInds << "Rep\tYear\tRepSeason\tSpecies\tIndID\tStatus";
-if (patchModel) outInds << "\tNatal_patch\tPatchID";
-else outInds << "\tNatal_X\tNatal_Y\tX\tY";
-if (dem.repType != 0) outInds << "\tSex";
-if (dem.stageStruct) outInds << "\tAge\tStage";
-if (emig.indVar) {
- if (emig.densDep) outInds << "\tD0\tAlpha\tBeta";
- else outInds << "\tEP";
-}
-if (trfr.indVar) {
- if (trfr.moveModel) {
- if (trfr.moveType == 1) { // SMS
- outInds << "\tDP\tGB\tAlphaDB\tBetaDB";
+ string name;
+ demogrParams dem = pSpecies->getDemogr();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
+ simParams sim = paramsSim->getSim();
+
+ if (sim.batchMode) {
+ name = paramsSim->getDir(2)
+ + "Batch" + Int2Str(sim.batchNum) + "_"
+ + "Sim" + Int2Str(sim.simulation)
+ + "_Land" + Int2Str(landNr) + "_Rep" + Int2Str(rep) + "_Inds.txt";
+ }
+ else {
+ name = paramsSim->getDir(2) + "Sim" + Int2Str(sim.simulation)
+ + "_Rep" + Int2Str(rep) + "_Inds.txt";
+ }
+ outInds.open(name.c_str());
+
+ outInds << "Rep\tYear\tRepSeason\tSpecies\tIndID\tStatus";
+ if (patchModel) outInds << "\tNatal_patch\tPatchID";
+ else outInds << "\tNatal_X\tNatal_Y\tX\tY";
+ if (dem.repType != 0) outInds << "\tSex";
+ if (dem.stageStruct) outInds << "\tAge\tStage";
+ if (emig.indVar) {
+ if (emig.densDep) outInds << "\tD0\tAlpha\tBeta";
+ else outInds << "\tEP";
+ }
+ if (trfr.indVar) {
+ if (trfr.moveModel) {
+ if (trfr.moveType == 1) { // SMS
+ outInds << "\tDP\tGB\tAlphaDB\tBetaDB";
+ }
+ if (trfr.moveType == 2) { // CRW
+ outInds << "\tStepLength\tRho";
+ }
}
- if (trfr.moveType == 2) { // CRW
- outInds << "\tStepLength\tRho";
+ else { // kernel
+ outInds << "\tMeanDistI";
+ if (trfr.twinKern) outInds << "\tMeanDistII\tPKernelI";
}
}
- else { // kernel
- outInds << "\tMeanDistI";
- if (trfr.twinKern) outInds << "\tMeanDistII\tPKernelI";
+ if (sett.indVar) {
+ outInds << "\tS0\tAlphaS\tBetaS";
}
-}
-if (sett.indVar) {
- outInds << "\tS0\tAlphaS\tBetaS";
-}
-outInds << "\tDistMoved";
+ outInds << "\tDistMoved";
#if RSDEBUG
-// ALWAYS WRITE NO. OF STEPS
-outInds << "\tNsteps";
+ // ALWAYS WRITE NO. OF STEPS
+ outInds << "\tNsteps";
#else
-if (trfr.moveModel) outInds << "\tNsteps";
+ if (trfr.moveModel) outInds << "\tNsteps";
#endif
-outInds << endl;
+ outInds << endl;
}
//---------------------------------------------------------------------------
// Write records to individuals file
-void Population::outIndividual(Landscape *pLandscape,int rep,int yr,int gen,
+void Population::outIndividual(Landscape* pLandscape, int rep, int yr, int gen,
int patchNum)
{
-//int x, y, p_id;
-bool writeInd;
-pathSteps steps;
-Cell *pCell;
-
-landParams ppLand = pLandscape->getLandParams();
-//landOrigin lim = pLandscape->getOrigin();
-demogrParams dem = pSpecies->getDemogr();
-emigRules emig = pSpecies->getEmig();
-trfrRules trfr = pSpecies->getTrfr();
-settleType sett = pSpecies->getSettle();
-short spNum = pSpecies->getSpNum();
-
-int ninds = (int)inds.size();
-
-for (int i = 0; i < ninds; i++) {
- indStats ind = inds[i]->getStats();
- if (yr == -1) { // write all initialised individuals
- writeInd = true;
- outInds << rep << "\t" << yr << "\t" << dem.repSeasons-1;
- }
- else {
- if (dem.stageStruct && gen < 0) { // write status 9 individuals only
- if (ind.status == 9) {
- writeInd = true;
- outInds << rep << "\t" << yr << "\t" << dem.repSeasons-1;
- }
- else writeInd = false;
- }
- else {
+ //int x, y, p_id;
+ bool writeInd;
+ pathSteps steps;
+ Cell* pCell;
+
+ landParams ppLand = pLandscape->getLandParams();
+ demogrParams dem = pSpecies->getDemogr();
+ emigRules emig = pSpecies->getEmig();
+ trfrRules trfr = pSpecies->getTrfr();
+ settleType sett = pSpecies->getSettle();
+ short spNum = pSpecies->getSpNum();
+
+ int ninds = (int)inds.size();
+
+ for (int i = 0; i < ninds; i++) {
+ indStats ind = inds[i]->getStats();
+ if (yr == -1) { // write all initialised individuals
writeInd = true;
- outInds << rep << "\t" << yr << "\t" << gen;
- }
- }
- if (writeInd) {
- outInds << "\t" << spNum << "\t" << inds[i]->getId();
- if (dem.stageStruct) outInds << "\t" << ind.status;
- else { // non-structured population
- outInds << "\t" << ind.status;
+ outInds << rep << "\t" << yr << "\t" << dem.repSeasons - 1;
}
- pCell = inds[i]->getLocn(1);
- locn loc;
- if (pCell == 0) loc.x = loc.y = -1; // beyond boundary or in no-data cell
- else loc = pCell->getLocn();
- pCell = inds[i]->getLocn(0);
- locn natalloc = pCell->getLocn();
-//#if SEASONAL
-// pCell = inds[i]->getLocn(2);
-// locn prevloc = pCell->getLocn();
-//#endif
- if (ppLand.patchModel) {
- outInds << "\t" << inds[i]->getNatalPatch()->getPatchNum();
- if (loc.x == -1) outInds << "\t-1";
- else outInds << "\t" << patchNum;
- }
- else { // cell-based model
- // EITHER write co-ordinates in cell units ...
- outInds << "\t" << (float)natalloc.x << "\t" << natalloc.y;
- outInds << "\t" << (float)loc.x << "\t" << (float)loc.y ;
- // ... OR write co-ordinates in real-world units
-// outInds << "\t" << (float)natalloc.x * (float)ppLand.resol + (float)lim.minEast
-// << "\t" << natalloc.y * (float)ppLand.resol + (float)lim.minNorth;
-// outInds << "\t" << (float)loc.x * (float)ppLand.resol + (float)lim.minEast
-// << "\t" << (float)loc.y * (float)ppLand.resol + (float)lim.minNorth;
- }
- if (dem.repType != 0) outInds <<"\t" << ind.sex;
- if (dem.stageStruct) outInds <<"\t" << ind.age <<"\t"<< ind.stage;
-
- if (emig.indVar) {
- emigTraits e = inds[i]->getEmigTraits();
- if (emig.densDep) {
- outInds << "\t" << e.d0 << "\t" << e.alpha << "\t" << e.beta;
+ else {
+ if (dem.stageStruct && gen < 0) { // write status 9 individuals only
+ if (ind.status == 9) {
+ writeInd = true;
+ outInds << rep << "\t" << yr << "\t" << dem.repSeasons - 1;
+ }
+ else writeInd = false;
}
else {
- outInds << "\t" << e.d0;
+ writeInd = true;
+ outInds << rep << "\t" << yr << "\t" << gen;
}
- } // end of if (emig.indVar)
-
- if (trfr.indVar) {
- if (trfr.moveModel) {
- if (trfr.moveType == 1) { // SMS
- trfrSMSTraits s = inds[i]->getSMSTraits();
- outInds << "\t" << s.dp << "\t" << s.gb;
- outInds << "\t" << s.alphaDB << "\t" << s.betaDB;
- } // end of SMS
- if (trfr.moveType == 2) { // CRW
- trfrCRWTraits c = inds[i]->getCRWTraits();
- outInds << "\t" << c.stepLength << "\t" << c.rho;
-#if RSDEBUG
-//DEBUGLOG << "Population::outIndividual():"
-// << " patchNum=" << patchNum << " i=" << i << " ID=" << inds[i]->getId()
-// << " nTrfrGenes=" << nTrfrGenes << " loc[0][0].allele[0]=" << loc[0][0].allele[0]
-// << endl;
-#endif
- } // end of CRW
+ }
+ if (writeInd) {
+ outInds << "\t" << spNum << "\t" << inds[i]->getId();
+ if (dem.stageStruct) outInds << "\t" << ind.status;
+ else { // non-structured population
+ outInds << "\t" << ind.status;
}
- else { // kernel
- trfrKernTraits k = inds[i]->getKernTraits();
- if (trfr.twinKern)
- {
- outInds << "\t" << k.meanDist1 << "\t" << k.meanDist2 << "\t" << k.probKern1;
+ pCell = inds[i]->getLocn(1);
+ locn loc;
+ if (pCell == 0) loc.x = loc.y = -1; // beyond boundary or in no-data cell
+ else loc = pCell->getLocn();
+ pCell = inds[i]->getLocn(0);
+ locn natalloc = pCell->getLocn();
+ if (ppLand.patchModel) {
+ outInds << "\t" << inds[i]->getNatalPatch()->getPatchNum();
+ if (loc.x == -1) outInds << "\t-1";
+ else outInds << "\t" << patchNum;
+ }
+ else { // cell-based model
+ outInds << "\t" << (float)natalloc.x << "\t" << natalloc.y;
+ outInds << "\t" << (float)loc.x << "\t" << (float)loc.y;
+ }
+ if (dem.repType != 0) outInds << "\t" << ind.sex;
+ if (dem.stageStruct) outInds << "\t" << ind.age << "\t" << ind.stage;
+
+ if (emig.indVar) {
+ emigTraits e = inds[i]->getEmigTraits();
+ if (emig.densDep) {
+ outInds << "\t" << e.d0 << "\t" << e.alpha << "\t" << e.beta;
}
else {
- outInds << "\t" << k.meanDist1;
+ outInds << "\t" << e.d0;
+ }
+ } // end of if (emig.indVar)
+
+ if (trfr.indVar) {
+ if (trfr.moveModel) {
+ if (trfr.moveType == 1) { // SMS
+ trfrSMSTraits s = inds[i]->getSMSTraits();
+ outInds << "\t" << s.dp << "\t" << s.gb;
+ outInds << "\t" << s.alphaDB << "\t" << s.betaDB;
+ } // end of SMS
+ if (trfr.moveType == 2) { // CRW
+ trfrCRWTraits c = inds[i]->getCRWTraits();
+ outInds << "\t" << c.stepLength << "\t" << c.rho;
+ } // end of CRW
+ }
+ else { // kernel
+ trfrKernTraits k = inds[i]->getKernTraits();
+ if (trfr.twinKern)
+ {
+ outInds << "\t" << k.meanDist1 << "\t" << k.meanDist2 << "\t" << k.probKern1;
+ }
+ else {
+ outInds << "\t" << k.meanDist1;
+ }
}
}
- }
- if (sett.indVar) {
- settleTraits s = inds[i]->getSettTraits();
- outInds << "\t" << s.s0 << "\t" << s.alpha << "\t" << s.beta;
- }
+ if (sett.indVar) {
+ settleTraits s = inds[i]->getSettTraits();
+ outInds << "\t" << s.s0 << "\t" << s.alpha << "\t" << s.beta;
+ }
- // distance moved (metres)
- if (loc.x == -1) outInds << "\t-1";
- else {
- float d = ppLand.resol * sqrt((float)((natalloc.x-loc.x)*(natalloc.x-loc.x)
- + (natalloc.y-loc.y)*(natalloc.y-loc.y)));
- outInds << "\t" << d;
- }
+ // distance moved (metres)
+ if (loc.x == -1) outInds << "\t-1";
+ else {
+ float d = ppLand.resol * sqrt((float)((natalloc.x - loc.x) * (natalloc.x - loc.x)
+ + (natalloc.y - loc.y) * (natalloc.y - loc.y)));
+ outInds << "\t" << d;
+ }
#if RSDEBUG
- // ALWAYS WRITE NO. OF STEPS
- steps = inds[i]->getSteps();
- outInds << "\t" << steps.year;
-#else
- if (trfr.moveModel) {
+ // ALWAYS WRITE NO. OF STEPS
steps = inds[i]->getSteps();
outInds << "\t" << steps.year;
- }
+#else
+ if (trfr.moveModel) {
+ steps = inds[i]->getSteps();
+ outInds << "\t" << steps.year;
+ }
#endif
- outInds << endl;
- } // end of writeInd condition
-
-}
+ outInds << endl;
+ } // end of writeInd condition
+ }
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Write records to genetics file
-void Population::outGenetics(const int rep,const int year,const int landNr)
+void Population::outGenetics(const int rep, const int year, const int landNr)
{
-simParams sim = paramsSim->getSim();
+ simParams sim = paramsSim->getSim();
-if (landNr >= 0) { // open file
- Genome *pGenome;
- genomeData gen = pSpecies->getGenomeData();
- if (gen.trait1Chromosome) {
- pGenome = new Genome(pSpecies->getNChromosomes(),pSpecies->getNLoci(0),
- pSpecies->isDiploid());
- }
- else {
- pGenome = new Genome(pSpecies);
+ if (landNr >= 0) { // open file
+ Genome* pGenome;
+ genomeData gen = pSpecies->getGenomeData();
+ if (gen.trait1Chromosome) {
+ pGenome = new Genome(pSpecies->getNChromosomes(), pSpecies->getNLoci(0),
+ pSpecies->isDiploid());
+ }
+ else {
+ pGenome = new Genome(pSpecies);
+ }
+ pGenome->outGenHeaders(rep, landNr, sim.outGenXtab);
+ delete pGenome;
+ return;
}
- pGenome->outGenHeaders(rep,landNr,sim.outGenXtab);
- delete pGenome;
- return;
-}
-if (landNr == -999) { // close file
- Genome *pGenome = new Genome();
- pGenome->outGenHeaders(rep,landNr,sim.outGenXtab);
- delete pGenome;
- return;
-}
-
-short spNum = pSpecies->getSpNum();
-short nstages = 1;
-if (pSpecies->stageStructured()) {
- stageParams sstruct = pSpecies->getStage();
- nstages = sstruct.nStages;
-}
+ if (landNr == -999) { // close file
+ Genome* pGenome = new Genome();
+ pGenome->outGenHeaders(rep, landNr, sim.outGenXtab);
+ delete pGenome;
+ return;
+ }
+ short spNum = pSpecies->getSpNum();
+ short nstages = 1;
+ if (pSpecies->stageStructured()) {
+ stageParams sstruct = pSpecies->getStage();
+ nstages = sstruct.nStages;
+ }
-int ninds = (int)inds.size();
-for (int i = 0; i < ninds; i++) {
- indStats ind = inds[i]->getStats();
- if (year == 0 || sim.outGenType == 1
- || (sim.outGenType == 0 && ind.stage == 0)
- || (sim.outGenType == 2 && ind.stage == nstages-1)) {
- inds[i]->outGenetics(rep,year,spNum,landNr,sim.outGenXtab);
+ int ninds = (int)inds.size();
+ for (int i = 0; i < ninds; i++) {
+ indStats ind = inds[i]->getStats();
+ if (year == 0 || sim.outGenType == 1
+ || (sim.outGenType == 0 && ind.stage == 0)
+ || (sim.outGenType == 2 && ind.stage == nstages - 1)) {
+ inds[i]->outGenetics(rep, year, spNum, landNr, sim.outGenXtab);
+ }
}
-}
}
diff --git a/RangeShiftR/src/RScore/Population.h b/RangeShiftR/src/RScore/Population.h
index 9c8efd8..fd1fa66 100644
--- a/RangeShiftR/src/RScore/Population.h
+++ b/RangeShiftR/src/RScore/Population.h
@@ -50,9 +50,6 @@ Last updated: 22 January 2022 by Steve Palmer
#include
#include
-//#include
-//#include
-//#include
using namespace std;
#include "Parameters.h"
diff --git a/RangeShiftR/src/RScore/RSrandom.cpp b/RangeShiftR/src/RScore/RSrandom.cpp
index 79744c9..1b9f523 100644
--- a/RangeShiftR/src/RScore/RSrandom.cpp
+++ b/RangeShiftR/src/RScore/RSrandom.cpp
@@ -26,7 +26,6 @@
#if !RS_RCPP
-
#if RSDEBUG
#include "Parameters.h"
extern paramSim* paramsSim;
@@ -94,6 +93,8 @@ int RSrandom::IRandom(int min, int max)
int RSrandom::Bernoulli(double p)
{
+ if (p < 0) throw runtime_error("Bernoulli's p cannot be negative.\n");
+ if (p > 1) throw runtime_error("Bernoulli's p cannot be above 1.\n");
return Random() < p;
}
@@ -190,6 +191,8 @@ int RSrandom::Poisson(double mean)
}
int RSrandom::Bernoulli(double p) {
+ if (p < 0) throw runtime_error("Bernoulli's p cannot be negative.\n");
+ if (p > 1) throw runtime_error("Bernoulli's p cannot be above 1.\n");
return Random() < p;
}
@@ -253,4 +256,28 @@ int RSrandom::Poisson(double mean)
#endif // RS_RCPP
+
+#if RSDEBUG
+ void testRSrandom() {
+
+ {
+ // Bernoulli distribution
+ // Abuse cases
+ assert_error("Bernoulli's p cannot be negative.\n", []{
+ RSrandom rsr;
+ rsr.Bernoulli(-0.3);
+ });
+ assert_error("Bernoulli's p cannot be above 1.\n", [] {
+ RSrandom rsr;
+ rsr.Bernoulli(1.1);
+ });
+ // Use cases
+ RSrandom rsr;
+ assert(rsr.Bernoulli(0) == 0);
+ assert(rsr.Bernoulli(1) == 1);
+ int bern_trial = rsr.Bernoulli(0.5);
+ assert(bern_trial == 0 || bern_trial == 1);
+ }
+ }
+#endif // RSDEBUG
//---------------------------------------------------------------------------
diff --git a/RangeShiftR/src/RScore/RSrandom.h b/RangeShiftR/src/RScore/RSrandom.h
index 9293b29..0e61c19 100644
--- a/RangeShiftR/src/RScore/RSrandom.h
+++ b/RangeShiftR/src/RScore/RSrandom.h
@@ -38,11 +38,12 @@ Last updated: 12 January 2021 by Steve Palmer
#include
#include
-//#include
+#include
+#include "Utils.h"
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
@@ -131,6 +132,9 @@ extern ofstream DEBUGLOG;
#endif // !RS_RCPP
+#if RSDEBUG
+ void testRSrandom();
+#endif // RSDEBUG
//---------------------------------------------------------------------------
diff --git a/RangeShiftR/src/RScore/RandomCheck.h b/RangeShiftR/src/RScore/RandomCheck.h
index b4f6f01..45c6b82 100644
--- a/RangeShiftR/src/RScore/RandomCheck.h
+++ b/RangeShiftR/src/RScore/RandomCheck.h
@@ -28,9 +28,9 @@
#include
using namespace std;
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
diff --git a/RangeShiftR/src/RScore/Species.cpp b/RangeShiftR/src/RScore/Species.cpp
index 9aae805..727e3c3 100644
--- a/RangeShiftR/src/RScore/Species.cpp
+++ b/RangeShiftR/src/RScore/Species.cpp
@@ -1,25 +1,25 @@
/*----------------------------------------------------------------------------
- *
- * 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 .
- *
+ *
--------------------------------------------------------------------------*/
-
-
+
+
//---------------------------------------------------------------------------
#include "Species.h"
@@ -31,7 +31,7 @@ Species::Species(void)
repType = 0; nStages = 2;
stageStruct = false;
propMales = 0.5; harem = 1.0; bc = 1.0; lambda = 1.5; probRep = 1.0;
-repSeasons = 1;
+repSeasons = 1;
repInterval = 0; maxAge = 1000; survival = 1;
fecDens = false; fecStageDens = false;
devDens = false; devStageDens = false;
@@ -39,7 +39,7 @@ survDens = false; survStageDens = false;
disperseOnLoss = false;
for (int i = 0; i < NSTAGES; i++) {
for (int j = 0; j < NSEXES; j++) {
- fec[i][j] = 0.0; dev[i][j] = 0.0; surv[i][j] = 0.0;
+ fec[i][j] = 0.0; dev[i][j] = 0.0; surv[i][j] = 0.0;
minAge[i][j] = 0;
}
}
@@ -82,10 +82,10 @@ for (int j = 0; j < NSEXES; j++) {
d0Scale = alphaScale = betaScale = 0.0;
// initialise transfer parameters
-moveModel = false; stgDepTrfr = false; sexDepTrfr = false; distMort = false;
+moveModel = false; stgDepTrfr = false; sexDepTrfr = false; distMort = false;
indVarTrfr = false;
twinKern = false;
-habMort = false;
+habMort = false;
costMap = false;
moveType = 1;
for (int i = 0; i < NSTAGES; i++) {
@@ -126,12 +126,12 @@ for (int i = 0; i < NSTAGES; i++) {
s0[i][j] = 1.0; alphaS[i][j] = 0.0; betaS[i][j] = 1.0;
}
}
-for (int j = 0; j < NSEXES; j++) {
+for (int j = 0; j < NSEXES; j++) {
alphaSMean[0][j] = 0.0; alphaSSD[0][j] = 0.0;
betaSMean[0][j] = 0.0; betaSSD[0][j] = 0.0;
s0Mean[0][j] = 0.0; s0SD[0][j] = 0.0;
}
-alphaSScale = 0.0; betaSScale = 0.0; s0Scale = 0.0;
+alphaSScale = 0.0; betaSScale = 0.0; s0Scale = 0.0;
// initialise attributes
spNum = 0;
@@ -407,7 +407,7 @@ if (ddwtSurv != 0) {
// Functions to handle min/max R or K (under environmental stochasticity)
//void Species::setMinMax(float min,float max) {
-void Species::setMinMax(float min, float max) {
+void Species::setMinMax(float min, float max) {
if (min >= 0.0 && max > min) {
minRK = min; maxRK = max;
}
@@ -626,7 +626,7 @@ if (indVarTrfr) {
}
else {
if (sexDepTrfr) {
- if (twinKern)
+ if (twinKern)
{
traitnames[trait++] = "meanDistI_F";
traitnames[trait++] = "meanDistI_M";
@@ -642,7 +642,7 @@ if (indVarTrfr) {
}
else {
traitnames[trait++] = "meanDistI";
- if (twinKern)
+ if (twinKern)
{
traitnames[trait++] = "meanDistII";
traitnames[trait++] = "probKernI";
@@ -1059,7 +1059,7 @@ void Species::setTrfr(const trfrRules t) {
#endif
moveModel = t.moveModel; stgDepTrfr = t.stgDep; sexDepTrfr = t.sexDep;
distMort = t.distMort; indVarTrfr = t.indVar;
-twinKern = t.twinKern;
+twinKern = t.twinKern;
habMort = t.habMort;
moveType = t.moveType; costMap = t.costMap;
//setGenome();
@@ -1069,7 +1069,7 @@ trfrRules Species::getTrfr(void) {
trfrRules t;
t.moveModel = moveModel; t.stgDep = stgDepTrfr; t.sexDep = sexDepTrfr;
t.distMort = distMort; t.indVar = indVarTrfr;
-t.twinKern = twinKern;
+t.twinKern = twinKern;
t.habMort = habMort;
t.moveType = moveType; t.costMap = costMap;
t.movtTrait[0] = movtTrait[0]; t.movtTrait[1] = movtTrait[1];
@@ -1085,7 +1085,7 @@ bool Species::useFullKernel(void) { return fullKernel; }
void Species::setKernTraits(const short stg,const short sex,
const trfrKernTraits k,const int resol)
{
-if (stg >= 0 && stg < NSTAGES && sex >= 0 && sex < NSEXES) {
+if (stg >= 0 && stg < NSTAGES && sex >= 0 && sex < NSEXES) {
if (k.meanDist1 > 0.0 && k.meanDist1 >= (float)resol) meanDist1[stg][sex] = k.meanDist1;
if (k.meanDist2 >= (float)resol) meanDist2[stg][sex] = k.meanDist2;
if (k.probKern1 > 0.0 && k.probKern1 < 1.0) probKern1[stg][sex] = k.probKern1;
@@ -1414,7 +1414,7 @@ if (stg >= 0 && stg < 1 && sex >= 0 && sex < NSEXES) // implemented for stage 0
if (sex == 0) {
if (s.s0Scale > 0.0 && s.s0Scale < 1.0) s0Scale = s.s0Scale;
if (s.alphaSScale > 0.0) alphaSScale = s.alphaSScale;
- if (s.betaSScale > 0.0) betaSScale = s.betaSScale;
+ if (s.betaSScale > 0.0) betaSScale = s.betaSScale;
}
}
}
diff --git a/RangeShiftR/src/RScore/Species.h b/RangeShiftR/src/RScore/Species.h
index 3f1b100..55dbacf 100644
--- a/RangeShiftR/src/RScore/Species.h
+++ b/RangeShiftR/src/RScore/Species.h
@@ -1,25 +1,25 @@
/*----------------------------------------------------------------------------
- *
- * 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 .
- *
+ *
--------------------------------------------------------------------------*/
-
-
+
+
/*------------------------------------------------------------------------------
RangeShifter v2.0 Species
@@ -31,9 +31,9 @@ AND THIS IS CURRENTLY LIMITED TO A SINGLE SPECIES.
The class holds all the demographic and dispersal parameters of the species.
For full details of RangeShifter, please see:
-Bocedi G., Palmer S.C.F., Pe?er G., Heikkinen R.K., Matsinos Y.G., Watts K.
+Bocedi G., Palmer S.C.F., Peer G., Heikkinen R.K., Matsinos Y.G., Watts K.
and Travis J.M.J. (2014). RangeShifter: a platform for modelling spatial
-eco-evolutionary dynamics and species? responses to environmental changes.
+eco-evolutionary dynamics and species responses to environmental changes.
Methods in Ecology and Evolution, 5, 388-396. doi: 10.1111/2041-210X.12162
Authors: Greta Bocedi & Steve Palmer, University of Aberdeen
@@ -45,20 +45,19 @@ Last updated: 28 July 2021 by Greta Bocedi
#ifndef SpeciesH
#define SpeciesH
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
//#endif
#include "Parameters.h"
-#include
// structures for demographic parameters
struct demogrParams {
- short repType;
+ short repType;
short repSeasons;
float propMales; float harem; float bc; float lambda;
bool stageStruct;
@@ -118,10 +117,10 @@ struct emigScales {
// structures for transfer parameters
struct trfrRules {
- bool moveModel; bool stgDep; bool sexDep;
+ bool moveModel; bool stgDep; bool sexDep;
bool distMort; bool indVar;
- bool twinKern;
- bool habMort;
+ bool twinKern;
+ bool habMort;
short moveType; bool costMap;
short movtTrait[2];
};
@@ -228,7 +227,7 @@ class Species {
float // survival coefficient
);
densDepParams getDensDep(void); // Get development and survival coefficients
-
+
void setFec( // Set fecundity
short, // stage (must be > 0)
short, // sex
@@ -256,7 +255,7 @@ class Species {
short, // stage
short // sex
);
-
+
float getMaxFec(void); // Get highest fecundity of any stage
void setMinAge( // Set minimum age
short, // stage
diff --git a/RangeShiftR/src/RScore/SubCommunity.h b/RangeShiftR/src/RScore/SubCommunity.h
index 3f1266f..ece9281 100644
--- a/RangeShiftR/src/RScore/SubCommunity.h
+++ b/RangeShiftR/src/RScore/SubCommunity.h
@@ -50,9 +50,9 @@ Last updated: 26 October 2021 by Steve Palmer
#include
using namespace std;
-//#if RS_RCPP && !R_CMD
+#if RS_RCPP
#include "../Version.h"
-//#endif
+#endif
//#if !RS_RCPP && R_CMD
//#include "../../Batch/Version.h"
diff --git a/RangeShiftR/src/RScore/Utils.cpp b/RangeShiftR/src/RScore/Utils.cpp
new file mode 100644
index 0000000..9d36b92
--- /dev/null
+++ b/RangeShiftR/src/RScore/Utils.cpp
@@ -0,0 +1,26 @@
+#include "Utils.h"
+
+const string Int2Str(const int x)
+{
+ ostringstream o;
+ if (!(o << x)) return "ERROR";
+ return o.str();
+}
+const string Float2Str(const float x) {
+ ostringstream o;
+ if (!(o << x)) return "ERROR";
+ return o.str();
+}
+const string Double2Str(const double x) {
+ ostringstream o;
+ if (!(o << x)) return "ERROR";
+ return o.str();
+}
+
+// Evaluate a lambda and assert we get the correct error
+void assert_error(const string& exptd_err_msg, void (*lambda)(void)) {
+ string err_msg{ "No error.\n" };
+ try { lambda(); } // evaluate
+ catch (exception& e) { err_msg = e.what(); }
+ assert(err_msg == exptd_err_msg);
+}
\ No newline at end of file
diff --git a/RangeShiftR/src/RScore/Utils.h b/RangeShiftR/src/RScore/Utils.h
new file mode 100644
index 0000000..34854a7
--- /dev/null
+++ b/RangeShiftR/src/RScore/Utils.h
@@ -0,0 +1,18 @@
+#ifndef UtilsH
+#define UtilsH
+
+#include
+#include
+#include
+
+#include
+using namespace std;
+
+const string Int2Str(const int x);
+const string Float2Str(const float x);
+const string Double2Str(const double x);
+
+// Evaluate a lambda and assert we get the correct error
+void assert_error(const string& exptd_err_msg, void (*x)(void));
+
+#endif // UtilsH
diff --git a/RangeShiftR/src/Rinterface.cpp b/RangeShiftR/src/Rinterface.cpp
index 6a597b5..3ee8ca4 100644
--- a/RangeShiftR/src/Rinterface.cpp
+++ b/RangeShiftR/src/Rinterface.cpp
@@ -4066,35 +4066,6 @@ void StreamErrorR(string filename)
/* Batch mode of v2.0 currently has no facility to save maps (unless initiated from GUI).
*/
-const string Int2Str(const int x)
-{
- ostringstream o;
- if(!(o << x))
- return "ERROR";
- return o.str();
-}
-const string Int2Str(const int x, unsigned int width)
-{
- ostringstream o;
- if(!(o << std::setfill('0') << std::setw(width) << x))
- return "ERROR";
- return o.str();
-}
-const string Float2Str(const float x)
-{
- ostringstream o;
- if(!(o << x))
- return "ERROR";
- return o.str();
-}
-const string Double2Str(const double x)
-{
- ostringstream o;
- if(!(o << x))
- return "ERROR";
- return o.str();
-}
-
void MemoLine(string msg)
{
// dummy function for batch version
| |