# NOT RUN {
## load data
data(sim_pu_points, sim_features)
## create basic problem
p1 <- problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_relative_targets(0.2) %>%
add_default_solver()
## create problem with boundary penalties
p2 <- p1 %>% add_boundary_penalties(5, 1)
## create problem with connectivity penalties
# create connectivity matrix based on spatial proximity
sc_matrix <- as.data.frame(sim_pu_raster, xy = TRUE)
sc_matrix <- sc_matrix[is.finite(values(sim_pu_raster)), 1:2]
sc_matrix <- 1 / (as.matrix(dist(sc_matrix)) + 1)
# remove connections between planning units with little connectivity
sc_matrix[sc_matrix < 0.85] <- 0
# create problem
p3 <- p1 %>% add_connectivity_penalties(25, sc_matrix)
# }
# NOT RUN {
## solve problems
s <- stack(solve(p1), solve(p2), solve(p3))
# plot solutions
plot(s, axes = FALSE, box = FALSE,
main = c("basic solution", "boundary penalties",
"connectivity penalties"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab