Movatterモバイル変換


[0]ホーム

URL:


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 aRapUnsolved() 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:

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:


Create new AttributeSpace object

Description

This function creates a newAttributeSpace object.

Usage

AttributeSpace(planning.unit.points, demand.points, species)

Arguments

planning.unit.points

PlanningUnitPoints() for planningunit in the space.

demand.points

DemandPoints() object for the space.

species

integer species identifier to indicate which species thespace is associated with.

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.points

PlanningUnitPoints() object for planningunit in the space.

demand.points

DemandPoints() object for the space.

species

integer species 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

list ofAttributeSpace() objects fordifferent species.

name

character name to identify the attribute space.

Value

A newAttributeSpaces object.

See Also

AttributeSpace.

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

spaces

list ofAttributeSpace() objects fordifferent species.

name

character name to identify the attribute space.

See Also

AttributeSpace.


Create new DemandPoints object

Description

This function creates a newDemandPoints object

Usage

DemandPoints(coords, weights)

Arguments

coords

base::matrix() of coordinates for each demand point.

weights

numeric weights for each demand point.

Value

A newDemandPoints object.

See Also

DemandPoints.

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

coords

base::matrix() of coordinates for each demand point.

weights

numeric weights for each demand point.

See Also

DemandPoints().


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

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 to0L.

Presolve

integer code for level of computation in presolve(lp_solve parameter). Defaults to 2.

TimeLimit

integer number of seconds to allow for solving.Defaults toNA_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 obtainmultiple solutions (used whenNumberSolutions is greater than one).Available options are"benders.cuts","solution.pool.0","solution.pool.1", and"solution.pool.2". The"benders.cuts" method produces a set of distinct solutions 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".

NumericFocus

integer how much effort should Gurobi focus onaddressing numerical issues? Defaults to0L such that minimal effortis spent to reduce run time.

Value

GurobiOpts object

See Also

GurobiOpts.

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

Threads

integer number of cores to use for processing. Defaultsto 1L.

MIPGap

numeric MIP gap specifying minimum solution quality.Defaults to 0.1.

Method

integer Algorithm to use for solving model. Defaults to0L.

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 obtainmultiple solutions (used whenNumberSolutions is greater than one).Available options are"benders.cuts","solution.pool.0","solution.pool.1", and"solution.pool.2". The"benders.cuts" method produces a set of distinct solutions 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".

NumericFocus

integer how much effort should Gurobi focus onaddressing numerical issues? Defaults to0L such that minimal effortis spent to reduce run time.

See Also

GurobiOpts().


Create ManualOpts object

Description

This function creates a new ManualOpts object.

Usage

ManualOpts(NumberSolutions = 1L)

Arguments

NumberSolutions

integer number of solutions to generate.Defaults to 1L.

Value

A newManualOpts() object

See Also

ManualOpts.

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

NumberSolutions

integer number of solutions.

See Also

ManualOpts().


Create new PlanningUnitPoints object

Description

This function creates a newPlanningUnitPoints object.

Usage

PlanningUnitPoints(coords, ids)

Arguments

coords

base::matrix() coordinates for each point.

ids

integer planning unit ids.

Value

A newPlanningUnitPoints object.

See Also

AttributeSpace.

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

coords

base::matrix() coordinates for each point.

ids

integer planning unit ids.

See Also

AttributeSpace().


PolySet

Description

Object contains PolySet data.

See Also

PBSmapping::PolySet().


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

base::data.frame() planning unit data. Columns must be"cost" (numeric), "area" (numeric), and "status"(integer).

species

base::data.frame() with species data. Columnsmust 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 onthe probability of species in each planning unit. Columns must be"species", (integer), "pu" (integer), and "value"(numeric).

attribute.spaces

list ofAttributeSpaces() objectswith the demand points and planning unit coordinates.

boundary

base::data.frame() with data on the sharedboundary length of planning units. Columns must be "id1"(integer), "id2" (integer), and "boundary" (integer).

polygons

PBSmapping::PolySet() planning unit spatial dataorNULL if data not available.

skipchecks

logical Skip data integrity checks? May improvespeed for big data sets.

.cache

base::environment() used to cache calculations.

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

polygons

PBSmapping::PolySet() planning unit spatial dataorNULL 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 mustbe "name" (character.

targets

base::data.frame() with species data. Columns mustbe "species" (integer), "target" (integer), "proportion"(numeric).

pu.species.probabilities

base::data.frame() with data onthe probability of species in each planning unit. Columns must be "species"(integer), "pu" (integer), and "value" (numeric).

attribute.spaces

list ofAttributeSpaces objects withthe demand points and planning unit coordinates.

boundary

base::data.frame() with data on the sharedboundary length of planning units. Columns must be "id1" (integer),"id2" (integer), and "boundary" (numeric).

skipchecks

logical Skip data integrity checks? May improvespeed for big data sets.

.cache

base::environment() used to cache calculations.

See Also

PBSmapping::PolySet().


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

numeric boundary length modifier. Defaults to 0.

failure.multiplier

numeric multiplier for failure planningunit. Defaults to 1.1.

max.r.level

numeric maximum R failure level for approximation.Defaults to 5L.

Value

RapReliableOpts object

See Also

RapReliableOpts.

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

BLM

numeric boundary length modifier. Defaults to 0.

failure.multiplier

numeric multiplier for failure planningunit. Defaults to 1.1.

max.r.level

numeric maximum R failure level for approximation.Defaults to 5L.

See Also

RapReliableOpts().


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

base::data.frame() with summary information onsolutions. See details below for more information.

selections

base::matrix() with binary selections. Thecellx_{ij} denotes if planning unitj is selected in thei'th solution.

amount.held

base::matrix() with the amount held for eachspecies in each solution.

space.held

base::matrix() with the proportion ofattribute space sampled for each species in each solution.

logging.file

character Gurobi log files.

.cache

base::environment() used to cache calculations.

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

RapResultsread.RapResults().


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

summary

base::data.frame() with summary information onsolutions.

selections

base::matrix() with binary selections. The cellx_{ij} denotes if planning unitj is selected in thei'th solution.

amount.held

base::matrix() with the amount held for eachspecies in each solution.

space.held

base::matrix() with the proportion of attributespace sampled for each species in each solution.

best

integer with index of best solution.

logging.file

character Gurobi log files.

.cache

base::environment() used to store extra data.

See Also

RapResults(),read.RapResults().


Create new RapSolved object

Description

This function creates aRapSolved() object.

Usage

RapSolved(unsolved, solver, results)

Arguments

unsolved

RapUnsolved() object.

solver

GurobiOpts() orManualOpts() object.

results

RapResults() object.

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

opts

RapReliableOpts() orRapUnreliableOpts()object used to store input parameters.

solver

GurobiOpts() orManualOpts() objectused to store solver information/parameters.

data

RapData() object used to store input data.

results

RapResults() object used to store results.

See Also

RapReliableOpts,RapUnreliableOpts,RapData,RapResults.


Create RapUnreliableOpts object

Description

This function creates a new RapUnreliableOpts object.

Usage

RapUnreliableOpts(BLM = 0)

Arguments

BLM

numeric boundary length modifier. Defaults to 0.

Value

RapUnreliableOpts() object

See Also

RapUnreliableOpts.

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

BLM

numeric boundary 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

RapReliableOpts() orRapUnreliableOpts()object.

data

RapData() object.

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

opts

RapReliableOpts() orRapUnreliableOpts()object used to store input parameters.

data

RapData() object used to store input data.

See Also

RapReliableOpts,RapUnreliableOpts,RapData.


SolverOpts class

Description

Object stores parameters used to solve problems.

See Also

GurobiOpts().


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

RapResults() orRapSolved() object.

y

Available inputs include:NULL to return all values,integer number specifying the solution for which the value shouldbe returned, and0 to return the value for the best solution.

species

NULL for all species orinteger indicatingspecies.

Value

base::matrix() ornumeric vector depending onarguments.

See Also

RapResults(),RapSolved().

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) <- value

Arguments

x

RapData(),RapUnsolved(), orRapSolved() object.

species

NULL for all species orinteger indicatingspecies.

value

numeric new target.

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

GurobiOpts() object.

...

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

RapData,RapUnsolved,RapSolved object.

basemap

character type of base map to display. Valid names are"roadmap","mobile","satellite","terrain","hybrid","mapmaker-roadmap","mapmaker-hybrid".

grayscale

logical should base map be gray scale?

force.reset

logical ignore data in cache? Setting this asignore will make function slower but may avoid bugs in cache system.

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

sf::st_sf() object.

res

numericvector specifying resolution of the output rasterin the x and y dimensions. Ifvector is of length one, then thepixels are assumed to be square.

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

RapData orRapResults object

name

character hash.

y

ifANY this object gets cached with name, else ifmissing the object hashed at name gets returned.

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

sf::st_sf() orPBSMapping::PolySet object.

tol

numeric to specify precision of calculations. In otherwords, how far apart vertices have to be to be considered different?

length.factor

numeric to scale boundary lengths.

edge.factor

numeric to scale boundary lengths for edges thatdo not have any neighbors, such as those that occur along the margins.

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

