# NOT RUN {
# set seed for reproducibility
set.seed(500)
# load data
data(sim_pu_raster, sim_features, sim_pu_zones_stack, sim_features_zones)
# create minimal problem with shuffle portfolio
p1 <- problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_relative_targets(0.2) %>%
add_shuffle_portfolio(10, remove_duplicates = FALSE) %>%
add_default_solver(gap = 0.2, verbose = FALSE)
# }
# NOT RUN {
# solve problem and generate 10 solutions within 20 % of optimality
s1 <- solve(p1)
# plot solutions in portfolio
plot(stack(s1), axes = FALSE, box = FALSE)
# }
# NOT RUN {
# build multi-zone conservation problem with shuffle portfolio
p2 <- problem(sim_pu_zones_stack, sim_features_zones) %>%
add_min_set_objective() %>%
add_relative_targets(matrix(runif(15, 0.1, 0.2), nrow = 5,
ncol = 3)) %>%
add_binary_decisions() %>%
add_shuffle_portfolio(10, remove_duplicates = FALSE) %>%
add_default_solver(gap = 0.2, verbose = FALSE)
# }
# NOT RUN {
# solve the problem
s2 <- solve(p2)
# print solution
str(s2, max.level = 1)
# plot solutions in portfolio
plot(stack(lapply(s2, category_layer)), main = "solution", axes = FALSE,
box = FALSE)
# }
Run the code above in your browser using DataLab