if (FALSE) {
# set seed for reproducibility
set.seed(500)
# load data
sim_pu_raster <- get_sim_pu_raster()
sim_features <- get_sim_features()
sim_zones_pu_raster <- get_sim_zones_pu_raster()
sim_zones_features <- get_sim_zones_features()
# create minimal problem with no targets
p0 <-
problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_binary_decisions() %>%
add_default_solver(verbose = FALSE)
# create problem with targets to secure 3 amounts for each feature
p1 <- p0 %>% add_absolute_targets(3)
# create problem with varying targets for each feature
targets <- c(1, 2, 3, 2, 1)
p2 <- p0 %>% add_absolute_targets(targets)
# solve problem
s1 <- c(solve(p1), solve(p2))
names(s1) <- c("equal targets", "varying targets")
# plot solution
plot(s1, axes = FALSE)
# create a problem with multiple management zones
p3 <-
problem(sim_zones_pu_raster, sim_zones_features) %>%
add_min_set_objective() %>%
add_binary_decisions() %>%
add_default_solver(verbose = FALSE)
# create a problem with targets that specify an equal amount of each feature
# to be represented in each zone
p4_targets <- matrix(
2,
nrow = number_of_features(sim_zones_features),
ncol = number_of_zones(sim_zones_features),
dimnames = list(
feature_names(sim_zones_features), zone_names(sim_zones_features)
)
)
print(p4_targets)
p4 <- p3 %>% add_absolute_targets(p4_targets)
# solve problem
s4 <- solve(p4)
# plot solution (pixel values correspond to zone identifiers)
plot(category_layer(s4), main = "equal targets", axes = FALSE)
# create a problem with targets that require a varying amount of each
# feature to be represented in each zone
p5_targets <- matrix(
rpois(15, 1),
nrow = number_of_features(sim_zones_features),
ncol = number_of_zones(sim_zones_features),
dimnames = list(
feature_names(sim_zones_features),
zone_names(sim_zones_features)
)
)
print(p5_targets)
p5 <- p3 %>% add_absolute_targets(p5_targets)
# solve problem
s5 <- solve(p5)
# plot solution (pixel values correspond to zone identifiers)
plot(category_layer(s5), main = "varying targets", axes = FALSE)
}
Run the code above in your browser using DataLab