Title: | 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), 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>. |
Authors: | Jeffrey O Hanson [aut, cre], Jonathan R Rhodes [aut], Hugh P Possingham [aut], Richard A Fuller [aut] |
Maintainer: | Jeffrey O Hanson <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2024-10-26 04:44:30 UTC |
Source: | https://github.com/jeffreyhanson/raptr |
This function returns the amount held for each species in a solution.
amount.held(x, y, species) ## S3 method for class 'RapSolved' amount.held(x, y = 0, species = NULL)
amount.held(x, y, species) ## S3 method for class 'RapSolved' amount.held(x, y = 0, species = NULL)
x |
|
y |
Available inputs include: |
species |
|
base::matrix()
or numeric
vector depending on
arguments.
## 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)
## 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)
This function sets or returns the target amounts for each species.
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
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
x |
|
species |
|
value |
|
numeric
vector.
RapData()
, RapResults()
,
RapSolved()
.
## 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)
## 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 GurobiOpts()
object to list.
## S3 method for class 'GurobiOpts' as.list(x, ...)
## S3 method for class 'GurobiOpts' as.list(x, ...)
x |
|
... |
not used. |
list
This function will not include the NumberSolutions
slot, the
MultipleSolutionsMethod
slot, or the TimeLimit
slot if it is
not finite.
GurobiOpts
.
## Not run: # make GuboriOpts object x <- GurobiOpts() # convert to list as.list(x) ## End(Not run)
## Not run: # make GuboriOpts object x <- GurobiOpts() # convert to list as.list(x) ## End(Not run)
This function creates a new AttributeSpace
object.
AttributeSpace(planning.unit.points, demand.points, species)
AttributeSpace(planning.unit.points, demand.points, species)
planning.unit.points |
|
demand.points |
|
species |
|
A new AttributeSpace
object.
DemandPoints, PlanningUnitPoints.
## 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)
## 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)
This class is used to store planning unit points and demand points for a single species in an attribute space.
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.
DemandPoints, PlanningUnitPoints.
This function creates a new AttributeSpaces
object.
AttributeSpaces(spaces, name)
AttributeSpaces(spaces, name)
spaces |
|
name |
|
A new AttributeSpaces
object.
## 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)
## 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)
This class is used to store a collection of attribute spaces for different species.
spaces
list
of AttributeSpace()
objects for
different species.
name
character
name to identify the attribute space.
This functions creates a blank SpatRaster
based on the spatial extent of a
sf
object.
blank.raster(x, res)
blank.raster(x, res)
x |
|
res |
|
## Not run: # make sf data polys <- sim.pus(225L) # make raster from sf blank.raster(polys, 1) ## End(Not run)
## Not run: # make sf data polys <- sim.pus(225L) # make raster from sf blank.raster(polys, 1) ## End(Not run)
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.
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)
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)
x |
|
tol |
|
length.factor |
|
edge.factor |
|
A data.frame
with 'id1' (integer
), 'id2'
(integer
), and 'amount' (numeric
) columns.
This function is based on the algorithm in QMARXAN https://github.com/tsw-apropos/qmarxan for calculating boundary length.
## 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)
## 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)
This function calculates the average of species values in each planning unit. By default all polygons will be treated as having separate ids.
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, ...)
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, ...)
x |
|
... |
not used. |
y |
|
ids |
|
field |
|
A base::data.frame()
object.
Although earlier versions of the package had an additional ncores
parameter, this parameter has been deprecated.
## 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)
## 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)
This dataset contains data to generate example prioritizations for the pale-headed Rosella (Platycercus adscitus) in Queensland, Australia.
"cs_pus.gpkg"
Geopackage file
"cs_species.tif"
GeoTIFF file.
"cs_space.tif"
GeoTIFF file.
The objects in the dataset are listed below.
"cs_pus.gpkg"
Geopackage file containing planning units.
The units were generated as 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/[email protected]/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. The
area
field denotes
the amount of land encompassed by each unit, the cost
field is set to 1 for all units, and the status
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 resolution).
## 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)
## 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)
This function converts sf::st_sf()
and
sp::SpatialPolygonsDataFrame()
objects to
PBSmapping::PolySet()
objects.
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)
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)
x |
|
n_preallocate |
|
PBSmapping::PolySet()
object.
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.
For a slower, more stable equivalent see
maptools::SpatialPolygons2PolySet
.
## Not run: # generate sf object sim_pus <- sim.pus(225L) # convert to PolySet x <- convert2PolySet(sim_pus) ## End(Not run)
## Not run: # generate sf object sim_pus <- sim.pus(225L) # convert to PolySet x <- convert2PolySet(sim_pus) ## End(Not run)
This function creates a new DemandPoints
object
DemandPoints(coords, weights)
DemandPoints(coords, weights)
coords |
|
weights |
|
A new DemandPoints
object.
## Not run: # make demand points dps <- DemandPoints( matrix(rnorm(100), ncol=2), runif(50) ) # print object print(dps) ## End(Not run)
## Not run: # make demand points dps <- DemandPoints( matrix(rnorm(100), ncol=2), runif(50) ) # print object print(dps) ## End(Not run)
This class is used to store demand point information.
coords
base::matrix()
of coordinates for each demand point.
weights
numeric
weights for each demand point.
Subset demand points from a RapData()
,
RapUnsolved()
, or RapSolved()
object.
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)
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)
x |
|
space |
|
species |
|
points |
|
RapData()
or RapUnsolved()
object depending
on input object.
RapData()
, RapUnsolved()
,
RapSolved()
.
## 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)
## 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)
This function creates a new GurobiOpts object.
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 )
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 )
Threads |
|
MIPGap |
|
Method |
|
Presolve |
|
TimeLimit |
|
NumberSolutions |
|
MultipleSolutionsMethod |
|
NumericFocus |
|
GurobiOpts
object
## 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)
## 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)
This class is used to store Gurobi input parameters.
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 when NumberSolutions
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 to
number_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 to 0L
such that minimal effort
is spent to reduce run time.
This function determines if the Gurobi R package is installed on the
computer and that it can be used base::options()
.
is.GurobiInstalled(verbose = TRUE)
is.GurobiInstalled(verbose = TRUE)
verbose |
|
logical
Is it installed and ready to use?
## Not run: # check if Gurobi is installed is.GurobiInstalled() # print cached status of installation options()$GurobiInstalled ## End(Not run)
## Not run: # check if Gurobi is installed is.GurobiInstalled() # print cached status of installation options()$GurobiInstalled ## End(Not run)
This function returns the Gurobi log file (*.log) associated with solving an optimization problem.
logging.file(x, y) ## S3 method for class 'RapResults' logging.file(x, y = 0) ## S3 method for class 'RapSolved' logging.file(x, y = 0)
logging.file(x, y) ## S3 method for class 'RapResults' logging.file(x, y = 0) ## S3 method for class 'RapSolved' logging.file(x, y = 0)
x |
|
y |
Available inputs include: |
The term logging file was used due to collisions with the log
function.
## 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)
## 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)
This function generates demand points to characterize a distribution of points.
make.DemandPoints( points, n = 100L, quantile = 0.5, kernel.method = c("ks", "hypervolume")[1], ... )
make.DemandPoints( points, n = 100L, quantile = 0.5, kernel.method = c("ks", "hypervolume")[1], ... )
points |
|
n |
|
quantile |
|
kernel.method |
|
... |
arguments passed to kernel density estimating functions |
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
().
A new DemandPoints()
object.
hypervolume::hypervolume()
, ks::kde()
,
adehabitatHR::mcp()
.
## 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)
## 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)
This function prepares spatially explicit planning unit, species data, and landscape data layers for RAP processing.
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, ... )
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, ... )
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 |
A new RapData
object.
## 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)
## 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)
This function creates a new ManualOpts object.
ManualOpts(NumberSolutions = 1L)
ManualOpts(NumberSolutions = 1L)
NumberSolutions |
|
A new ManualOpts()
object
## Not run: # create ManualOpts object ManualOpts(NumberSolutions = 1L) ## End(Not run)
## Not run: # create ManualOpts object ManualOpts(NumberSolutions = 1L) ## End(Not run)
This class is used to store parameters.
NumberSolutions
integer
number of solutions.
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.
maximum.targets(x, verbose) ## S3 method for class 'RapUnsolOrSol' maximum.targets(x, verbose = FALSE)
maximum.targets(x, verbose) ## S3 method for class 'RapUnsolOrSol' maximum.targets(x, verbose = FALSE)
x |
|
verbose |
|
data.frame
object.
## Not run: # load RapSolved objects data(sim_ru) # calculate maximum metrics maximum.targets(sim_ru) ## End(Not run)
## Not run: # load RapSolved objects data(sim_ru) # calculate maximum metrics maximum.targets(sim_ru) ## End(Not run)
This function sets or returns the species names in an object.
## 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)
## 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)
x |
|
value |
new species names. |
RapData()
, RapUnsolved()
,
RapSolved()
.
## 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)
## 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)
This function creates a new PlanningUnitPoints
object.
PlanningUnitPoints(coords, ids)
PlanningUnitPoints(coords, ids)
coords |
|
ids |
|
A new PlanningUnitPoints
object.
## Not run: # create PlanningUnitPoints object x <- PlanningUnitPoints(matrix(rnorm(150), ncol = 1), seq_len(150)) # print object print(x) ## End(Not run)
## Not run: # create PlanningUnitPoints object x <- PlanningUnitPoints(matrix(rnorm(150), ncol = 1), seq_len(150)) # print object print(x) ## End(Not run)
This class is used to planning units in an attribute space.
coords
base::matrix()
coordinates for each point.
ids
integer
planning unit ids.
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.
## 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)
## 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)
x |
|
y |
Available inputs are: |
basemap |
|
pu.color.palette |
|
alpha |
|
grayscale |
|
main |
|
force.reset |
|
i |
Available inputs are: |
j |
Available inputs are: |
This function requires the RgoogleMaps package to be installed in order to create display a basemap.
## 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)
## 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)
Prints objects.
## 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, ...)
## 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, ...)
x |
|
... |
not used. |
header |
|
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, RapResults()
,
RapSolved()
.
## 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)
## 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)
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.
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)
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)
x |
|
species |
|
threshold |
|
RapData()
or RapUnsolved()
object depending
on input object.
RapData()
, RapUnsolved()
,
RapSolved()
.
## 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)
## 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 from a RapData()
,
RapUnsolved()
, or RapSolved()
object.
pu.subset(x, pu) ## S3 method for class 'RapData' pu.subset(x, pu) ## S3 method for class 'RapUnsolOrSol' pu.subset(x, pu)
pu.subset(x, pu) ## S3 method for class 'RapData' pu.subset(x, pu) ## S3 method for class 'RapUnsolOrSol' pu.subset(x, pu)
x |
|
pu |
|
RapData()
or RapUnsolved()
object depending
on input object.
RapData()
, RapUnsolved()
,
RapSolved()
.
## 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)
## 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)
This function generates random points in a terra::rast()
object.
randomPoints(mask, n, prob = FALSE)
randomPoints(mask, n, prob = FALSE)
mask |
|
n |
|
prob |
|
base::matrix()
with x-coordinates, y-coordinates, and
cell values.
This function is similar to dismo::randomPoints
.
## 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)
## 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)
This is a general function to create Rap objects from scratch and solve them to generate solutions.
rap( pus, species, spaces = NULL, formulation = c("unreliable", "reliable")[1], solve = TRUE, ... )
rap( pus, species, spaces = NULL, formulation = c("unreliable", "reliable")[1], solve = TRUE, ... )
pus |
|
species |
|
spaces |
|
formulation |
|
solve |
|
... |
arguments are passed to |
A new RapSolved()
object if solve
is TRUE
,
otherwise an RapUnsolved()
is returned.
Type vignette("raptr")
to see the package vignette for a
tutorial.
GurobiOpts()
, RapReliableOpts()
,
RapUnreliableOpts()
RapData()
,
RapResults()
, RapUnsolved()
,
RapSolved()
.
This function creates a "RapData" object using pre-processed data.
RapData( pu, species, targets, pu.species.probabilities, attribute.spaces, boundary, polygons = NA, skipchecks = FALSE, .cache = new.env() )
RapData( pu, species, targets, pu.species.probabilities, attribute.spaces, boundary, polygons = NA, skipchecks = FALSE, .cache = new.env() )
pu |
|
species |
|
targets |
|
pu.species.probabilities |
|
attribute.spaces |
|
boundary |
|
polygons |
|
skipchecks |
|
.cache |
|
A new RapData
object.
Generally, users are not encouraged to change arguments to
.cache
.
PBSmapping::PolySet()
, sp::SpatialPoints()
,
sp::SpatialPointsDataFrame()
, make.RapData()
,
RapData.
## 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)
## 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)
This class is used to store RAP input data.
polygons
PBSmapping::PolySet()
planning unit spatial data
or NULL
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
of AttributeSpaces
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.
This function creates a new RapReliableOpts object.
RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L)
RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L)
BLM |
|
failure.multiplier |
|
max.r.level |
|
RapReliableOpts
object
## Not run: # create RapReliableOpts using defaults RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L) ## End(Not run)
## Not run: # create RapReliableOpts using defaults RapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L) ## End(Not run)
This class is used to store input parameters for the reliable formulation of RAP.
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.
This function creates a new RapResults()
object.
RapResults( summary, selections, amount.held, space.held, logging.file, .cache = new.env() )
RapResults( summary, selections, amount.held, space.held, logging.file, .cache = new.env() )
summary |
|
selections |
|
amount.held |
|
space.held |
|
logging.file |
|
.cache |
|
The summary
table follows Marxan conventions (
https://marxansolutions.org/). The columns
are:
The index of each solution in the object.
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).
The objective function for the solution.
Total cost associated with a solution.
Number of planning units selected in a solution.
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
The amount of shared boundary length among planning units selected in the solution.
The amount of exposed boundary length in the solution.
The number of shared boundary length among planning units not selected in the solution.
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.
RapResults
object
slot best
is automatically determined based on data in
summary
.
This class is used to store RAP results.
The summary
table follows Marxan conventions
(https://marxansolutions.org/). The columns
are:
The index of each solution in the object.
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).
The objective function for the solution.
Total cost associated with a solution.
Number of planning units selected in a solution.
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
The amount of shared boundary length among planning units selected in the solution.
The amount of exposed boundary length in the solution.
The number of shared boundary length among planning units not selected in the solution.
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.
summary
base::data.frame()
with summary information on
solutions.
selections
base::matrix()
with binary selections. The cell
denotes if planning unit
is selected in the
'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.
RapResults()
, read.RapResults()
.
This function creates a RapSolved()
object.
RapSolved(unsolved, solver, results)
RapSolved(unsolved, solver, results)
unsolved |
|
solver |
|
results |
|
RapSolved()
object.
RapSolved, RapResults,
link{solve}
.
This class is used to store RAP input and output data in addition to input parameters.
opts
RapReliableOpts()
or RapUnreliableOpts()
object used to store input parameters.
solver
GurobiOpts()
or ManualOpts()
object
used to store solver information/parameters.
data
RapData()
object used to store input data.
results
RapResults()
object used to store results.
RapReliableOpts, RapUnreliableOpts, RapData, RapResults.
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).
The main classes used in this package are used to store input data and prioritizations:
parameters for solving optimization problems using Gurobi.
parameters for the reliable formulation of RAP.
parameters for the unreliable formulation of RAP.
planning unit, species data, and demand points for RAP.
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.
prioritizations and summary statistics on their performance.
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.
Maintainer: Jeffrey O Hanson [email protected]
Authors:
Jonathan R Rhodes
Hugh P Possingham
Richard A Fuller
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.
Useful links:
Report bugs at https://github.com/jeffreyhanson/raptr/issues
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).
SpatialPolygons2PolySet(...)
SpatialPolygons2PolySet(...)
... |
not used. |
The following functions have been deprecated:
SpatialPolygons2PolySet()
renamed
as the convert2PolySet()
function.
This function creates a new RapUnreliableOpts object.
RapUnreliableOpts(BLM = 0)
RapUnreliableOpts(BLM = 0)
BLM |
|
RapUnreliableOpts()
object
## Not run: # create RapUnreliableOpts using defaults RapUnreliableOpts(BLM = 0) ## End(Not run)
## Not run: # create RapUnreliableOpts using defaults RapUnreliableOpts(BLM = 0) ## End(Not run)
This class is used to store input parameters for the unreliable RAP problem formulation.
BLM
numeric
boundary length modifier. Defaults to 0.
This function creates a RapUnsolved()
object using a
GurobiOpts()
, a RapReliableOpts()
or
RapUnreliableOpts()
object, and a RapData()
object.
RapUnsolved(opts, data)
RapUnsolved(opts, data)
opts |
|
data |
|
RapUnsolved()
object.
RapReliableOpts, RapUnreliableOpts, RapData.
## 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)
## 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)
This class is used to store RAP input data and input parameters.
opts
RapReliableOpts()
or RapUnreliableOpts()
object used to store input parameters.
data
RapData()
object used to store input data.
RapReliableOpts, RapUnreliableOpts, RapData.
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.
rrap.proportion.held( pu.coordinates, pu.probabilities, dp.coordinates, dp.weights, failure.distance, maximum.r.level = as.integer(length(pu.probabilities)) )
rrap.proportion.held( pu.coordinates, pu.probabilities, dp.coordinates, dp.weights, failure.distance, maximum.r.level = as.integer(length(pu.probabilities)) )
pu.coordinates |
|
pu.probabilities |
|
dp.coordinates |
|
dp.weights |
|
failure.distance |
|
maximum.r.level |
|
numeric
value indicating the proportion of variation that the
demand points explain in the planning units
## 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)
## 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)
Extract solution score from RapResults()
or
RapSolved()
object.
score(x, y) ## S3 method for class 'RapResults' score(x, y = 0) ## S3 method for class 'RapSolved' score(x, y = 0)
score(x, y) ## S3 method for class 'RapResults' score(x, y = 0) ## S3 method for class 'RapSolved' score(x, y = 0)
x |
|
y |
Available inputs include: |
matrix
or numeric
vector with solution score(s)
depending on arguments.
## 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)
## 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 selections for a given solution from a RapResults()
or
RapSolved()
object.
selections(x, y) ## S3 method for class 'RapResults' selections(x, y = 0) ## S3 method for class 'RapSolved' selections(x, y = 0)
selections(x, y) ## S3 method for class 'RapResults' selections(x, y = 0) ## S3 method for class 'RapSolved' selections(x, y = 0)
x |
|
y |
|
base::matrix()
or numeric
vector depending on
arguments.
## 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)
## 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)
Shows objects.
## 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)
## 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)
object |
|
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, RapResults()
,
RapSolved()
.
## 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)
## 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)
This function simulates planning units for RAP.
sim.pus( n, xmn = -sqrt(n)/2, xmx = sqrt(n)/2, ymn = -sqrt(n)/2, ymx = sqrt(n)/2 )
sim.pus( n, xmn = -sqrt(n)/2, xmx = sqrt(n)/2, ymn = -sqrt(n)/2, ymx = sqrt(n)/2 )
n |
|
xmn |
|
xmx |
|
ymn |
|
ymx |
|
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
).
sf::st_as_sf()
with planning units.
## 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)
## 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)
This function simulates attribute space data for RAP.
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, ...)
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, ...)
x |
|
... |
not used. |
d |
|
model |
|
res |
|
terra::rast()
with layers for each dimension of the space.
## 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)
## 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)
This function simulates species distributions for RAP.
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", ...)
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", ...)
x |
|
... |
not used. |
n |
|
model |
|
res |
|
terra::rast()
with layers for each species.
## 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)
## 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)
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.
RapUnsolved()
object with all the simulated data.
RapSolved()
object with 5 near-optimal solutions.
The species were simulated to represent various simplified species distributions.
This species has an equal probability (0.5) of occurring in all planning units.
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.
This species has two distinct ecotypes. Each ecotype has its own core and marginal area.
## 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)
## 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)
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.
## 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)
## 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)
a |
|
b |
|
... |
not used. |
verbose |
|
RapSolved()
object
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.
## 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)
## 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)
This function returns the attribute space held for each species in a solution.
space.held(x, y, species, space) ## S3 method for class 'RapSolved' space.held(x, y = 0, species = NULL, space = NULL)
space.held(x, y, species, space) ## S3 method for class 'RapSolved' space.held(x, y = 0, species = NULL, space = NULL)
x |
|
y |
Available inputs include: |
species |
|
space |
|
matrix
object.
## 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)
## 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)
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.
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, ... )
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, ... )
x |
|
species |
|
space |
|
... |
not used. |
pu.color.palette |
|
main |
|
y |
|
## 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)
## 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)
This function sets or returns the attribute space targets for each species.
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
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
x |
|
species |
|
space |
|
value |
|
A numeric
or matrix
objects.
RapData()
, RapResults()
, RapSolved()
.
## 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)
## 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)
This function plots the distribution of species across the study area.
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, ... )
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, ... )
x |
|
species |
|
... |
not used. |
prob.color.palette |
|
pu.color.palette |
|
basemap |
|
alpha |
|
grayscale |
|
main |
|
force.reset |
|
y |
|
This function requires the RgoogleMaps package to be installed in order to create display a basemap.
## 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)
## 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 from a RapData()
, RapUnsolved()
, or
RapSolved()
object.
spp.subset(x, species) ## S3 method for class 'RapData' spp.subset(x, species) ## S3 method for class 'RapUnsolOrSol' spp.subset(x, species)
spp.subset(x, species) ## S3 method for class 'RapData' spp.subset(x, species) ## S3 method for class 'RapUnsolOrSol' spp.subset(x, species)
x |
|
species |
|
RapData()
or RapUnsolved()
object depending
on input object.
RapData()
, RapUnsolved()
,
RapSolved()
.
## Not run: # load data data(sim_ru) # generate new object with only species 1 sim_ru2 <- spp.subset(sim_ru, 1) ## End(Not run)
## Not run: # load data data(sim_ru) # generate new object with only species 1 sim_ru2 <- spp.subset(sim_ru, 1) ## End(Not run)
Extracts summary of solutions in a RapResults()
or
RapSolved()
object.
object |
|
... |
not used. |
This table follows Marxan conventions (https://marxansolutions.org/). The columns are:
The index of each solution in the object.
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).
The objective function for the solution.
Total cost associated with a solution.
Number of planning units selected in a solution.
The total amount of shared boundary length between all planning units. All solutions in the same object should have equal values for this column.
The amount of shared boundary length among planning units selected in the solution.
The amount of exposed boundary length in the solution.
The number of shared boundary length among planning units not selected in the solution.
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.
data.frame
## Not run: # load data data(sim_rs) # show summary summary(sim_rs) ## End(Not run)
## Not run: # load data data(sim_rs) # show summary summary(sim_rs) ## End(Not run)
This function updates parameters or data stored in an existing
GurobiOpts()
, RapUnreliableOpts()
,
RapReliableOpts()
, RapData()
,
RapUnsolved()
, or RapSolved()
object.
## 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)
## 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)
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 |
|
GurobiOpts,
RapUnreliableOpts,
RapReliableOpts, RapData,
RapUnsolved, or RapSolved object
depending on argument to x
.
GurobiOpts, RapUnreliableOpts, RapReliableOpts, RapData, RapUnsolved, RapSolved.
## 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)
## 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)
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.
urap.proportion.held(x, y, y.weights = rep(1, nrow(y)))
urap.proportion.held(x, y, y.weights = rep(1, nrow(y)))
x |
|
y |
|
y.weights |
|
numeric
value indicating the proportion of variation that
x
explains in y
## Not run: urap.proportion.held(as.matrix(iris[1:2,-5]), as.matrix(iris[1:5,-5])) ## End(Not run)
## Not run: urap.proportion.held(as.matrix(iris[1:2,-5]), as.matrix(iris[1:5,-5])) ## End(Not run)