# 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 simple problem
p <- problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_binary_decisions()
# create problem with targets to secure 3 amounts for each feature
p1 <- p %>% add_absolute_targets(3)
# create problem with varying targets for each feature
targets <- c(1, 2, 3, 2, 1)
p2 <- p %>% add_absolute_targets(targets)
# }
# NOT RUN {
# solve problem
s <- stack(solve(p1), solve(p2))
# plot solution
plot(s, main = c("equal targets", "varying targets"), axes = FALSE,
box = FALSE)
# }
# NOT RUN {
# create a problem with multiple management zones
p3 <- problem(sim_pu_zones_stack, sim_features_zones) %>%
add_min_set_objective() %>%
add_binary_decisions()
# 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_features_zones),
ncol = number_of_zones(sim_features_zones),
dimnames = list(feature_names(sim_features_zones),
zone_names(sim_features_zones)))
print(p4_targets)
p4 <- p3 %>% add_absolute_targets(p4_targets)
# solve problem
# }
# NOT RUN {
# solve problem
s4 <- solve(p4)
# plot solution (pixel values correspond to zone identifiers)
plot(category_layer(s4), main = c("equal targets"))
# }
# NOT RUN {
# 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_features_zones),
ncol = number_of_zones(sim_features_zones),
dimnames = list(feature_names(sim_features_zones),
zone_names(sim_features_zones)))
print(p5_targets)
p5 <- p3 %>% add_absolute_targets(p4_targets)
# solve problem
# }
# NOT RUN {
# solve problem
s5 <- solve(p5)
# plot solution (pixel values correspond to zone identifiers)
plot(category_layer(s5), main = c("varying targets"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab