# NOT RUN {
# create basic problem
p1 <- problem(sim_pu_polygons, sim_features, "cost") %>%
add_min_set_objective() %>%
add_relative_targets(0.2)
# create problem with constraints that require 1 neighbor
p2 <- p1 %>% add_neighbor_constraints(1)
# create problem with constraints that require 2 neighbors
p3 <- p1 %>% add_neighbor_constraints(2)
# create problem with constraints that require 3 neighbors
p4 <- p1 %>% add_neighbor_constraints(3)
# }
# NOT RUN {
# solve problems
s <- list(solve(p1), solve(p2), solve(p3), solve(p4))
# plot solutions
par(mfrow = c(2,2), mar = c(0, 0, 4.1, 0))
plot(s[[1]], main = "basic solution")
plot(s[[1]][s[[1]]$solution_1 == 1, ], col = "darkgreen", add = TRUE)
plot(s[[2]], main="1 neighbor")
plot(s[[2]][s[[2]]$solution_1 == 1, ], col = "darkgreen", add = TRUE)
plot(s[[3]], main="2 neighbors")
plot(s[[3]][s[[3]]$solution_1 == 1, ], col = "darkgreen", add = TRUE)
plot(s[[4]], main="3 neighbors")
plot(s[[4]][s[[4]]$solution_1 == 1, ], col = "darkgreen", add = TRUE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab