Type: | Package |
Title: | Representative and Adequate Prioritization Toolkit in R |
Version: | 1.0.1 |
Description: | Biodiversity is in crisis. The overarching aim of conservation is to preserve biodiversity patterns and processes. To this end, protected areas are established to buffer species and preserve biodiversity processes. But resources are limited and so protected areas must be cost-effective. This package contains tools to generate plans for protected areas (prioritizations), using spatially explicit targets for biodiversity patterns and processes. To obtain solutions in a feasible amount of time, this package uses the commercial 'Gurobi' software (obtained from https://www.gurobi.com/). For more information on using this package, see Hanson et al. (2018) <doi:10.1111/2041-210X.12862>. |
Imports: | utils, methods, stats, graphics, grDevices, sp (≥ 1.4.6), Matrix (≥ 1.4.1), assertthat (≥ 0.2.1), boot (≥ 1.3.28), PBSmapping (≥ 2.73.0), scales (≥ 1.2.0), shape (≥ 1.4.6), adehabitatHR (≥ 0.4.19), RColorBrewer (≥ 1.1.3), ggplot2 (≥ 3.4.0), hypervolume (≥ 2.0.7), ks (≥ 1.13.5), mvtnorm (≥ 1.1.3), withr (≥ 2.5.0), |
Depends: | R (≥ 4.0.0), sf (≥ 1.0.9), terra (≥ 1.6.47) |
Suggests: | knitr, roxygen2, rmarkdown, testthat, RgoogleMaps (≥ 1.4.5.3), dplyr (≥ 1.0.8), vegan (≥ 2.6.2), gurobi (≥ 8.0.0), gridExtra (≥ 2.3), rgl (≥ 1.0.1) |
LinkingTo: | Rcpp, RcppEigen, BH |
LazyData: | true |
License: | GPL-3 |
Encoding: | UTF-8 |
Language: | en-US |
URL: | https://jeffrey-hanson.com/raptr/, https://github.com/jeffreyhanson/raptr |
BugReports: | https://github.com/jeffreyhanson/raptr/issues |
VignetteBuilder: | knitr |
Collate: | 'RcppExports.R' 'raptr-internal.R' 'generics.R' 'DemandPoints.R' 'misc.R' 'PlanningUnitPoints.R' 'AttributeSpace.R' 'AttributeSpaces.R' 'GurobiOpts.R' 'ManualOpts.R' 'calcSpeciesAverageInPus.R' 'calcBoundaryData.R' 'RapData.R' 'RapReliableOpts.R' 'RapResults.R' 'RapUnreliableOpts.R' 'RapUnsolved.R' 'RapSolved.R' 'convert2PolySet.R' 'data.R' 'deprecated.R' 'package.R' 'rap.R' 'rrap.proportion.held.R' 'sim.pus.R' 'sim.space.R' 'sim.species.R' 'urap.proportion.held.R' 'zzz.R' |
RoxygenNote: | 7.3.1 |
NeedsCompilation: | yes |
Packaged: | 2024-01-27 20:24:35 UTC; jeff |
Author: | Jeffrey O Hanson [aut, cre], Jonathan R Rhodes [aut], Hugh P Possingham [aut], Richard A Fuller [aut] |
Maintainer: | Jeffrey O Hanson <jeffrey.hanson@uqconnect.edu.au> |
Repository: | CRAN |
Date/Publication: | 2024-01-28 11:20:05 UTC |
raptr: Representative and Adequate Prioritization Toolkit in R
Description
Biodiversity is in crisis. The overarching aim of conservation is to preserve biodiversity patterns and processes. To this end, protected areas are established to buffer species and preserve biodiversity processes. But resources are limited and so protected areas must be cost-effective. This package contains tools to generate plans for protected areas (prioritizations). Conservation planning data are used to construct an optimization problem, which is then solved to yield prioritizations. To solve the optimization problems in a feasible amount of time, this package uses the commercial 'Gurobi' software package (obtained from https://www.gurobi.com/). For more information on using this package, see Hanson et al. (2018).
Details
The main classes used in this package are used to store input data and prioritizations:
- GurobiOpts
parameters for solving optimization problems using Gurobi.
- RapReliableOpts
parameters for the reliable formulation of RAP.
- RapUnreliableOpts
parameters for the unreliable formulation of RAP.
- RapData
planning unit, species data, and demand points for RAP.
- RapUnsolved
contains all the data and input parameters required to generate prioritizations using RAP. This class contains a GurobiOpts object, a RapReliableOpts or RapUnreliableOpts object, and a RapData object.
- RapResults
prioritizations and summary statistics on their performance.
- RapSolved
contains all the input data, parameters and output data. This class contains all the objects in a
RapUnsolved()
object and also a RapResults object.
Type vignette("raptr")
for a tutorial on how to use this package.
Author(s)
Maintainer: Jeffrey O Hanson jeffrey.hanson@uqconnect.edu.au
Authors:
Jonathan R Rhodes
Hugh P Possingham
Richard A Fuller
References
Hanson JO, Rhodes JR, Possingham HP & Fuller RA (2018) raptr: Representative and Adequate Prioritization", Toolkit in R. Methods in Ecology & Evolution,", 9: 320–330. DOI: 10.1111/2041-210X.12862.
See Also
Useful links:
Report bugs at https://github.com/jeffreyhanson/raptr/issues
Create new AttributeSpace object
Description
This function creates a new AttributeSpace
object.
Usage
AttributeSpace(planning.unit.points, demand.points, species)
Arguments
planning.unit.points |
|
demand.points |
|
species |
|
Value
A new AttributeSpace
object.
See Also
DemandPoints, PlanningUnitPoints.
Examples
## Not run:
space <- AttributeSpace(
PlanningUnitPoints(
matrix(rnorm(100), ncol = 2),
seq_len(50)
),
DemandPoints(
matrix(rnorm(100), ncol = 2),
runif(50)
),
species = 1L
)
## End(Not run)
AttributeSpace: An S4 class to represent an attribute space.
Description
This class is used to store planning unit points and demand points for a single species in an attribute space.
Slots
planning.unit.points
PlanningUnitPoints()
object for planning unit in the space.demand.points
DemandPoints()
object for the space.species
integer
species id to indicate which species the space is associated with.
See Also
DemandPoints, PlanningUnitPoints.
Create new AttributeSpaces object
Description
This function creates a new AttributeSpaces
object.
Usage
AttributeSpaces(spaces, name)
Arguments
spaces |
|
name |
|
Value
A new AttributeSpaces
object.
See Also
Examples
## Not run:
space1 <- AttributeSpace(
PlanningUnitPoints(
matrix(rnorm(100), ncol = 2),
seq_len(50)
),
DemandPoints(
matrix(rnorm(100), ncol = 2),
runif(50)
),
species = 1L
)
space2 <- AttributeSpace(
PlanningUnitPoints(
matrix(rnorm(100), ncol = 2),
seq_len(50)
),
DemandPoints(
matrix(rnorm(100), ncol = 2),
runif(50)
),
species = 2L
)
spaces <- AttributeSpaces(list(space1, space2), "spaces")
## End(Not run)
AttributeSpaces: An S4 class to represent a collection of attribute spaces for different species.
Description
This class is used to store a collection of attribute spaces for different species.
Slots
spaces
list
ofAttributeSpace()
objects for different species.name
character
name to identify the attribute space.
See Also
Create new DemandPoints object
Description
This function creates a new DemandPoints
object
Usage
DemandPoints(coords, weights)
Arguments
coords |
|
weights |
|
Value
A new DemandPoints
object.
See Also
Examples
## Not run:
# make demand points
dps <- DemandPoints(
matrix(rnorm(100), ncol=2),
runif(50)
)
# print object
print(dps)
## End(Not run)
DemandPoints: An S4 class to represent demand points
Description
This class is used to store demand point information.
Slots
coords
base::matrix()
of coordinates for each demand point.weights
numeric
weights for each demand point.
See Also
Create GurobiOpts object
Description
This function creates a new GurobiOpts object.
Usage
GurobiOpts(
Threads = 1L,
MIPGap = 0.1,
Method = 0L,
Presolve = 2L,
TimeLimit = NA_integer_,
NumberSolutions = 1L,
MultipleSolutionsMethod = c("benders.cuts", "solution.pool.0", "solution.pool.1",
"solution.pool.2")[1],
NumericFocus = 0L
)
Arguments
Threads |
|
MIPGap |
|
Method |
|
Presolve |
|
TimeLimit |
|
NumberSolutions |
|
MultipleSolutionsMethod |
|
NumericFocus |
|
Value
GurobiOpts
object
See Also
Examples
## Not run:
# create GurobiOpts object using default parameters
GurobiOpts(Threads = 1L, MIPGap = 0.1, Method = 0L, Presolve=2L,
TimeLimit = NA_integer_, NumberSolutions = 1L, NumericFocus = 0L)
## End(Not run)
GurobiOpts: An S4 class to represent Gurobi parameters
Description
This class is used to store Gurobi input parameters.
Slots
Threads
integer
number of cores to use for processing. Defaults to 1L.MIPGap
numeric
MIP gap specifying minimum solution quality. Defaults to 0.1.Method
integer
Algorithm to use for solving model. Defaults to 0L.Presolve
integer
code for level of computation in presolve. Defaults to 2.TimeLimit
integer
number of seconds to allow for solving. Defaults to NA_integer_, and so a time limit is not imposed.NumberSolutions
integer
number of solutions to generate. Defaults to 1L.MultipleSolutionsMethod
integer
name of method to obtain multiple solutions (used whenNumberSolutions
is greater than one). Available options are"benders.cuts"
,"solution.pool.0"
,"solution.pool.1"
, and"solution.pool.2"
. The"benders.cuts"
method produces a set of distinct solutions that are all within the optimality gap. The"solution.pool.0"
method returns all solutions identified whilst trying to find a solution that is within the specified optimality gap. The"solution.pool.1"
method finds one solution within the optimality gap and a number of additional solutions that are of any level of quality (such that the total number of solutions is equal tonumber_solutions
). The"solution.pool.2"
finds a specified number of solutions that are nearest to optimality. The search pool methods correspond to the parameters used by the Gurobi software suite (see https://www.gurobi.com/documentation/8.0/refman/poolsearchmode.html#parameter:PoolSearchMode). Defaults to"benders.cuts"
.NumericFocus
integer
how much effort should Gurobi focus on addressing numerical issues? Defaults to0L
such that minimal effort is spent to reduce run time.
See Also
Create ManualOpts object
Description
This function creates a new ManualOpts object.
Usage
ManualOpts(NumberSolutions = 1L)
Arguments
NumberSolutions |
|
Value
A new ManualOpts()
object
See Also
Examples
## Not run:
# create ManualOpts object
ManualOpts(NumberSolutions = 1L)
## End(Not run)
ManualOpts: An S4 class to represent parameters for manually specified solutions
Description
This class is used to store parameters.
Slots
NumberSolutions
integer
number of solutions.
See Also
Create new PlanningUnitPoints object
Description
This function creates a new PlanningUnitPoints
object.
Usage
PlanningUnitPoints(coords, ids)
Arguments
coords |
|
ids |
|
Value
A new PlanningUnitPoints
object.
See Also
Examples
## Not run:
# create PlanningUnitPoints object
x <- PlanningUnitPoints(matrix(rnorm(150), ncol = 1), seq_len(150))
# print object
print(x)
## End(Not run)
PlanningUnitPoints: An S4 class to represent planning units in an attribute space
Description
This class is used to planning units in an attribute space.
Slots
coords
base::matrix()
coordinates for each point.ids
integer
planning unit ids.
See Also
PolySet
Description
Object contains PolySet data.
See Also
Create new RapData object
Description
This function creates a "RapData" object using pre-processed data.
Usage
RapData(
pu,
species,
targets,
pu.species.probabilities,
attribute.spaces,
boundary,
polygons = NA,
skipchecks = FALSE,
.cache = new.env()
)
Arguments
pu |
|
species |
|
targets |
|
pu.species.probabilities |
|
attribute.spaces |
|
boundary |
|
polygons |
|
skipchecks |
|
.cache |
|
Value
A new RapData
object.
Note
Generally, users are not encouraged to change arguments to
.cache
.
See Also
PBSmapping::PolySet()
, sp::SpatialPoints()
,
sp::SpatialPointsDataFrame()
, make.RapData()
,
RapData.
Examples
## Not run:
# load data
cs_pus <- sf::read_sf(
system.file("extdata", "cs_pus.gpkg", package = "raptr")
)
cs_spp <- terra::rast(
system.file("extdata", "cs_spp.tif", package = "raptr")
)
cs_space <- terra::rast(
system.file("extdata", "cs_space.tif", package = "raptr")
)
# create data for RapData object
attribute.spaces <- list(
AttributeSpaces(name = "geographic", list(
AttributeSpace(
planning.unit.points = PlanningUnitPoints(
suppressWarnings(
sf::st_coordinates(sf::st_centroid(cs_pus[1:10, ]))
),
seq_len(10)
),
demand.points = make.DemandPoints(
randomPoints(cs_spp[[1]], n = 10, prob = TRUE)
),
species = 1L
))
),
AttributeSpaces(name = "environmental", list(
AttributeSpace(
planning.unit.points = PlanningUnitPoints(
as.matrix(terra::extract(
cs_space[[1]], as(cs_pus[1:10, ], "SpatVector"),
fun = "mean",
ID = FALSE
)),
seq_len(10)
),
demand.points = make.DemandPoints(
as.matrix(terra::as.data.frame(cs_space[[1]], na.rm = TRUE))
),
species = 1L
)
))
)
pu.species.probabilities <- calcSpeciesAverageInPus(
cs_pus[1:10,], cs_spp[[1]]
)
polygons <- convert2PolySet(cs_pus[1:10, ])
boundary <- calcBoundaryData(cs_pus[1:10, ])
# create RapData object
x <- RapData(
pu = cs_pus[1:10, ], species = data.frame(name = "test"),
target = data.frame(species = 1L, target = 0:2, proportion = 0.2),
pu.species.probabilities = pu.species.probabilities,
attribute.spaces = attribute.spaces,
polygons = polygons,
boundary = boundary
)
# print object
print(x)
## End(Not run)
RapData: An S4 class to represent RAP input data
Description
This class is used to store RAP input data.
Slots
polygons
PBSmapping::PolySet()
planning unit spatial data orNULL
if data not available.pu
base::data.frame()
planning unit data. Columns must be "cost" (numeric
), "area" (numeric
), and "status" (integer
).species
base::data.frame()
with species data. Columns must be "name" (character
.targets
base::data.frame()
with species data. Columns must be "species" (integer
), "target" (integer
), "proportion" (numeric
).pu.species.probabilities
base::data.frame()
with data on the probability of species in each planning unit. Columns must be "species" (integer
), "pu" (integer
), and "value" (numeric
).attribute.spaces
list
ofAttributeSpaces
objects with the demand points and planning unit coordinates.boundary
base::data.frame()
with data on the shared boundary length of planning units. Columns must be "id1" (integer
), "id2" (integer
), and "boundary" (numeric
).skipchecks
logical
Skip data integrity checks? May improve speed for big data sets..cache
base::environment()
used to cache calculations.
See Also
RapOpts class
Description
Object is either RapReliableOpts()
or
RapUnreliableOpts()
.
Create RapReliableOpts object
Description
This function creates a new RapReliableOpts object.
Usage
RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L)
Arguments
BLM |
|
failure.multiplier |
|
max.r.level |
|
Value
RapReliableOpts
object
See Also
Examples
## Not run:
# create RapReliableOpts using defaults
RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L)
## End(Not run)
RapReliableOpts: An S4 class to represent input parameters for the reliable formulation of RAP.
Description
This class is used to store input parameters for the reliable formulation of RAP.
Slots
BLM
numeric
boundary length modifier. Defaults to 0.failure.multiplier
numeric
multiplier for failure planning unit. Defaults to 1.1.max.r.level
numeric
maximum R failure level for approximation. Defaults to 5L.
See Also
Create RapResults object
Description
This function creates a new RapResults()
object.
Usage
RapResults(
summary,
selections,
amount.held,
space.held,
logging.file,
.cache = new.env()
)
Arguments
summary |
|
selections |
|
amount.held |
|
space.held |
|
logging.file |
|
.cache |
|
Details
The summary
table follows Marxan conventions (
https://marxansolutions.org/). The columns
are:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this column correspond to outputs from the Gurobi software package (https://www.gurobi.com/documentation/6.5/refman/optimization_status_codes.html).
- Score
The objective function for the solution.
- Cost
Total cost associated with a solution.
- Planning_Units
Number of planning units selected in a solution.
- Connectivity_Total
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
- Connectivity_In
The amount of shared boundary length among planning units selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in the solution.
- Connectivity_Out
The number of shared boundary length among planning units not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in the solution (
Connectivity_In
) to the total amount of boundary length (Connectivity_Edge
). This ratio is an indicator of solution quality. Solutions with a lower ratio will have less planning units and will be more efficient.
Value
RapResults
object
Note
slot best
is automatically determined based on data in
summary
.
See Also
RapResults: An S4 class to represent RAP results
Description
This class is used to store RAP results.
Details
The summary
table follows Marxan conventions
(https://marxansolutions.org/). The columns
are:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this column correspond to outputs from the Gurobi software package (https://www.gurobi.com/documentation/6.5/refman/optimization_status_codes.html).
- Score
The objective function for the solution.
- Cost
Total cost associated with a solution.
- Planning_Units
Number of planning units selected in a solution.
- Connectivity_Total
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
- Connectivity_In
The amount of shared boundary length among planning units selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in the solution.
- Connectivity_Out
The number of shared boundary length among planning units not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in the solution (
Connectivity_In
) to the total amount of boundary length (Connectivity_Edge
). This ratio is an indicator of solution quality. Solutions with a lower ratio will have less planning units and will be more efficient.
Slots
summary
base::data.frame()
with summary information on solutions.selections
base::matrix()
with binary selections. The cellx_{ij}
denotes if planning unitj
is selected in thei
'th solution.amount.held
base::matrix()
with the amount held for each species in each solution.space.held
base::matrix()
with the proportion of attribute space sampled for each species in each solution.best
integer
with index of best solution.logging.file
character
Gurobi log files..cache
base::environment()
used to store extra data.
See Also
RapResults()
, read.RapResults()
.
Create new RapSolved object
Description
This function creates a RapSolved()
object.
Usage
RapSolved(unsolved, solver, results)
Arguments
unsolved |
|
solver |
|
results |
|
Value
RapSolved()
object.
See Also
RapSolved, RapResults,
link{solve}
.
RapSolved: An S4 class to represent RAP inputs and outputs
Description
This class is used to store RAP input and output data in addition to input parameters.
Slots
opts
RapReliableOpts()
orRapUnreliableOpts()
object used to store input parameters.solver
GurobiOpts()
orManualOpts()
object used to store solver information/parameters.data
RapData()
object used to store input data.results
RapResults()
object used to store results.
See Also
RapReliableOpts, RapUnreliableOpts, RapData, RapResults.
Create RapUnreliableOpts object
Description
This function creates a new RapUnreliableOpts object.
Usage
RapUnreliableOpts(BLM = 0)
Arguments
BLM |
|
Value
RapUnreliableOpts()
object
See Also
Examples
## Not run:
# create RapUnreliableOpts using defaults
RapUnreliableOpts(BLM = 0)
## End(Not run)
RapUnreliableOpts: An S4 class to represent parameters for the unreliable RAP problem
Description
This class is used to store input parameters for the unreliable RAP problem formulation.
Slots
BLM
numeric
boundary length modifier. Defaults to 0.
Create a new RapUnsolved object
Description
This function creates a RapUnsolved()
object using a
GurobiOpts()
, a RapReliableOpts()
or
RapUnreliableOpts()
object, and a RapData()
object.
Usage
RapUnsolved(opts, data)
Arguments
opts |
|
data |
|
Value
RapUnsolved()
object.
See Also
RapReliableOpts, RapUnreliableOpts, RapData.
Examples
## Not run:
# set random number generator seed
set.seed(500)
# load data
cs_pus <- sf::read_sf(
system.file("extdata", "cs_pus.gpkg", package = "raptr")
)
cs_spp <- terra::rast(
system.file("extdata", "cs_spp.tif", package = "raptr")
)
# create inputs for RapUnsolved
ro <- RapUnreliableOpts()
rd <- make.RapData(cs_pus[seq_len(10), ], cs_spp, NULL,
include.geographic.space = TRUE,n.demand.points = 5L)
# create RapUnsolved object
ru <- RapUnsolved(ro, rd)
# print object
print(ru)
## End(Not run)
RapUnsolved: An S4 class to represent RAP inputs
Description
This class is used to store RAP input data and input parameters.
Slots
opts
RapReliableOpts()
orRapUnreliableOpts()
object used to store input parameters.data
RapData()
object used to store input data.
See Also
RapReliableOpts, RapUnreliableOpts, RapData.
SolverOpts class
Description
Object stores parameters used to solve problems.
See Also
Extract amount held for a solution
Description
This function returns the amount held for each species in a solution.
Usage
amount.held(x, y, species)
## S3 method for class 'RapSolved'
amount.held(x, y = 0, species = NULL)
Arguments
x |
|
y |
Available inputs include: |
species |
|
Value
base::matrix()
or numeric
vector depending on
arguments.
See Also
Examples
## Not run:
# load data
data(sim_rs)
# amount held (%) in best solution for each species
amount.held(sim_rs, 0)
# amount held (%) in best solution for species 1
amount.held(sim_rs, 0, 1)
# amount held (%) in second solution for each species
amount.held(sim_rs, 2)
# amount held (%) in each solution for each species
amount.held(sim_rs, NULL)
## End(Not run)
Amount targets
Description
This function sets or returns the target amounts for each species.
Usage
amount.target(x, species)
amount.target(x, species) <- value
## S3 method for class 'RapData'
amount.target(x, species = NULL)
## S3 replacement method for class 'RapData'
amount.target(x, species = NULL) <- value
## S3 method for class 'RapUnsolOrSol'
amount.target(x, species = NULL)
## S3 replacement method for class 'RapUnsolOrSol'
amount.target(x, species = NULL) <- value
Arguments
x |
|
species |
|
value |
|
Value
numeric
vector.
See Also
RapData()
, RapResults()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_rs)
# extract amount targets for all species
amount.target(sim_rs)
# set amount targets for all species
amount.target(sim_rs) <- 0.1
# extract amount targets for first species
amount.target(sim_rs, 1)
# set amount targets for for first species
amount.target(sim_rs, 1) <- 0.5
## End(Not run)
Convert object to list
Description
Convert GurobiOpts()
object to list.
Usage
## S3 method for class 'GurobiOpts'
as.list(x, ...)
Arguments
x |
|
... |
not used. |
Value
list
Note
This function will not include the NumberSolutions
slot, the
MultipleSolutionsMethod
slot, or the TimeLimit
slot if it is
not finite.
See Also
GurobiOpts
.
Examples
## Not run:
# make GuboriOpts object
x <- GurobiOpts()
# convert to list
as.list(x)
## End(Not run)
Basemap
Description
This function retrieves google map data for planning units. The google map data is cached to provide fast plotting capabilities.
Usage
basemap(x, basemap = "hybrid", grayscale = FALSE, force.reset = FALSE)
## S3 method for class 'RapData'
basemap(x, basemap = "hybrid", grayscale = FALSE, force.reset = FALSE)
## S3 method for class 'RapSolved'
basemap(x, basemap = "none", grayscale = FALSE, force.reset = FALSE)
Arguments
x |
|
basemap |
|
grayscale |
|
force.reset |
|
Value
list
with google map data.
See Also
RgoogleMaps::GetMap.bbox()
, plot()
.
Blank raster
Description
This functions creates a blank SpatRaster
based on the spatial extent of a
sf
object.
Usage
blank.raster(x, res)
Arguments
x |
|
res |
|
Examples
## Not run:
# make sf data
polys <- sim.pus(225L)
# make raster from sf
blank.raster(polys, 1)
## End(Not run)
Get and set cache methods
Description
Getter and setter methods for caches in RapData and RapResults object.
Usage
cache(x, name, y)
## S4 method for signature 'RapData,character,ANY'
cache(x, name, y)
## S4 method for signature 'RapData,character,missing'
cache(x, name, y)
## S4 method for signature 'RapResults,character,ANY'
cache(x, name, y)
## S4 method for signature 'RapResults,character,missing'
cache(x, name, y)
Arguments
x |
|
name |
|
y |
if |
Value
ANY
or NULL
depends on y
argument.
Note
caches are implemented using environments, the hash is used as the name of the object in the environment.
Calculate boundary data for planning units
Description
This function calculates boundary length data. Be aware that this function is designed with performance in mind, and as a consequence, if this function is used improperly then it may crash R. Furthermore, multipart polygons with touching edges will likely result in inaccuracies.
Usage
calcBoundaryData(x, tol, length.factor, edge.factor)
## S3 method for class 'PolySet'
calcBoundaryData(x, tol = 0.001, length.factor = 1, edge.factor = 1)
## S3 method for class 'SpatialPolygons'
calcBoundaryData(x, tol = 0.001, length.factor = 1, edge.factor = 1)
## S3 method for class 'sf'
calcBoundaryData(x, tol = 0.001, length.factor = 1, edge.factor = 1)
Arguments
x |
|
tol |
|
length.factor |
|
edge.factor |
|
Value
A data.frame
with 'id1' (integer
), 'id2'
(integer
), and 'amount' (numeric
) columns.
See Also
This function is based on the algorithm in QMARXAN https://github.com/tsw-apropos/qmarxan for calculating boundary length.
Examples
## Not run:
# simulate planning units
sim_pus <- sim.pus(225L)
# calculate boundary data
bound.dat <- calcBoundaryData(sim_pus)
# print summary of boundary data
summary(bound.dat)
## End(Not run)
Calculate average value for species data in planning units
Description
This function calculates the average of species values in each planning unit. By default all polygons will be treated as having separate ids.
Usage
calcSpeciesAverageInPus(x, ...)
## S3 method for class 'SpatialPolygons'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), ...)
## S3 method for class 'SpatialPolygonsDataFrame'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), field = NULL, ...)
## S3 method for class 'sf'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), field = NULL, ...)
Arguments
x |
|
... |
not used. |
y |
|
ids |
|
field |
|
Value
A base::data.frame()
object.
Note
Although earlier versions of the package had an additional ncores
parameter, this parameter has been deprecated.
Examples
## Not run:
# simulate data
sim_pus <- sim.pus(225L)
sim_spp <- terra::rast(
lapply(c("uniform", "normal", "bimodal"),
sim.species, n = 1, res = 1, x = sim_pus)
)
# calculate average for 1 species
puvspr1.dat <- calcSpeciesAverageInPus(sim_pus, sim_spp[[1]])
# calculate average for multiple species
puvspr2.dat <- calcSpeciesAverageInPus(sim_pus, sim_spp)
## End(Not run)
Case-study dataset for a conservation planning exercise
Description
This dataset contains data to generate example prioritizations for the pale-headed Rosella (Platycercus adscitus) in Queensland, Australia.
Format
"cs_pus.gpkg"
Geopackage file
"cs_species.tif"
GeoTIFF file.
"cs_space.tif"
GeoTIFF file.
Details
The objects in the dataset are listed below.
"cs_pus.gpkg"
Geopackage file containing planning units. The units were generated as
30km^2
squares across the species' range, and then clipped to the Queensland, Australia (using data obtained from the Australia Bureau of Statistics; https://www.abs.gov.au/ausstats/abs@.nsf/mf/1259.0.30.001?OpenDocument). They were then overlaid with Australia's protected area network (obtained from the World Database on Protected Areas (WDPA) at https://www.protectedplanet.net/en). This attribute table has 3 fields. Thearea
field denotes the amount of land encompassed by each unit, thecost
field is set to 1 for all units, and thestatus
field indicates if 50% or more of the units' extent is covered by protected areas."cs_spp.tif"
GeoTIFF file containing probability distribution map for the P. adscitus clipped to Queensland, Australia. This map was derived from records obtained from The Atlas of Living Australia.
"cs_space.tif"
GeoTIFF file describing broad-scale climate variation across Queensland (obtained from https://worldclim.org/, and resampled to
10km^2
resolution).
Examples
## Not run:
# load data
cs_pus <- sf::read_sf(
system.file("extdata", "cs_pus.gpkg", package = "raptr")
)
cs_spp <- terra::rast(
system.file("extdata", "cs_spp.tif", package = "raptr")
)
cs_space <- terra::rast(
system.file("extdata", "cs_space.tif", package = "raptr")
)
# plot data
plot(cs_pus)
plot(cs_spp)
plot(cs_space)
## End(Not run)
Convert object to PolySet data
Description
This function converts sf::st_sf()
and
sp::SpatialPolygonsDataFrame()
objects to
PBSmapping::PolySet()
objects.
Usage
convert2PolySet(x, n_preallocate)
## S3 method for class 'SpatialPolygonsDataFrame'
convert2PolySet(x, n_preallocate = 10000L)
## S3 method for class 'SpatialPolygons'
convert2PolySet(x, n_preallocate = 10000L)
## S3 method for class 'sf'
convert2PolySet(x, n_preallocate = 10000L)
Arguments
x |
|
n_preallocate |
|
Value
PBSmapping::PolySet()
object.
Note
Be aware that this function is designed to be as fast as possible, but as a result it depends on C++ code and if used inappropriately this function will crash R.
See Also
For a slower, more stable equivalent see
maptools::SpatialPolygons2PolySet
.
Examples
## Not run:
# generate sf object
sim_pus <- sim.pus(225L)
# convert to PolySet
x <- convert2PolySet(sim_pus)
## End(Not run)
Subset demand points
Description
Subset demand points from a RapData()
,
RapUnsolved()
, or RapSolved()
object.
Usage
dp.subset(x, space, species, points)
## S3 method for class 'RapData'
dp.subset(x, space, species, points)
## S3 method for class 'RapUnsolOrSol'
dp.subset(x, space, species, points)
Arguments
x |
|
space |
|
species |
|
points |
|
Value
RapData()
or RapUnsolved()
object depending
on input object.
See Also
RapData()
, RapUnsolved()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru)
# generate new object with first 10 planning units
sim_ru2 <- dp.subset(sim_ru, 1, 1, seq_len(10))
## End(Not run)
Test if Gurobi is installed
Description
This function determines if the Gurobi R package is installed on the
computer and that it can be used base::options()
.
Usage
is.GurobiInstalled(verbose = TRUE)
Arguments
verbose |
|
Value
logical
Is it installed and ready to use?
See Also
Examples
## Not run:
# check if Gurobi is installed
is.GurobiInstalled()
# print cached status of installation
options()$GurobiInstalled
## End(Not run)
Test if hash is cached in a Rap object
Description
Tests if hash is cached in Rap object.
Usage
is.cached(x, name)
## S4 method for signature 'RapData,character'
is.cached(x, name)
## S4 method for signature 'RapResults,character'
is.cached(x, name)
Arguments
x |
|
name |
|
Value
logical
Is it cached?
Note
caches are implemented using environments, the hash is used as the name of the object in the environment.
Compare Rap objects
Description
This function checks objects to see if they share the same input data.
Usage
is.comparable(x, y)
## S4 method for signature 'RapData,RapData'
is.comparable(x, y)
## S4 method for signature 'RapUnsolOrSol,RapUnsolOrSol'
is.comparable(x, y)
## S4 method for signature 'RapData,RapUnsolOrSol'
is.comparable(x, y)
## S4 method for signature 'RapUnsolOrSol,RapData'
is.comparable(x, y)
Arguments
x |
|
y |
|
Value
logical
are the objects based on the same data?
See Also
RapData, RapUnsolved, RapSolved.
Log file
Description
This function returns the Gurobi log file (*.log) associated with solving an optimization problem.
Usage
logging.file(x, y)
## S3 method for class 'RapResults'
logging.file(x, y = 0)
## S3 method for class 'RapSolved'
logging.file(x, y = 0)
Arguments
x |
|
y |
Available inputs include: |
Note
The term logging file was used due to collisions with the log
function.
See Also
Examples
## Not run:
# load data
data(sim_rs)
# log file for the best solution
cat(logging.file(sim_rs, 0))
# log file for the second solution
cat(logging.file(sim_rs, 2))
# log files for all solutions
cat(logging.file(sim_rs, NULL))
## End(Not run)
Generate demand points for RAP
Description
This function generates demand points to characterize a distribution of points.
Usage
make.DemandPoints(
points,
n = 100L,
quantile = 0.5,
kernel.method = c("ks", "hypervolume")[1],
...
)
Arguments
points |
|
n |
|
quantile |
|
kernel.method |
|
... |
arguments passed to kernel density estimating functions |
Details
Broadly speaking, demand points are generated by fitting a kernal
to the input points
. A shape is then fit to the extent of
the kernal, and then points are randomly generated inside the shape. The
demand points are generated as random points inside the shape. The weights
for each demand point are calculated the estimated density of input points
at the demand point. By supplying 'ks' as an argument to method
in
kernel.method
, the shape is defined using a minimum convex polygon
adehabitatHR::mcp()
and ks::kde()
is used to fit
the kernel. Note this can only be used when the data is low-dimensional (d
< 3). By supplying "hypervolume"
as an argument to method
,
the hypervolume::hypervolume()
function is used to create the
demand points. This method can be used for hyper-dimensional data
(d << 3
).
Value
A new DemandPoints()
object.
See Also
hypervolume::hypervolume()
, ks::kde()
,
adehabitatHR::mcp()
.
Examples
## Not run:
# set random number generator seed
set.seed(500)
# load data
cs_spp <- terra::rast(
system.file("extdata", "cs_spp.tif", package = "raptr")
)
cs_space <- terra::rast(
system.file("extdata", "cs_space.tif", package = "raptr")
)
# generate species points
species.points <- randomPoints(cs_spp[[1]], n = 100, prob = TRUE)
env.points <- as.matrix(terra::extract(cs_space, species.points))
# generate demand points for a 1d space using ks
dps1 <- make.DemandPoints(points = env.points[, 1], kernel.method = "ks")
# print object
print(dps1)
# generate demand points for a 2d space using hypervolume
dps2 <- make.DemandPoints(
points = env.points,
kernel.method = "hypervolume",
samples.per.point = 50,
verbose = FALSE
)
# print object
print(dps2)
## End(Not run)
Make data for RAP using minimal inputs
Description
This function prepares spatially explicit planning unit, species data, and landscape data layers for RAP processing.
Usage
make.RapData(
pus,
species,
spaces = NULL,
amount.target = 0.2,
space.target = 0.2,
n.demand.points = 100L,
kernel.method = c("ks", "hypervolume")[1],
quantile = 0.5,
species.points = NULL,
n.species.points = ceiling(0.2 * terra::global(species, "sum", na.rm = TRUE)[[1]]),
include.geographic.space = TRUE,
scale = TRUE,
verbose = FALSE,
...
)
Arguments
pus |
|
species |
|
spaces |
|
amount.target |
|
space.target |
|
n.demand.points |
|
kernel.method |
|
quantile |
|
species.points |
|
n.species.points |
|
include.geographic.space |
|
scale |
|
verbose |
|
... |
additional arguments to |
Value
A new RapData
object.
See Also
Examples
## Not run:
# load data
cs_pus <- sf::read_sf(
system.file("extdata", "cs_pus.gpkg", package = "raptr")
)
cs_spp <- terra::rast(
system.file("extdata", "cs_spp.tif", package = "raptr")
)
cs_space <- terra::rast(
system.file("extdata", "cs_space.tif", package = "raptr")
)
# make RapData object using the first 10 planning units in the dat
x <- make.RapData(cs_pus[1:10,], cs_spp, cs_space,
include.geographic.space = TRUE)
# print object
print(x)
## End(Not run)
Maximum targets
Description
This function accepts a RapUnsolved()
object and returns a
data.frame
containing the amount-based and space-based targets for
each species and attribute space. These are calculated using a
prioritization that contains all the available planning units. Note that the
maximum amount-based targets are always 1.
Usage
maximum.targets(x, verbose)
## S3 method for class 'RapUnsolOrSol'
maximum.targets(x, verbose = FALSE)
Arguments
x |
|
verbose |
|
Value
data.frame
object.
Examples
## Not run:
# load RapSolved objects
data(sim_ru)
# calculate maximum metrics
maximum.targets(sim_ru)
## End(Not run)
Names
Description
This function sets or returns the species names in an object.
Usage
## S3 replacement method for class 'RapData'
names(x) <- value
## S3 method for class 'RapData'
names(x)
## S3 replacement method for class 'RapUnsolOrSol'
names(x) <- value
## S3 method for class 'RapUnsolOrSol'
names(x)
Arguments
x |
|
value |
new species names. |
See Also
RapData()
, RapUnsolved()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_rs)
# show names
names(sim_rs)
# change names
names(sim_rs) <- c('spp1', 'spp2', 'spp3')
# show new names
names(sim_rs)
## End(Not run)
Plot object
Description
This function plots the solutions contained in RapSolved()
objects. It can be used to show a single solution, or the the selection
frequencies of planning units contained in a single RapSolved()
object. Additionally, two RapSolved()
objects can be supplied to
plot the differences between them.
Usage
## S4 method for signature 'RapSolved,numeric'
plot(x, y, basemap = "none",
pu.color.palette = c("#e5f5f9", "#00441b", "#FFFF00", "#FF0000"), alpha =
ifelse(basemap == "none", 1, 0.7), grayscale = FALSE, main = NULL,
force.reset = FALSE)
## S4 method for signature 'RapSolved,missing'
plot(x, y, basemap = "none",
pu.color.palette = c("PuBu", "#FFFF00", "#FF0000"),
alpha = ifelse(basemap == "none", 1, 0.7),
grayscale = FALSE, main = NULL,
force.reset = FALSE)
## S4 method for signature 'RapSolved,RapSolved'
plot(x, y, i = NULL, j = i,
basemap = "none",
pu.color.palette = ifelse(is.null(i), c("RdYlBu", "#FFFF00",
"#FF0000"), "Accent"),
alpha = ifelse(basemap == "none", 1, 0.7),
grayscale = FALSE, main = NULL, force.reset = FALSE)
Arguments
x |
|
y |
Available inputs are: |
basemap |
|
pu.color.palette |
|
alpha |
|
grayscale |
|
main |
|
force.reset |
|
i |
Available inputs are: |
j |
Available inputs are: |
Details
This function requires the RgoogleMaps package to be installed in order to create display a basemap.
See Also
Examples
## Not run:
# load example data set with solutions
data(sim_rs)
# plot selection frequencies
plot(sim_rs)
# plot best solution
plot(sim_rs, 0)
# plot second solution
plot(sim_rs, 2)
# plot different between best and second solutions
plot(sim_rs, sim_rs, 0 ,2)
## End(Not run)
Print objects
Description
Prints objects.
Usage
## S3 method for class 'AttributeSpace'
print(x, ..., header = TRUE)
## S3 method for class 'AttributeSpaces'
print(x, ..., header = TRUE)
## S3 method for class 'GurobiOpts'
print(x, ..., header = TRUE)
## S3 method for class 'ManualOpts'
print(x, ..., header = TRUE)
## S3 method for class 'RapData'
print(x, ..., header = TRUE)
## S3 method for class 'RapReliableOpts'
print(x, ..., header = TRUE)
## S3 method for class 'RapResults'
print(x, ..., header = TRUE)
## S3 method for class 'RapUnreliableOpts'
print(x, ..., header = TRUE)
## S3 method for class 'RapUnsolved'
print(x, ...)
## S3 method for class 'RapSolved'
print(x, ...)
Arguments
x |
|
... |
not used. |
header |
|
See Also
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, RapResults()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru, sim_rs)
# print GurobiOpts object
print(GurobiOpts())
# print RapReliableOpts object
print(RapReliableOpts())
# print RapUnreliableOpts object
print(RapUnreliableOpts())
# print RapData object
print(sim_ru@data)
# print RapUnsolved object
print(sim_ru)
# print RapResults object
print(sim_rs@results)
# print RapSolved object
print(sim_rs)
## End(Not run)
Subset probabilities above a threshold
Description
This function subsets out probabilities assigned to planning units above a threshold. It effectively sets the probability that species inhabit planning units to zero if they are below the threshold.
Usage
prob.subset(x, species, threshold)
## S3 method for class 'RapData'
prob.subset(x, species, threshold)
## S3 method for class 'RapUnsolOrSol'
prob.subset(x, species, threshold)
Arguments
x |
|
species |
|
threshold |
|
Value
RapData()
or RapUnsolved()
object depending
on input object.
See Also
RapData()
, RapUnsolved()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru)
# generate new object with first 10 planning units
sim_ru2 <- prob.subset(sim_ru, seq_len(3), c(0.1, 0.2, 0.3))
## End(Not run)
Subset planning units
Description
Subset planning units from a RapData()
,
RapUnsolved()
, or RapSolved()
object.
Usage
pu.subset(x, pu)
## S3 method for class 'RapData'
pu.subset(x, pu)
## S3 method for class 'RapUnsolOrSol'
pu.subset(x, pu)
Arguments
x |
|
pu |
|
Value
RapData()
or RapUnsolved()
object depending
on input object.
See Also
RapData()
, RapUnsolved()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru)
# generate new object with first 10 planning units
sim_ru2 <- pu.subset(sim_ru, seq_len(10))
## End(Not run)
Sample random points from a SpatRaster
Description
This function generates random points in a terra::rast()
object.
Usage
randomPoints(mask, n, prob = FALSE)
Arguments
mask |
|
n |
|
prob |
|
Value
base::matrix()
with x-coordinates, y-coordinates, and
cell values.
See Also
This function is similar to dismo::randomPoints
.
Examples
## Not run:
# simulate data
sim_pus <- sim.pus(225L)
sim_spp <- sim.species(sim_pus, model = "normal", n = 1, res = 0.25)
# generate points
pts1 <- randomPoints(sim_spp, n = 5)
pts2 <- randomPoints(sim_spp, n = 5, prob = TRUE)
# plot points
plot(sim_spp)
points(pts1, col = "red")
points(pts2, col = "black")
## End(Not run)
Generate prioritizations using RAP
Description
This is a general function to create Rap objects from scratch and solve them to generate solutions.
Usage
rap(
pus,
species,
spaces = NULL,
formulation = c("unreliable", "reliable")[1],
solve = TRUE,
...
)
Arguments
pus |
|
species |
|
spaces |
|
formulation |
|
solve |
|
... |
arguments are passed to |
Value
A new RapSolved()
object if solve
is TRUE
,
otherwise an RapUnsolved()
is returned.
Note
Type vignette("raptr")
to see the package vignette for a
tutorial.
See Also
GurobiOpts()
, RapReliableOpts()
,
RapUnreliableOpts()
RapData()
,
RapResults()
, RapUnsolved()
,
RapSolved()
.
Deprecation notice
Description
The functions listed here are deprecated. This means that they once existed in earlier versions of the of the raptr package, but they have since been removed entirely, replaced by other functions, or renamed as other functions in newer versions. To help make it easier to transition to new versions of the raptr package, we have listed alternatives for deprecated the functions (where applicable). If a function is described as being renamed, then this means that only the name of the function has changed (i.e., the inputs, outputs, and underlying code remain the same).
Usage
SpatialPolygons2PolySet(...)
Arguments
... |
not used. |
Details
The following functions have been deprecated:
SpatialPolygons2PolySet()
renamed as the
convert2PolySet()
function.
Read RAP results
Description
This function reads files output from Gurobi and returns a RapResults
object.
Usage
read.RapResults(
opts,
data,
model.list,
logging.file,
solution.list,
verbose = FALSE
)
Arguments
opts |
|
data |
|
model.list |
|
logging.file |
|
solution.list |
|
verbose |
|
Value
RapResults
object
See Also
RapReliableOpts()
, RapUnreliableOpts()
,
RapData()
, RapResults()
.
Proportion held using reliable RAP formulation.
Description
This is a convenience function to quickly calculate the proportion of variation that one set of points captures in a another set of points using the reliable formulation.
Usage
rrap.proportion.held(
pu.coordinates,
pu.probabilities,
dp.coordinates,
dp.weights,
failure.distance,
maximum.r.level = as.integer(length(pu.probabilities))
)
Arguments
pu.coordinates |
|
pu.probabilities |
|
dp.coordinates |
|
dp.weights |
|
failure.distance |
|
maximum.r.level |
|
Value
numeric
value indicating the proportion of variation that the
demand points explain in the planning units
Examples
## Not run:
rrap.proportion.held(as.matrix(iris[1:2,-5]), runif(1:2),
as.matrix(iris[1:5,-5]), runif(1:5), 10)
## End(Not run)
Solution score
Description
Extract solution score from RapResults()
or
RapSolved()
object.
Usage
score(x, y)
## S3 method for class 'RapResults'
score(x, y = 0)
## S3 method for class 'RapSolved'
score(x, y = 0)
Arguments
x |
|
y |
Available inputs include: |
Value
matrix
or numeric
vector with solution score(s)
depending on arguments.
See Also
Examples
## Not run:
# load data
data(sim_rs)
# score for the best solution
score(sim_rs, 0)
# score for the second solution
score(sim_rs, 2)
# score for all solutions
score(sim_rs, NULL)
## End(Not run)
Extract solution selections
Description
Extract selections for a given solution from a RapResults()
or
RapSolved()
object.
Usage
selections(x, y)
## S3 method for class 'RapResults'
selections(x, y = 0)
## S3 method for class 'RapSolved'
selections(x, y = 0)
Arguments
x |
|
y |
|
Value
base::matrix()
or numeric
vector depending on
arguments.
See Also
Examples
## Not run:
# load data
data(sim_rs)
# selections for the best solution
selections(sim_rs, 0)
# selections for the second solution
selections(sim_rs, 2)
# selections for each solution
selections(sim_rs)
## End(Not run)
Show objects
Description
Shows objects.
Usage
## S4 method for signature 'GurobiOpts'
show(object)
## S4 method for signature 'ManualOpts'
show(object)
## S4 method for signature 'RapData'
show(object)
## S4 method for signature 'RapReliableOpts'
show(object)
## S4 method for signature 'RapResults'
show(object)
## S4 method for signature 'RapUnreliableOpts'
show(object)
## S4 method for signature 'RapUnsolved'
show(object)
## S4 method for signature 'RapSolved'
show(object)
Arguments
object |
|
See Also
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, RapResults()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru, sim_rs)
# show GurobiOpts object
GurobiOpts()
# show RapReliableOpts object
RapReliableOpts()
# show RapUnreliableOpts object
RapUnreliableOpts()
# show RapData object
sim_ru@data
# show RapUnsolved object
sim_ru
# show RapResults object
sim_rs@results
# show RapSolved object
sim_rs
## End(Not run)
Simulate planning units
Description
This function simulates planning units for RAP.
Usage
sim.pus(
n,
xmn = -sqrt(n)/2,
xmx = sqrt(n)/2,
ymn = -sqrt(n)/2,
ymx = sqrt(n)/2
)
Arguments
n |
|
xmn |
|
xmx |
|
ymn |
|
ymx |
|
Details
Square planning units are generated in the shape of a square.
Default coordinate arguments are such that the planning units will be
centered at origin. The data slot contains an "id" (integer
),
"cost" (numeric
), "status" (integer
), and "area"
(numeric
).
Value
sf::st_as_sf()
with planning units.
Examples
## Not run:
# generate 225 square planning units arranged in a square
# with 1 unit height / width
x <- sim.pus(225)
# generate 225 rectangular pus arranged in a square
y <- sim.pus(225, xmn = -5, xmx = 10, ymn = -5, ymx = 5)
par(mfrow = c(1, 2))
plot(x, main = "x")
plot(y, main = "y")
par(mfrow = c(1, 1))
## End(Not run)
Simulate attribute space data for RAP
Description
This function simulates attribute space data for RAP.
Usage
sim.space(x, ...)
## S3 method for class 'SpatRaster'
sim.space(x, d = 2, model = 0.2, ...)
## S3 method for class 'SpatialPolygons'
sim.space(x, res, d = 2, model = 0.2, ...)
## S3 method for class 'sf'
sim.space(x, res, d = 2, model = 0.2, ...)
Arguments
x |
|
... |
not used. |
d |
|
model |
|
res |
|
Value
terra::rast()
with layers for each dimension of the space.
Examples
## Not run:
# simulate planning units
sim_pus <- sim.pus(225L)
# simulate 1d space using SpatRaster
s1 <- sim.space(blank.raster(sim_pus, 1), d = 1)
# simulate 1d space using sf
s2 <- sim.space(sim_pus, res = 1, d = 1)
# simulate 2d space using sf
s3 <- sim.space(sim_pus, res = 1, d = 2)
# plot simulated spaces
par(mfrow = c(2,2))
plot(s1, main = "s1")
plot(s2, main = "s2")
plot(s3[[1]], main = "s3: first dimension")
plot(s3[[2]], main = "s3: second dimension")
## End(Not run)
Simulate species distribution data for RAP
Description
This function simulates species distributions for RAP.
Usage
sim.species(x, ...)
## S3 method for class 'SpatRaster'
sim.species(x, n = 1, model = "normal", ...)
## S3 method for class 'SpatialPolygons'
sim.species(x, res, n = 1, model = "normal", ...)
## S3 method for class 'sf'
sim.species(x, res, n = 1, model = "normal", ...)
Arguments
x |
|
... |
not used. |
n |
|
model |
|
res |
|
Value
terra::rast()
with layers for each species.
Examples
## Not run:
# make polygons
sim_pus <- sim.pus(225L)
# simulate 1 uniform species distribution using SpatRaster
s1 <- sim.species(blank.raster(sim_pus, 1), n = 1, model = "uniform")
# simulate 1 uniform species distribution based on sf
s2 <- sim.species(sim_pus, res = 1, n = 1, model = "uniform")
# simulate 1 normal species distributions
s3 <- sim.species(sim_pus, res = 1, n = 1, model = "normal")
# simulate 1 bimodal species distribution
s4 <- sim.species(sim_pus, res = 1, n = 1, model = "bimodal")
# simulate 1 species distribution using a random field
s5 <- sim.species(sim_pus, res = 1, n = 1, model = 0.2)
# plot simulations
par(mfrow = c(2,2))
plot(s2, main = "constant")
plot(s3, main = "normal")
plot(s4, main = "bimodal")
plot(s5, main = "random field")
## End(Not run)
Simulated dataset for a conservation planning exercise
Description
This dataset contains all the data needed to generate prioritizations for three simulated species. This dataset contains planning units, species distribution maps, and demand points for each species. For the purposes of exploring the behaviour of the problem, demand points were generated using the centroids of planning units and the probability that they are occupied by the species. Note that methodology is not encouraged for real-world conservation planning.
Format
- sim_ru
RapUnsolved()
object with all the simulated data.- sim_rs
RapSolved()
object with 5 near-optimal solutions.
Details
The species were simulated to represent various simplified species distributions.
- uniform
This species has an equal probability (0.5) of occurring in all planning units.
- normal
This species has a single range-core where it is most likely to be found. It is less likely to be found in areas further away from the center of its range.
- bimodal
This species has two distinct ecotypes. Each ecotype has its own core and marginal area.
Examples
## Not run:
# load data
data(sim_ru, sim_rs)
# plot species distributions
spp.plot(sim_ru, 1)
spp.plot(sim_ru, 2)
spp.plot(sim_ru, 3)
# plot selection frequencies
plot(sim_rs)
# plot best solution
plot(sim_rs, 0)
## End(Not run)
Solve RAP object
Description
This function uses Gurobi to find prioritizations using the input parameter
and data stored in a RapUnsolved()
object, and returns a
RapSolved()
object with outputs in it.
Usage
## S4 method for signature 'RapUnsolOrSol,missing'
solve(a, b, ..., verbose = FALSE)
## S4 method for signature 'RapUnsolOrSol,GurobiOpts'
solve(a, b, verbose = FALSE)
## S4 method for signature 'RapUnsolOrSol,matrix'
solve(a, b, verbose = FALSE)
## S4 method for signature 'RapUnsolOrSol,numeric'
solve(a, b, verbose = FALSE)
## S4 method for signature 'RapUnsolOrSol,logical'
solve(a, b, verbose = FALSE)
Arguments
a |
|
b |
|
... |
not used. |
verbose |
|
Value
RapSolved()
object
Note
This function is used to solve a RapUnsolved()
object that
has all of its inputs generated. The rap function (without lower case 'r')
provides a more general interface for generating inputs and outputs.
See Also
Examples
## Not run:
# load RapUnsolved object
data(sim_ru)
# solve it using Gurobi
sim_rs <- solve(sim_ru)
# evaluate manually specified solution using planning unit indices
sim_rs2 <- solve(sim_ru, seq_len(10))
# evaluate manually specifed solution using binary selections
sim_rs3 <- solve(sim_ru, c(rep(TRUE, 10), rep(FALSE, 90)))
# evaluate multiple manually specified solutions
sim_rs4 <- solve(sim_ru, matrix(sample(c(0, 1), size = 500, replace = TRUE),
ncol = 100, nrow = 5))
## End(Not run)
Extract attribute space held for a solution
Description
This function returns the attribute space held for each species in a solution.
Usage
space.held(x, y, species, space)
## S3 method for class 'RapSolved'
space.held(x, y = 0, species = NULL, space = NULL)
Arguments
x |
|
y |
Available inputs include: |
species |
|
space |
|
Value
matrix
object.
See Also
Examples
## Not run:
# load data
data(sim_rs)
# space held (%) for each species in best solution
space.held(sim_rs, 0)
# space held (%) for each species in second solution
space.held(sim_rs, 2)
# space held (%) for each species in each solution
space.held(sim_rs)
## End(Not run)
Plot space
Description
This function plots the distribution of planning units and the distribution of demand points for a particular species in an attribute space. Note that this function only works for attribute spaces with one, two, or three dimensions.
Usage
space.plot(x, species, space, ...)
## S3 method for class 'RapData'
space.plot(
x,
species,
space = 1,
pu.color.palette = c("#4D4D4D4D", "#00FF0080", "#FFFF0080", "#FF00004D"),
main = NULL,
...
)
## S3 method for class 'RapUnsolved'
space.plot(
x,
species,
space = 1,
pu.color.palette = c("#4D4D4D4D", "#00FF0080", "#FFFF0080", "#FF00004D"),
main = NULL,
...
)
## S3 method for class 'RapSolved'
space.plot(
x,
species,
space = 1,
y = 0,
pu.color.palette = c("#4D4D4D4D", "#00FF0080", "#FFFF0080", "#FF00004D"),
main = NULL,
...
)
Arguments
x |
|
species |
|
space |
|
... |
not used. |
pu.color.palette |
|
main |
|
y |
|
Examples
## Not run:
# load RapSolved objects
data(sim_ru, sim_rs)
# plot first species in first attribute space
space.plot(sim_ru, 1, 1)
# plot distribution of solutions for first species in first attribute space
space.plot(sim_rs, 1, 1)
## End(Not run)
Attribute space targets
Description
This function sets or returns the attribute space targets for each species.
Usage
space.target(x, species, space)
space.target(x, species, space) <- value
## S3 method for class 'RapData'
space.target(x, species = NULL, space = NULL)
## S3 replacement method for class 'RapData'
space.target(x, species = NULL, space = NULL) <- value
## S3 method for class 'RapUnsolOrSol'
space.target(x, species = NULL, space = NULL)
## S3 replacement method for class 'RapUnsolOrSol'
space.target(x, species = NULL, space = NULL) <- value
Arguments
x |
|
species |
|
space |
|
value |
|
Value
A numeric
or matrix
objects.
See Also
RapData()
, RapResults()
, RapSolved()
.
Examples
## Not run:
# load data
data(sim_rs)
# extract space targets for all species
space.target(sim_rs)
# set space targets for all species
space.target(sim_rs) <- 0.1
# extract target for first species for first space
space.target(sim_rs, 1, 1)
# set space targets for first species for first space
space.target(sim_rs, 1, 1) <- 0.5
## End(Not run)
Plot species
Description
This function plots the distribution of species across the study area.
Usage
spp.plot(x, species, ...)
## S3 method for class 'RapData'
spp.plot(
x,
species,
prob.color.palette = "YlGnBu",
pu.color.palette = c("#4D4D4D", "#00FF00", "#FFFF00", "#FF0000"),
basemap = "none",
alpha = ifelse(identical(basemap, "none"), 1, 0.7),
grayscale = FALSE,
main = NULL,
force.reset = FALSE,
...
)
## S3 method for class 'RapUnsolved'
spp.plot(
x,
species,
prob.color.palette = "YlGnBu",
pu.color.palette = c("#4D4D4D", "#00FF00", "#FFFF00", "#FF0000"),
basemap = "none",
alpha = ifelse(basemap == "none", 1, 0.7),
grayscale = FALSE,
main = NULL,
force.reset = FALSE,
...
)
## S3 method for class 'RapSolved'
spp.plot(
x,
species,
y = 0,
prob.color.palette = "YlGnBu",
pu.color.palette = c("#4D4D4D", "#00FF00", "#FFFF00", "#FF0000"),
basemap = "none",
alpha = ifelse(basemap == "none", 1, 0.7),
grayscale = FALSE,
main = NULL,
force.reset = FALSE,
...
)
Arguments
x |
|
species |
|
... |
not used. |
prob.color.palette |
|
pu.color.palette |
|
basemap |
|
alpha |
|
grayscale |
|
main |
|
force.reset |
|
y |
|
Details
This function requires the RgoogleMaps package to be installed in order to create display a basemap.
Examples
## Not run:
# load RapSolved objects
data(sim_ru, sim_rs)
# plot first species in sim_ru
spp.plot(sim_ru, species = 1)
# plot "bimodal" species in sim_rs
spp.plot(sim_rs, species = "bimodal")
## End(Not run)
Subset species
Description
Subset species from a RapData()
, RapUnsolved()
, or
RapSolved()
object.
Usage
spp.subset(x, species)
## S3 method for class 'RapData'
spp.subset(x, species)
## S3 method for class 'RapUnsolOrSol'
spp.subset(x, species)
Arguments
x |
|
species |
|
Value
RapData()
or RapUnsolved()
object depending
on input object.
See Also
RapData()
, RapUnsolved()
,
RapSolved()
.
Examples
## Not run:
# load data
data(sim_ru)
# generate new object with only species 1
sim_ru2 <- spp.subset(sim_ru, 1)
## End(Not run)
Summary of solutions
Description
Extracts summary of solutions in a RapResults()
or
RapSolved()
object.
Arguments
object |
|
... |
not used. |
Details
This table follows Marxan conventions (https://marxansolutions.org/). The columns are:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this column correspond to outputs from the Gurobi software package (https://www.gurobi.com/documentation/6.5/refman/optimization_status_codes.html).
- Score
The objective function for the solution.
- Cost
Total cost associated with a solution.
- Planning_Units
Number of planning units selected in a solution.
- Connectivity_Total
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
- Connectivity_In
The amount of shared boundary length among planning units selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in the solution.
- Connectivity_Out
The number of shared boundary length among planning units not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in the solution (
Connectivity_In
) to the total amount of boundary length (Connectivity_Edge
). This ratio is an indicator of solution quality. Solutions with a lower ratio will have less planning units and will be more efficient.
Value
data.frame
See Also
Examples
## Not run:
# load data
data(sim_rs)
# show summary
summary(sim_rs)
## End(Not run)
Update object
Description
This function updates parameters or data stored in an existing
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, or RapSolved()
object.
Usage
## S3 method for class 'GurobiOpts'
update(
object,
Threads = NULL,
MIPGap = NULL,
Method = NULL,
Presolve = NULL,
TimeLimit = NULL,
NumberSolutions = NULL,
MultipleSolutionsMethod = NULL,
NumericFocus = NULL,
...
)
## S3 method for class 'ManualOpts'
update(object, NumberSolutions = NULL, ...)
## S3 method for class 'RapData'
update(
object,
species = NULL,
space = NULL,
name = NULL,
amount.target = NULL,
space.target = NULL,
pu = NULL,
cost = NULL,
status = NULL,
...
)
## S3 method for class 'RapReliableOpts'
update(object, BLM = NULL, failure.multiplier = NULL, max.r.level = NULL, ...)
## S3 method for class 'RapUnreliableOpts'
update(object, BLM = NULL, ...)
## S3 method for class 'RapUnsolOrSol'
update(object, ..., formulation = NULL, solve = TRUE)
Arguments
object |
|
Threads |
|
MIPGap |
|
Method |
|
Presolve |
|
TimeLimit |
|
NumberSolutions |
|
MultipleSolutionsMethod |
|
NumericFocus |
|
... |
parameters passed to |
species |
|
space |
|
name |
|
amount.target |
|
space.target |
|
pu |
|
cost |
|
status |
|
BLM |
|
failure.multiplier |
|
max.r.level |
|
formulation |
|
solve |
|
Value
GurobiOpts,
RapUnreliableOpts,
RapReliableOpts, RapData,
RapUnsolved, or RapSolved object
depending on argument to x
.
See Also
GurobiOpts, RapUnreliableOpts, RapReliableOpts, RapData, RapUnsolved, RapSolved.
Examples
## Not run:
# load data
data(sim_ru, sim_rs)
# GurobiOpts
x <- GurobiOpts(MIPGap = 0.7)
y <- update(x, MIPGap = 0.1)
print(x)
print(y)
# RapUnreliableOpts
x <- RapUnreliableOpts(BLM = 10)
y <- update(x, BLM = 2)
print(x)
print(y)
# RapReliableOpts
x <- RapReliableOpts(failure.multiplier = 2)
y <- update(x, failure.multiplier = 4)
print(x)
print(y)
# RapData
x <- sim_ru@data
y <- update(x, space.target = c(0.4, 0.7, 0.1))
print(space.target(x))
print(space.target(y))
## RapUnsolved
x <- sim_ru
y <- update(x, amount.target = c(0.1, 0.2, 0.3), BLM = 3, solve = FALSE)
print(x@opts@BLM); print(amount.target(x))
print(y@opts@BLM); print(space.target(y))
## RapSolved
x <- sim_rs
y <- update(x, space.target = c(0.4, 0.6, 0.9), BLM = 100, Presolve = 1L,
solve = FALSE)
print(x@opts@BLM); print(amount.target(x))
print(y@opts@BLM); print(space.target(y))
## End(Not run)
Proportion held using unreliable RAP formulation.
Description
This is a convenience function to quickly calculate the proportion of variation that one set of points captures in a another set of points using the unreliable formulation.
Usage
urap.proportion.held(x, y, y.weights = rep(1, nrow(y)))
Arguments
x |
|
y |
|
y.weights |
|
Value
numeric
value indicating the proportion of variation that
x
explains in y
Examples
## Not run:
urap.proportion.held(as.matrix(iris[1:2,-5]), as.matrix(iris[1:5,-5]))
## End(Not run)