| 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 fromhttps://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 preservebiodiversity patterns and processes. To this end, protected areas areestablished to buffer species and preserve biodiversity processes. Butresources are limited and so protected areas must be cost-effective. Thispackage contains tools to generate plans for protected areas(prioritizations). Conservation planning data are used to construct anoptimization problem, which is then solved to yield prioritizations. Tosolve the optimization problems in a feasible amount of time, this packageuses the commercial 'Gurobi' software package (obtained fromhttps://www.gurobi.com/). For more information on usingthis package, see Hanson et al. (2018).
Details
The main classes used in this package are used to store input data andprioritizations:
- GurobiOpts
parameters for solving optimizationproblems using Gurobi.
- RapReliableOpts
parameters for the reliableformulation of RAP.
- RapUnreliableOpts
parameters for the unreliableformulation of RAP.
- RapData
planning unit, species data, and demandpoints for RAP.
- RapUnsolved
contains all the data and inputparameters required to generate prioritizations using RAP. This classcontains aGurobiOpts object, aRapReliableOpts orRapUnreliableOptsobject, and aRapData object.
- RapResults
prioritizations and summarystatistics 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 aRapResultsobject.
Typevignette("raptr") for a tutorial on how to use this package.
Author(s)
Maintainer: Jeffrey O Hansonjeffrey.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 athttps://github.com/jeffreyhanson/raptr/issues
Create new AttributeSpace object
Description
This function creates a newAttributeSpace object.
Usage
AttributeSpace(planning.unit.points, demand.points, species)Arguments
planning.unit.points |
|
demand.points |
|
species |
|
Value
A newAttributeSpace 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 asingle species in an attribute space.
Slots
planning.unit.pointsPlanningUnitPoints()object for planningunit in the space.demand.pointsDemandPoints()object for the space.speciesintegerspecies id to indicate which species the spaceis associated with.
See Also
DemandPoints,PlanningUnitPoints.
Create new AttributeSpaces object
Description
This function creates a newAttributeSpaces object.
Usage
AttributeSpaces(spaces, name)Arguments
spaces |
|
name |
|
Value
A newAttributeSpaces 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 spacesfor different species.
Description
This class is used to store a collection of attribute spaces for differentspecies.
Slots
spaceslistofAttributeSpace()objects fordifferent species.namecharactername to identify the attribute space.
See Also
Create new DemandPoints object
Description
This function creates a newDemandPoints object
Usage
DemandPoints(coords, weights)Arguments
coords |
|
weights |
|
Value
A newDemandPoints object.
See Also
Examples
## Not run: # make demand pointsdps <- DemandPoints( matrix(rnorm(100), ncol=2), runif(50))# print objectprint(dps)## End(Not run)DemandPoints: An S4 class to represent demand points
Description
This class is used to store demand point information.
Slots
coordsbase::matrix()of coordinates for each demand point.weightsnumericweights 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 parametersGurobiOpts(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
Threadsintegernumber of cores to use for processing. Defaultsto 1L.MIPGapnumericMIP gap specifying minimum solution quality.Defaults to 0.1.MethodintegerAlgorithm to use for solving model. Defaults to0L.Presolveintegercode for level of computation in presolve.Defaults to 2.TimeLimitintegernumber of seconds to allow for solving.Defaults to NA_integer_, and so a time limit is not imposed.NumberSolutionsintegernumber of solutions to generate.Defaults to 1L.MultipleSolutionsMethodintegername of method to obtainmultiple solutions (used whenNumberSolutionsis 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 thatare all within the optimality gap. The"solution.pool.0"method returns all solutions identified whilst trying to finda solution that is within the specified optimality gap. The"solution.pool.1"method finds one solution within the optimalitygap 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 aspecified number of solutions that are nearest to optimality. Thesearch pool methods correspond to the parameters used by the Gurobisoftware suite (seehttps://www.gurobi.com/documentation/8.0/refman/poolsearchmode.html#parameter:PoolSearchMode).Defaults to"benders.cuts".NumericFocusintegerhow much effort should Gurobi focus onaddressing numerical issues? Defaults to0Lsuch that minimal effortis 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 newManualOpts() object
See Also
Examples
## Not run: # create ManualOpts objectManualOpts(NumberSolutions = 1L)## End(Not run)ManualOpts: An S4 class to represent parameters for manually specifiedsolutions
Description
This class is used to store parameters.
Slots
NumberSolutionsintegernumber of solutions.
See Also
Create new PlanningUnitPoints object
Description
This function creates a newPlanningUnitPoints object.
Usage
PlanningUnitPoints(coords, ids)Arguments
coords |
|
ids |
|
Value
A newPlanningUnitPoints object.
See Also
Examples
## Not run: # create PlanningUnitPoints objectx <- PlanningUnitPoints(matrix(rnorm(150), ncol = 1), seq_len(150))# print objectprint(x)## End(Not run)PlanningUnitPoints: An S4 class to represent planning units in an attributespace
Description
This class is used to planning units in an attribute space.
Slots
coordsbase::matrix()coordinates for each point.idsintegerplanning 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 newRapData 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 datacs_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 objectattribute.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 objectx <- 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 objectprint(x)## End(Not run)RapData: An S4 class to represent RAP input data
Description
This class is used to store RAP input data.
Slots
polygonsPBSmapping::PolySet()planning unit spatial dataorNULLif data not available.pubase::data.frame()planning unit data. Columns must be"cost" (numeric), "area" (numeric), and "status"(integer).speciesbase::data.frame()with species data. Columns mustbe "name" (character.targetsbase::data.frame()with species data. Columns mustbe "species" (integer), "target" (integer), "proportion"(numeric).pu.species.probabilitiesbase::data.frame()with data onthe probability of species in each planning unit. Columns must be "species"(integer), "pu" (integer), and "value" (numeric).attribute.spaceslistofAttributeSpacesobjects withthe demand points and planning unit coordinates.boundarybase::data.frame()with data on the sharedboundary length of planning units. Columns must be "id1" (integer),"id2" (integer), and "boundary" (numeric).skipcheckslogicalSkip data integrity checks? May improvespeed for big data sets..cachebase::environment()used to cache calculations.
See Also
RapOpts class
Description
Object is eitherRapReliableOpts() orRapUnreliableOpts().
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 defaultsRapReliableOpts(BLM = 0, failure.multiplier = 1.1, max.r.level = 5L)## End(Not run)RapReliableOpts: An S4 class to represent input parameters for the reliableformulation of RAP.
Description
This class is used to store input parameters for the reliable formulation ofRAP.
Slots
BLMnumericboundary length modifier. Defaults to 0.failure.multipliernumericmultiplier for failure planningunit. Defaults to 1.1.max.r.levelnumericmaximum R failure level for approximation.Defaults to 5L.
See Also
Create RapResults object
Description
This function creates a newRapResults() 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
Thesummary table follows Marxan conventions (https://marxansolutions.org/). The columnsare:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this columncorrespond 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 betweenall planning units. All solutions in the same object should have equalvalues for this column.
- Connectivity_In
The amount of shared boundary length among planningunits selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in thesolution.
- Connectivity_Out
The number of shared boundary length among planningunits not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in thesolution (
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 moreefficient.
Value
RapResults object
Note
slotbest is automatically determined based on data insummary.
See Also
RapResults: An S4 class to represent RAP results
Description
This class is used to store RAP results.
Details
Thesummary table follows Marxan conventions(https://marxansolutions.org/). The columnsare:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this columncorrespond 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 betweenall planning units. All solutions in the same object should have equalvalues for this column.
- Connectivity_In
The amount of shared boundary length among planningunits selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in thesolution.
- Connectivity_Out
The number of shared boundary length among planningunits not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in thesolution (
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 moreefficient.
Slots
summarybase::data.frame()with summary information onsolutions.selectionsbase::matrix()with binary selections. The cellx_{ij}denotes if planning unitjis selected in thei'th solution.amount.heldbase::matrix()with the amount held for eachspecies in each solution.space.heldbase::matrix()with the proportion of attributespace sampled for each species in each solution.bestintegerwith index of best solution.logging.filecharacterGurobi log files..cachebase::environment()used to store extra data.
See Also
RapResults(),read.RapResults().
Create new RapSolved object
Description
This function creates aRapSolved() 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 inputparameters.
Slots
optsRapReliableOpts()orRapUnreliableOpts()object used to store input parameters.solverGurobiOpts()orManualOpts()objectused to store solver information/parameters.dataRapData()object used to store input data.resultsRapResults()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 defaultsRapUnreliableOpts(BLM = 0)## End(Not run)RapUnreliableOpts: An S4 class to represent parameters for the unreliableRAP problem
Description
This class is used to store input parameters for the unreliable RAP problemformulation.
Slots
BLMnumericboundary length modifier. Defaults to 0.
Create a new RapUnsolved object
Description
This function creates aRapUnsolved() object using aGurobiOpts(), aRapReliableOpts() orRapUnreliableOpts() object, and aRapData() object.
Usage
RapUnsolved(opts, data)Arguments
opts |
|
data |
|
Value
RapUnsolved() object.
See Also
RapReliableOpts,RapUnreliableOpts,RapData.
Examples
## Not run: # set random number generator seedset.seed(500)# load datacs_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 RapUnsolvedro <- RapUnreliableOpts()rd <- make.RapData(cs_pus[seq_len(10), ], cs_spp, NULL, include.geographic.space = TRUE,n.demand.points = 5L)# create RapUnsolved objectru <- RapUnsolved(ro, rd)# print objectprint(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
optsRapReliableOpts()orRapUnreliableOpts()object used to store input parameters.dataRapData()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() ornumeric vector depending onarguments.
See Also
Examples
## Not run: # load datadata(sim_rs)# amount held (%) in best solution for each speciesamount.held(sim_rs, 0)# amount held (%) in best solution for species 1amount.held(sim_rs, 0, 1)# amount held (%) in second solution for each speciesamount.held(sim_rs, 2)# amount held (%) in each solution for each speciesamount.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) <- valueArguments
x |
|
species |
|
value |
|
Value
numeric vector.
See Also
RapData(),RapResults(),RapSolved().
Examples
## Not run: # load datadata(sim_rs)# extract amount targets for all speciesamount.target(sim_rs)# set amount targets for all speciesamount.target(sim_rs) <- 0.1# extract amount targets for first speciesamount.target(sim_rs, 1)# set amount targets for for first speciesamount.target(sim_rs, 1) <- 0.5## End(Not run)Convert object to list
Description
ConvertGurobiOpts() object to list.
Usage
## S3 method for class 'GurobiOpts'as.list(x, ...)Arguments
x |
|
... | not used. |
Value
list
Note
This function will not include theNumberSolutions slot, theMultipleSolutionsMethod slot, or theTimeLimit slot if it isnot finite.
See Also
GurobiOpts.
Examples
## Not run: # make GuboriOpts objectx <- GurobiOpts()# convert to listas.list(x)## End(Not run)Basemap
Description
This function retrieves google map data for planning units. The google mapdata 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 blankSpatRaster based on the spatial extent of asf object.
Usage
blank.raster(x, res)Arguments
x |
|
res |
|
Examples
## Not run: # make sf datapolys <- sim.pus(225L)# make raster from sfblank.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 orNULL depends ony argument.
Note
caches are implemented using environments, the hash is used as thename of the object in the environment.
Calculate boundary data for planning units
Description
This function calculates boundary length data. Be aware that thisfunction is designed with performance in mind, and as a consequence, if thisfunction is used improperly then it may crash R. Furthermore, multipartpolygons 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
Adata.frame with 'id1' (integer), 'id2'(integer), and 'amount' (numeric) columns.
See Also
This function is based on the algorithm in QMARXANhttps://github.com/tsw-apropos/qmarxan for calculating boundarylength.
Examples
## Not run: # simulate planning unitssim_pus <- sim.pus(225L)# calculate boundary databound.dat <- calcBoundaryData(sim_pus)# print summary of boundary datasummary(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
Abase::data.frame() object.
Note
Although earlier versions of the package had an additionalncoresparameter, this parameter has been deprecated.
Examples
## Not run: # simulate datasim_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 speciespuvspr1.dat <- calcSpeciesAverageInPus(sim_pus, sim_spp[[1]])# calculate average for multiple speciespuvspr2.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 thepale-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^2squares across thespecies' 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 areanetwork (obtained from the World Database on Protected Areas(WDPA) athttps://www.protectedplanet.net/en). Thisattribute table has 3 fields. Theareafield denotesthe amount of land encompassed by each unit, thecostfield is set to 1 for all units, and thestatusfieldindicates if 50% or more of the units' extent is covered byprotected areas."cs_spp.tif"GeoTIFF file containing probabilitydistribution map for theP. adscitus clipped toQueensland, Australia. This map was derived from recordsobtained from The Atlas of Living Australia.
"cs_space.tif"GeoTIFF file describing broad-scale climatevariation across Queensland(obtained fromhttps://worldclim.org/,and resampled to
10km^2resolution).
Examples
## Not run: # load datacs_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 dataplot(cs_pus)plot(cs_spp)plot(cs_space)## End(Not run)Convert object to PolySet data
Description
This function convertssf::st_sf() andsp::SpatialPolygonsDataFrame() objects toPBSmapping::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, butas a result it depends on C++ code and if used inappropriately thisfunction will crash R.
See Also
For a slower, more stable equivalent seemaptools::SpatialPolygons2PolySet.
Examples
## Not run: # generate sf objectsim_pus <- sim.pus(225L)# convert to PolySetx <- convert2PolySet(sim_pus)## End(Not run)Subset demand points
Description
Subset demand points from aRapData(),RapUnsolved(), orRapSolved() 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() orRapUnsolved() object dependingon input object.
See Also
RapData(),RapUnsolved(),RapSolved().
Examples
## Not run: # load datadata(sim_ru)# generate new object with first 10 planning unitssim_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 thecomputer and that it can be usedbase::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 installedis.GurobiInstalled()# print cached status of installationoptions()$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 thename 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 solvingan 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 thelogfunction.
See Also
Examples
## Not run: # load datadata(sim_rs)# log file for the best solutioncat(logging.file(sim_rs, 0))# log file for the second solutioncat(logging.file(sim_rs, 2))# log files for all solutionscat(logging.file(sim_rs, NULL))## End(Not run)Generate demand points for RAP
Description
This function generates demand points to characterize a distribution ofpoints.
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 kernalto the inputpoints. A shape is then fit to the extent ofthe kernal, and then points are randomly generated inside the shape. Thedemand points are generated as random points inside the shape. The weightsfor each demand point are calculated the estimated density of input pointsat the demand point. By supplying 'ks' as an argument tomethod inkernel.method, the shape is defined using a minimum convex polygonadehabitatHR::mcp() andks::kde() is used to fitthe kernel. Note this can only be used when the data is low-dimensional (d< 3). By supplying"hypervolume" as an argument tomethod,thehypervolume::hypervolume() function is used to create thedemand points. This method can be used for hyper-dimensional data(d << 3).
Value
A newDemandPoints() object.
See Also
hypervolume::hypervolume(),ks::kde(),adehabitatHR::mcp().
Examples
## Not run: # set random number generator seedset.seed(500)# load datacs_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 pointsspecies.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 ksdps1 <- make.DemandPoints(points = env.points[, 1], kernel.method = "ks")# print objectprint(dps1)# generate demand points for a 2d space using hypervolumedps2 <- make.DemandPoints( points = env.points, kernel.method = "hypervolume", samples.per.point = 50, verbose = FALSE)# print objectprint(dps2)## End(Not run)Make data for RAP using minimal inputs
Description
This function prepares spatially explicit planning unit, species data, andlandscape 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 newRapData object.
See Also
Examples
## Not run: # load datacs_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 datx <- make.RapData(cs_pus[1:10,], cs_spp, cs_space, include.geographic.space = TRUE)# print objectprint(x)## End(Not run)Maximum targets
Description
This function accepts aRapUnsolved() object and returns adata.frame containing the amount-based and space-based targets foreach species and attribute space. These are calculated using aprioritization that contains all the available planning units. Note that themaximum 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 objectsdata(sim_ru)# calculate maximum metricsmaximum.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 datadata(sim_rs)# show namesnames(sim_rs)# change namesnames(sim_rs) <- c('spp1', 'spp2', 'spp3')# show new namesnames(sim_rs)## End(Not run)Plot object
Description
This function plots the solutions contained inRapSolved()objects. It can be used to show a single solution, or the the selectionfrequencies of planning units contained in a singleRapSolved()object. Additionally, twoRapSolved() objects can be supplied toplot 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 theRgoogleMaps package to be installedin order to create display a basemap.
See Also
Examples
## Not run: # load example data set with solutionsdata(sim_rs)# plot selection frequenciesplot(sim_rs)# plot best solutionplot(sim_rs, 0)# plot second solutionplot(sim_rs, 2)# plot different between best and second solutionsplot(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 datadata(sim_ru, sim_rs)# print GurobiOpts objectprint(GurobiOpts())# print RapReliableOpts objectprint(RapReliableOpts())# print RapUnreliableOpts objectprint(RapUnreliableOpts())# print RapData objectprint(sim_ru@data)# print RapUnsolved objectprint(sim_ru)# print RapResults objectprint(sim_rs@results)# print RapSolved objectprint(sim_rs)## End(Not run)Subset probabilities above a threshold
Description
This function subsets out probabilities assigned to planning units above athreshold. It effectively sets the probability that species inhabit planningunits 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() orRapUnsolved() object dependingon input object.
See Also
RapData(),RapUnsolved(),RapSolved().
Examples
## Not run: # load datadata(sim_ru)# generate new object with first 10 planning unitssim_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 aRapData(),RapUnsolved(), orRapSolved() 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() orRapUnsolved() object dependingon input object.
See Also
RapData(),RapUnsolved(),RapSolved().
Examples
## Not run: # load datadata(sim_ru)# generate new object with first 10 planning unitssim_ru2 <- pu.subset(sim_ru, seq_len(10))## End(Not run)Sample random points from a SpatRaster
Description
This function generates random points in aterra::rast() object.
Usage
randomPoints(mask, n, prob = FALSE)Arguments
mask |
|
n |
|
prob |
|
Value
base::matrix() with x-coordinates, y-coordinates, andcell values.
See Also
This function is similar todismo::randomPoints.
Examples
## Not run: # simulate datasim_pus <- sim.pus(225L)sim_spp <- sim.species(sim_pus, model = "normal", n = 1, res = 0.25)# generate pointspts1 <- randomPoints(sim_spp, n = 5)pts2 <- randomPoints(sim_spp, n = 5, prob = TRUE)# plot pointsplot(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 themto 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 newRapSolved() object ifsolve isTRUE,otherwise anRapUnsolved() is returned.
Note
Typevignette("raptr") to see the package vignette for atutorial.
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 theof theraptr package, but they have since been removedentirely, replaced by other functions, or renamed as other functionsin newer versions.To help make it easier to transition to new versions of theraptrpackage, we have listed alternatives for deprecated the functions(where applicable).If a function is described as being renamed, then this meansthat 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()renamedas the
convert2PolySet()function.
Read RAP results
Description
This function reads files output from Gurobi and returns aRapResultsobject.
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 ofvariation that one set of points captures in a another set of points usingthe 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 thedemand 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 fromRapResults() orRapSolved() 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 ornumeric vector with solution score(s)depending on arguments.
See Also
Examples
## Not run: # load datadata(sim_rs)# score for the best solutionscore(sim_rs, 0)# score for the second solutionscore(sim_rs, 2)# score for all solutionsscore(sim_rs, NULL)## End(Not run)Extract solution selections
Description
Extract selections for a given solution from aRapResults() orRapSolved() 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() ornumeric vector depending onarguments.
See Also
Examples
## Not run: # load datadata(sim_rs)# selections for the best solutionselections(sim_rs, 0)# selections for the second solutionselections(sim_rs, 2)# selections for each solutionselections(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 datadata(sim_ru, sim_rs)# show GurobiOpts objectGurobiOpts()# show RapReliableOpts objectRapReliableOpts()# show RapUnreliableOpts objectRapUnreliableOpts()# show RapData objectsim_ru@data# show RapUnsolved objectsim_ru# show RapResults objectsim_rs@results# show RapSolved objectsim_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 becentered 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 / widthx <- sim.pus(225)# generate 225 rectangular pus arranged in a squarey <- 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 unitssim_pus <- sim.pus(225L)# simulate 1d space using SpatRasters1 <- sim.space(blank.raster(sim_pus, 1), d = 1)# simulate 1d space using sfs2 <- sim.space(sim_pus, res = 1, d = 1)# simulate 2d space using sfs3 <- sim.space(sim_pus, res = 1, d = 2)# plot simulated spacespar(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 polygonssim_pus <- sim.pus(225L)# simulate 1 uniform species distribution using SpatRasters1 <- sim.species(blank.raster(sim_pus, 1), n = 1, model = "uniform")# simulate 1 uniform species distribution based on sfs2 <- sim.species(sim_pus, res = 1, n = 1, model = "uniform")# simulate 1 normal species distributionss3 <- sim.species(sim_pus, res = 1, n = 1, model = "normal")# simulate 1 bimodal species distributions4 <- sim.species(sim_pus, res = 1, n = 1, model = "bimodal")# simulate 1 species distribution using a random fields5 <- sim.species(sim_pus, res = 1, n = 1, model = 0.2)# plot simulationspar(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 forthree simulated species. This dataset contains planning units, speciesdistribution maps, and demand points for each species. For the purposes ofexploring the behaviour of the problem, demand points were generated usingthe centroids of planning units and the probability that they are occupiedby the species. Note that methodology is not encouraged for real-worldconservation 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 speciesdistributions.
- uniform
This species has an equal probability (0.5) of occurring inall planning units.
- normal
This species has a single range-core where it is most likelyto be found. It is less likely to be found in areas furtheraway from the center of its range.
- bimodal
This species has two distinct ecotypes. Each ecotype has itsown core and marginal area.
Examples
## Not run: # load datadata(sim_ru, sim_rs)# plot species distributionsspp.plot(sim_ru, 1)spp.plot(sim_ru, 2)spp.plot(sim_ru, 3)# plot selection frequenciesplot(sim_rs)# plot best solutionplot(sim_rs, 0)## End(Not run)Solve RAP object
Description
This function uses Gurobi to find prioritizations using the input parameterand data stored in aRapUnsolved() object, and returns aRapSolved() 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 aRapUnsolved() object thathas 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 objectdata(sim_ru)# solve it using Gurobisim_rs <- solve(sim_ru)# evaluate manually specified solution using planning unit indicessim_rs2 <- solve(sim_ru, seq_len(10))# evaluate manually specifed solution using binary selectionssim_rs3 <- solve(sim_ru, c(rep(TRUE, 10), rep(FALSE, 90)))# evaluate multiple manually specified solutionssim_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 asolution.
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 datadata(sim_rs)# space held (%) for each species in best solutionspace.held(sim_rs, 0)# space held (%) for each species in second solutionspace.held(sim_rs, 2)# space held (%) for each species in each solutionspace.held(sim_rs)## End(Not run)Plot space
Description
This function plots the distribution of planning units and the distributionof demand points for a particular species in an attribute space.Note that this function only works for attribute spaces with one, two, orthree 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 objectsdata(sim_ru, sim_rs)# plot first species in first attribute spacespace.plot(sim_ru, 1, 1)# plot distribution of solutions for first species in first attribute spacespace.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) <- valueArguments
x |
|
species |
|
space |
|
value |
|
Value
Anumeric ormatrix objects.
See Also
RapData(),RapResults(),RapSolved().
Examples
## Not run: # load datadata(sim_rs)# extract space targets for all speciesspace.target(sim_rs)# set space targets for all speciesspace.target(sim_rs) <- 0.1# extract target for first species for first spacespace.target(sim_rs, 1, 1)# set space targets for first species for first spacespace.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 theRgoogleMaps package to be installedin order to create display a basemap.
Examples
## Not run: # load RapSolved objectsdata(sim_ru, sim_rs)# plot first species in sim_ruspp.plot(sim_ru, species = 1)# plot "bimodal" species in sim_rsspp.plot(sim_rs, species = "bimodal")## End(Not run)Subset species
Description
Subset species from aRapData(),RapUnsolved(), orRapSolved() 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() orRapUnsolved() object dependingon input object.
See Also
RapData(),RapUnsolved(),RapSolved().
Examples
## Not run: # load datadata(sim_ru)# generate new object with only species 1sim_ru2 <- spp.subset(sim_ru, 1)## End(Not run)Summary of solutions
Description
Extracts summary of solutions in aRapResults() orRapSolved() object.
Arguments
object |
|
... | not used. |
Details
This table follows Marxan conventions(https://marxansolutions.org/). Thecolumns are:
- Run_Number
The index of each solution in the object.
- Status
The status of the solution. The values in this columncorrespond 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 betweenall planning units. All solutions in the same object should have equalvalues for this column.
- Connectivity_In
The amount of shared boundary length among planningunits selected in the solution.
- Connectivity_Edge
The amount of exposed boundary length in thesolution.
- Connectivity_Out
The number of shared boundary length among planningunits not selected in the solution.
- Connectivity_Fraction
The ratio of shared boundary length in thesolution (
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 moreefficient.
Value
data.frame
See Also
Examples
## Not run: # load datadata(sim_rs)# show summarysummary(sim_rs)## End(Not run)Update object
Description
This function updates parameters or data stored in an existingGurobiOpts(),RapUnreliableOpts(),RapReliableOpts(),RapData(),RapUnsolved(), orRapSolved() 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, orRapSolved objectdepending on argument tox.
See Also
GurobiOpts,RapUnreliableOpts,RapReliableOpts,RapData,RapUnsolved,RapSolved.
Examples
## Not run: # load datadata(sim_ru, sim_rs)# GurobiOptsx <- GurobiOpts(MIPGap = 0.7)y <- update(x, MIPGap = 0.1)print(x)print(y)# RapUnreliableOptsx <- RapUnreliableOpts(BLM = 10)y <- update(x, BLM = 2)print(x)print(y)# RapReliableOptsx <- RapReliableOpts(failure.multiplier = 2)y <- update(x, failure.multiplier = 4)print(x)print(y)# RapDatax <- sim_ru@datay <- update(x, space.target = c(0.4, 0.7, 0.1))print(space.target(x))print(space.target(y))## RapUnsolvedx <- sim_ruy <- 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))## RapSolvedx <- sim_rsy <- 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 ofvariation that one set of points captures in a another set of points usingthe 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 thatx explains iny
Examples
## Not run: urap.proportion.held(as.matrix(iris[1:2,-5]), as.matrix(iris[1:5,-5]))## End(Not run)