if (FALSE) {
# set seed for reproducibility
set.seed(500)
# load data
sim_zones_pu_raster <- get_sim_zones_pu_raster()
sim_zones_features <- get_sim_zones_features()
# create multi-zone problem with minimum set objective
targets_matrix <- matrix(rpois(15, 1), nrow = 5, ncol = 3)
# create minimal problem with minimum set objective
p1 <-
problem(sim_zones_pu_raster, sim_zones_features) %>%
add_min_set_objective() %>%
add_absolute_targets(targets_matrix) %>%
add_binary_decisions() %>%
add_default_solver(verbose = FALSE)
# create another problem that is the same as p1, but has constraints
# to mandate that every planning unit in the solution is assigned to
# zone
p2 <- p1 %>% add_mandatory_allocation_constraints()
# solve problems
s1 <- solve(p1)
s2 <- solve(p2)
# convert solutions into category layers, where each pixel is assigned
# value indicating which zone it was assigned to in the zone
c1 <- category_layer(s1)
c2 <- category_layer(s2)
# plot solution category layers
plot(c(c1, c2), main = c("default", "mandatory allocation"), axes = FALSE)
}
Run the code above in your browser using DataLab