generate_nsf: Generate neighbour selection function

Description Usage Arguments Details Value Examples

View source: R/generate-nsf.r

Description

Optimization by simulated annealing requires a function to select a neighbouring state to test given the current state. This function generates such a neighbour selection function. The resulting function will swap the status of a single planning unit.

Usage

1
generate_nsf(pu, buffer, locked, recalculate = 1L)

Arguments

pu

raster::RasterStack, sp::SpatialPolygonsDataFrame, or sf::sf object; planning units.

buffer

numeric; a buffer around the perimeter of the currently selected planning units in the units of the projection. Any planning units within this buffer will be considered for switching when generating a neighbouring state.

locked

name of a binary column (for vector data) or layer (for raster data) that specified planning units that are locked in or out and should be left unchanged. Alternatively, a integer vector of planning unit numbers may be supplied specifying units to leave unchanged.

recalculate

integer; frequency at which the set of planning units to consider for switching should be recalculated, e.g. a value of 100 would result in recalculating every 100 calls to the returned function. This process of recalculating can be computationally intensive for large sets of planning units, so choosing a larger value for recalculate will speed up processing time.

Details

In an attempt to more intelligently select a planning unit to switch, only those planning units meeting the following criteria will be considered:

This ensures that units in the interior of an existing reserve or far from an existing reserve are not changed.

Value

A function to choose a neighbouring state given a vector of binary decision variables. To return the list of planning units under consideration for switching use pu_list = TRUE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# generate data
r <- raster::raster(nrows = 10, ncols = 10, crs = "+proj=aea", vals = 0)
# lock some units to be unchanged
names(r) <- "locked_out"
r[sample(1:100, 10)] <- 1
pus <- raster::rasterToPolygons(r)
selected <- sample(c(FALSE, TRUE), 100, replace = TRUE, prob = c(0.9, 0.1))

# generate neighbour selection function
neighbour <- generate_nsf(pus, buffer = 20, locked = "locked_out")

# neighbouring solution
neighbour(selected)
neighbour(selected, pu_list = TRUE)

mstrimas/metacapa documentation built on Dec. 3, 2019, 3:16 p.m.