# NOT RUN {
# load data
data(sim_pu_raster, sim_pu_zones_stack, sim_features, sim_features_zones)
# threshold the feature data to generate binary biodiversity data
sim_binary_features <- sim_features
thresholds <- raster::quantile(sim_features, probs = 0.95, names = FALSE,
na.rm = TRUE)
for (i in seq_len(raster::nlayers(sim_features)))
sim_binary_features[[i]] <- as.numeric(raster::values(sim_features[[i]]) >
thresholds[[i]])
# create problem with maximum utility objective
p1 <- problem(sim_pu_raster, sim_binary_features) %>%
add_max_cover_objective(500) %>%
add_binary_decisions()
# }
# NOT RUN {
# solve problem
s1 <- solve(p1)
# plot solution
plot(s1, main = "solution", axes = FALSE, box = FALSE)
# }
# NOT RUN {
# threshold the multi-zone feature data to generate binary biodiversity data
sim_binary_features_zones <- sim_features_zones
for (z in number_of_zones(sim_features_zones)) {
thresholds <- raster::quantile(sim_features_zones[[z]], probs = 0.95,
names = FALSE, na.rm = TRUE)
for (i in seq_len(number_of_features(sim_features_zones))) {
sim_binary_features_zones[[z]][[i]] <- as.numeric(
raster::values(sim_features_zones[[z]][[i]]) > thresholds[[i]])
}
}
# create multi-zone problem with maximum utility objective that
# has a single budget for all zones
p2 <- problem(sim_pu_zones_stack, sim_binary_features_zones) %>%
add_max_cover_objective(800) %>%
add_binary_decisions()
# }
# NOT RUN {
# solve problem
s2 <- solve(p2)
# plot solution
plot(category_layer(s2), main = "solution", axes = FALSE, box = FALSE)
# }
# NOT RUN {
# create multi-zone problem with maximum utility objective that
# has separate budgets for each zone
p3 <- problem(sim_pu_zones_stack, sim_binary_features_zones) %>%
add_max_cover_objective(c(400, 400, 400)) %>%
add_binary_decisions()
# }
# NOT RUN {
# solve problem
s3 <- solve(p3)
# plot solution
plot(category_layer(s3), main = "solution", axes = FALSE, box = FALSE)
# }
Run the code above in your browser using DataLab