sf::st_as_sf() object.

...

not used.

y

terra::rast() object.

ids

integer vector of ids. Defaults to indices of layers inargument toy.

field

integer index orcharacter name of column withplanning unit ids. Valid only whenx is asf::st_sf() orsp::SpatialPolygonsDataFrame() object.Default behavior is to treat each polygon as a different planning unit.

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 as30km^2 squares 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. Thearea field denotesthe amount of land encompassed by each unit, thecostfield is set to 1 for all units, and thestatus fieldindicates 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 to10km^2 resolution).

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

sf::st_sf(),sp::SpatialPolygons() orsp::SpatialPolygonsDataFrame() object.

n_preallocate

integer How much memory should be preallocatedfor processing? Ideally, this number should equal the number of verticesin thesp::SpatialPolygons() object. If data processing istaking too long consider increasing this value.

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

RapData(),RapUnsolved(), orRapSolved() object.

space

integer vector to specify the index of the space tosubset demand points from.

species

integer vector to specify the index of the species tosubset demand points from.

points

integer vector to specify the index of demand points tosubset.

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

logical should messages be printed?

Value

logical Is it installed and ready to use?

See Also

base::options().

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

RapData orRapResults object

name

character hash.

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

RapData,RapUnsolved, orRapSolved object.

y

RapData,RapUnsolved, orRapSolved object.

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

RapResults() orRapSolved() object.

y

Available inputs include:NULL to return all values,integer number specifying the solution for which the log file shouldbe returned, and0 to return log file for the best solution.

Note

The term logging file was used due to collisions with thelogfunction.

See Also

RapResults(),RapSolved().

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

base::matrix() object containing points.

n

integer number of demand points to use for each attributespace for each species. Defaults to100L.

quantile

numeric quantile to generate demand points within. If0 then demand points are generated across the full range of values thepoints intersect. Defaults to0.5.

kernel.method

character name of kernel method to use togenerate demand points. Defaults to'ks'.

...

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

sf::st_as_sf() with planning unit data.

species

terra::rast() with species probabilitydistribution data.

spaces

list of/orterra::rast() representingprojects of attribute space over geographic space. Use alist todenote separate attribute spaces.

amount.target

numeric vector for area targets (%) for eachspecies. Defaults to 0.2 for each attribute space for each species.

space.target

numeric vector for attribute space targets (%)for each species. Defaults to 0.2 for each attribute space for eachspecies and each space.

n.demand.points

integer number of demand points to use foreach attribute space for each species. Defaults to 100L.

kernel.method

character name of kernel method to use togenerate demand points. Use either"ks" or"hypervolume".

quantile

numeric quantile to generate demand points within. Ifspecies.points intersect. Defaults to 0.5.

species.points

list of/orsf::st_sf() object species presencerecords. Use alist of objects to represent different species. Must have the samenumber of elements asspecies. If not supplied then usen.species.points to sample points from the species distributions.

n.species.points

numeric vector specifying the number pointsto sample the species distributions to use to generate demand points.Defaults to 20% of the distribution.

include.geographic.space

logical should the geographic spacebe considered an attribute space?

scale

logical scale the attribute spaces to unit mean andstandard deviation? This prevents overflow. Defaults toTRUE.

verbose

logical print statements during processing?

...

additional arguments tocalcBoundaryData() andcalcSpeciesAverageInPus().

Value

A newRapData object.

See Also

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"))# 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

RapUnsolved() orRapSolved() object.

verbose

logical should messages be printed duringcalculations? Defaults toFALSE.

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

RapData(),RapUnsolved(), orRapSolved() object.

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

RapSolved() object.

y

Available inputs are:NULL to plot selection frequencies,numeric number to plot a specific solution,0 to plot the best solution, and aRapSolved()object to plot differences in solutions between objects. Defaults toNULL.

basemap

character object indicating the type of basemap to use(seebasemap()). Valid options include"none","roadmap","mobile","satellite","terrain","hybrid","mapmaker-roadmap","mapmaker-hybrid".Defaults to"none" such that no basemap is shown.

pu.color.palette

character vector of colors to indicateplanning unit statuses.If plotting selection frequencies (i.e.,j = NULL), thendefaults to ac("PuBu", "#FFFF00", "#FF0000").Here, the first element corresponds to a color palette(perRColorBrewer::brewer.pal()) and the last two elementsindicate the colors for locked in and locked out planning units.Otherwise, the parameter defaults to acharacter vector ofc("grey30", "green", "yellow", "black", "gray80", "red", "orange").

alpha

numeric value to indicating the transparency level forcoloring the planning units.

grayscale

logical should the basemap be gray-scaled?

main

character title for the plot. Defaults toNULL anda default title is used.

force.reset

logical if basemap data has been cached, should itbe re-downloaded?

i

Available inputs are:NULL to plot selection frequencies.numeric to plot a specific solution,0 to plot the bestsolution. This argument is only used wheny is aRapSolved() object. Defaults toNULL.

j

Available inputs are:NULL to plot selection frequencies.numeric to plot a specific solution,0 to plot the bestsolution. This argument is only used wheny is aRapSolved() object. Defaults to argumentj.

Details

This function requires theRgoogleMaps package to be installedin order to create display a basemap.

See Also

RapSolved().

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

GurobiOpts(),RapUnreliableOpts(),RapReliableOpts(),RapData(),RapUnsolved(),RapResults(), orRapSolved() object.

...

not used.

header

logical should object header be included?

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

RapData(),RapUnsolved(), orRapSolved() object.

species

integer vector specifying the index of the species towhich the threshold should be applied.

threshold

numeric probability to use a 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

RapData(),RapUnsolved(), orRapSolved() object.

pu

integer vector to specify the index of planning units tosubset.

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

terra::rast() object

n

integer number of points to sample

prob

logical should the raster values be used as weights?Defaults toFALSE.

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

sf::st_as_sf() object representing planningunits.

species

terra::rast() object with species distributiondata.

spaces

terra::rast() orlist ofterra::rast() objects. Eachelements denotes the spatial distribution for each space. Defaults toNULL such that spaces are generated automatically.

formulation

character to indicate if the"unreliable" or"reliable" formulation should be used to generate prioritizations.Defaults to"unreliable".

solve

logical should solutions be generated?

...

arguments are passed toGurobiOpts(),make.RapData(), andRapReliableOpts() orRapUnreliableOpts() functions.

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 theconvert2PolySet() 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

RapReliableOpts orRapUnreliableOpts object

data

RapData object

model.list

list object containing Gurobi model data

logging.file

character Gurobi log files.

solution.list

list object containing Gurobi solution data.

verbose

logical print progress messages? Defaults toFALSE.

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

base::matrix() of planning unitcoordinates.

pu.probabilities

numeric vector of planning unit probabilities.

dp.coordinates

base::matrix() of demand point coordinates.

dp.weights

numeric vector of demand point weights.

failure.distance

numeric indicating the cost of the failureplanning unit.

maximum.r.level

integer maximum failure (R) level to use forcalculations.

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

RapResults() orRapSolved() object.

y

Available inputs include:NULL to return all scores,integer number specifying the solution for which the score shouldbe returned, and0 to return score for the best solution.

Value

matrix ornumeric vector with solution score(s)depending on arguments.

See Also

RapResults(),RapSolved().

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

RapResults() orRapSolved() object.

y

NULL to return all values,integer 0 to return valuesfor the best solution,integer value greater than 0 fory'thsolution value.

Value

base::matrix() ornumeric vector depending onarguments.

See Also

RapResults(),RapSolved().

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

GurobiOpts(),RapUnreliableOpts(),RapReliableOpts(),RapData(),RapUnsolved(),RapResults(), orRapSolved() 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

integer number of planning units. Notesqrt(n) must yielda valid number.

xmn

numeric value for minimum x-coordinate.

xmx

numeric value for maximum x-coordinate.

ymn

numeric value for minimum y-coordinate.

ymx

numeric value for maximum y-coordinate.

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

terra::rast() orsf::st_sf() object delineatingthe spatial extent for the study area.

...

not used.

d

integer number of dimensions. Defaults to 2.

model

numeric scale parameter for simulating spatiallyauto-correlated data using Gaussian random fields.Higher values produce patchier data with more well defined clusters,and lower values produce more evenly distributed data.Defaults to 0.2.

res

numeric resolution to simulate distributions. Only neededwhensf::st_sf() are supplied.

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

terra::rast() orsf::st_sf() object delineatingthe spatial extent for the study area.

...

not used.

n

integer number of species. Defaults to 1.

model

character ornumeric for simulating data.If acharacter value is supplied, then the following values cancan be used to simulate species distributions with particularcharacteristics:"uniform","normal", and"bimodal".If anumeric value is supplied, then this is used to simulatespecies distributions using a Gaussian random field, where thenumeric value is treated as the scale parameter.Defaults to"normal".

res

numeric resolution to simulate distributions. Only neededwhensf::st_sf() are supplied.

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

RapUnsolved() orRapSolved() object.

b

