# NOT RUN {
# load data
data(sim_pu_points, sim_features)
# create a symmetric connectivity matrix where the connectivity between
# two planning units is the inverse distance between them
sc_matrix <- (1 / (as.matrix(dist(sim_pu_points@coords)) + 1))
# remove connections between planning units with little connectivity
sc_matrix[sc_matrix < 0.85] <- 0
# create basic problem
p1 <- problem(sim_pu_points, sim_features, "cost") %>%
add_min_set_objective() %>%
add_relative_targets(0.2)
# create problem with low connectivity penalties
p2 <- p1 %>% add_connectivity_penalties(25, sc_matrix)
# create problem with higher connectivity penalties
p3 <- p1 %>% add_connectivity_penalties(50, sc_matrix)
# create an asymmetric connectivity matrix where links from even numered
# units to odd numbered units have half the connectivity as from odd
# numbered units to even units
even_units <- seq(2, length(sim_pu_points), 2)
odd_units <- seq(1, length(sim_pu_points), 2)
ac_matrix <- sc_matrix
ac_matrix[even_units, odd_units] <- 0.5 * ac_matrix[even_units, odd_units]
# create problem with asymmetric connectivity and high penalties
p4 <- p1 %>% add_connectivity_penalties(50, ac_matrix)
# }
# 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]], pch = 19, main = "basic solution", cex = 1.5)
points(s[[1]][s[[1]]$solution_1 == 1, ], col = "darkgreen", pch = 19,
cex = 1.5)
plot(s[[2]], pch = 19, main = "small penalties", cex = 1.5)
points(s[[2]][s[[2]]$solution_1 == 1, ], col = "darkgreen", pch = 19,
cex = 1.5)
plot(s[[3]], pch = 19, main = "high penalties", cex = 1.5)
points(s[[3]][s[[3]]$solution_1 == 1, ], col = "darkgreen", pch = 19,
cex = 1.5)
plot(s[[4]], pch = 19, main = "asymmetric connectivity", cex = 1.5)
points(s[[4]][s[[4]]$solution_1 == 1, ], col = "darkgreen", pch=19,
cex = 1.5)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab