# NOT RUN {
# set seed for reproducibility
set.seed(500)
# load data
data(sim_pu_zones_stack, sim_features_zones)
# 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_pu_zones_stack, sim_features_zones) %>%
add_min_set_objective() %>%
add_absolute_targets(targets_matrix) %>%
add_binary_decisions()
# 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()
# }
# NOT RUN {
# 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(stack(c1, c2), main = c("default", "mandatory allocation"),
axes = FALSE, box = FALSE)
# }
Run the code above in your browser using DataLab