missing to generate solutions using Gurobi. Prioritizationscan be specified usinglogical,numeric, orbase::matrix() objects. This may be useful for evaluating theperformance of solutions obtained using other software.

...

not used.

verbose

logical should messages be printed during creation ofthe initial model matrix?.

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

RapUnsolved(),RapSolved().

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

RapResults() orRapSolved() object.

y

Available inputs include:NULL to return all values,integer number specifying the solution for which the value shouldbe returned, and0 to return the value for the best solution.

species

NULL for all species orinteger indicatingspecies.

space

NULL for all spaces orinteger indicating aspecific space.

Value

matrix object.

See Also

RapResults(),RapSolved().

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

RapData(),RapUnsolved(), orRapSolved() object.

species

character name of species, orinteger index forspecies.

space

integer index of attribute space.

...

not used.

pu.color.palette

character vector of colors indicate planning unitstatuses. Defaults toc("grey30", "green", "black", "red") whichindicate not selected, selected, locked in, and locked out (respectively).

main

character title for the plot. Defaults toNULL anda default title is used.

y

integer number specifying the solution to be plotted. Thevalue0 can be used to plot the best solution.

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) <- value

Arguments

x

RapData(),RapUnsolved(), orRapSolved() object.

species

NULL for all species orinteger indicating species.

space

NULL for all spaces orinteger indicating a space.

value

numeric new target.

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

RapData(),RapUnsolved(), orRapSolved() object.

species

character name of species, orinteger index forspecies.

...

not used.

prob.color.palette

character name of color palette to denoteprobability of occupancy of the species in planning units (seeRColorBrewer::brewer.pal()). Defaults to"YlGnBu".

pu.color.palette

character vector of colors to indicate planningunit statuses. Defaults toc("grey30", "green", "black", "red") whichindicate not selected, selected, locked in, and locked out (respectively).

basemap

character object indicating the type of basemap to use(seebasemap()). Valid options include"none","roadmap","mobile","satellite","terrain","hybrid","mapmaker-roadmap","mapmaker-hybrid".Defaults to"none" such that no basemap is shown.

alpha

numeric value to indicating the transparency level forcoloring the planning units.

grayscale

logical should the basemap be gray-scaled?

main

character title for the plot. Defaults toNULL anda default title is used.

force.reset

logical if basemap data has been cached, should itbe re-downloaded?

y

NULLinteger 0 to return values for the bestsolution,integer value greater than 0 fory'th solutionvalue.

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

RapData(),RapUnsolved(), orRapSolved() object.

species

integer, orcharacter vectors to specify theindex or species names to subset.

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

RapResults(), orRapSolved() 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

RapResults(),RapSolved().

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

GurobiOpts(),RapUnreliableOpts(),RapReliableOpts(),RapData(),RapUnsolved(), orRapSolved() object.

Threads

integer number of cores to use for processing.

MIPGap

numeric MIP gap specifying minimum solution quality.

Method

integer Algorithm to use for solving model.

Presolve

integer code for level of computation in presolve.

TimeLimit

integer number of seconds to allow for solving.

NumberSolutions

integer number of solutions to generate.

MultipleSolutionsMethod

integer name of method to obtainmultiple solutions (used whenNumberSolutions is greater than one).Available options are"benders.cuts","solution.pool.0","solution.pool.1", and"solution.pool.2". The"benders.cuts" method produces a set of distinct solutions 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".

NumericFocus

integer how much effort should Gurobi focus onaddressing numerical issues? Defaults to0L such that minimal effortis spent to reduce run time.

...

parameters passed toupdate.RapReliableOpts(),update.RapUnreliableOpts(), orupdate.RapData().

species

integer orcharacter denoting species for whichtargets or name should be updated.

space

integer denoting space for which targets should beupdated.

name

character to rename species.

amount.target

numeric vector for new area targets (%) for thespecified species.

space.target

numeric vector for new attribute space targets(%) for the specified species and attribute spaces.

pu

integer planning unit indices that need to be updated.

cost

numeric new costs for specified planning units.

status

integer new statuses for specified planning units.

BLM

numeric boundary length modifier.

failure.multiplier

numeric multiplier for failure planningunit.

max.r.level

numeric maximum R failure level for approximation.

formulation

character indicating new problem formulation touse. This can be either "unreliable" or "reliable". The default isNULL so that formulation inobject is used.

solve

logical should the problem be solved? This argument isonly valid forRapUnsolved() andRapSolved()objects. Defaults toTRUE.

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

base::matrix() of points

y

base::matrix() of points

y.weights

numeric vector of weights for each point iny. Defaults to equal weights for all points iny.

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)

[8]ページ先頭

©2009-2025 Movatter.jp