This function is a thin wrapper around optim()
that performs conservation
prioritization using simulated annealing.
Usage
mc_prioritize(
objective,
nsf,
x,
n = 10000L,
itemp = 10,
n_temp = 10L,
maximize = TRUE,
verbose = TRUE
)
Arguments
- objective
an objective function to optimize over, typically created by
generate_objective()
.- nsf
a neighbour selection function, typically created by
generate_nsf()
.- x
logical vector specifying which planning units are selected as a starting point. Traditional conservation prioritization methods, such as those implemented by the
prioritizr
R package, can be used to generate starting solutions.- n
integer; number of simulated annealing iterations.
- itemp
numeric; initial temperature for the simulated annealing cooling schedule. Higher temperatures will result in bad changes being more likely to be accepted.
- n_temp
integer; number of objective function evaluations at each temperature in the annealing process.
- maximize
logical; whether the objective function is to be maximized or minimized. The standard objective function generated by
generate_objective()
is meant to be maximized.- verbose
logical; whether to print the simulated annealing output as the heuristic progresses.
Examples
# generate features
r <- raster::raster(nrows = 10, ncols = 10, crs = "+proj=laea",
vals = sample(0:1, 100, replace = TRUE))
s <- raster::stack(r, r, r)
s[[2]][] <- sample(0:1, 100, replace = TRUE, prob = c(0.6, 0.4))
s[[3]][] <- sample(0:1, 100, replace = TRUE, prob = c(0.8, 0.2))
names(s) <- c("a", "b", "c")
features <- raster::rasterToPolygons(s)
features <- sf::st_as_sf(features)
# cost
features$cost <- runif(nrow(features))
# dispersal functions
disp_f <- list(a = dispersal_negexp(1 / 0.01),
b = dispersal_negexp(1 / 0.005),
c = dispersal_negexp(1 / 0.02))
# calculate scale factors
scale_mc <- mc_reserve(features, rep(TRUE, nrow(features)), disp_f)
# set budget at 50% of total
budget <- 0.5 * sum(features$cost)
# build an objective function and neighbour selection function
objective <- generate_objective(features, disp_f, budget, delta = 0.001,
blm = 0.001, units = "km")
nsf <- generate_nsf(features, buffer = 20)
# random starting point
x_start <- sample(c(FALSE, TRUE), 100, replace = TRUE, prob = c(0.9, 0.1))
# optimize
mc_prioritize(objective, nsf, x_start, n = 50L)
#> sann objective function values
#> initial value 0.000748
#> final value 0.000748
#> sann stopped after 49 iterations
#> [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE
#> [25] FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
#> [37] TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [61] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE FALSE FALSE
#> [73] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE FALSE
#> [85] FALSE FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
#> [97] FALSE FALSE FALSE FALSE