Learn R Programming

prioritizr (version 3.0.4)

add_neighbor_constraints: Add neighbor constraints

Description

Add constraints to a conservation problem to ensure that all selected planning units have at least a certain number of neighbors.

Usage

add_neighbor_constraints(x, k, ...)

Arguments

k

integer number of neighbors each selected planning units must have.

...

arguments passed to connected_matrix.

Value

ConservationProblem-class object with the constraint added to it.

Details

The mathematical ideas that underpin this function inspired by Billionnet (2013).

References

Billionnet A (2013) Mathematical optimization ideas for biodiversity conservation. European Journal of Operational Research, 231: 514--534.

See Also

constraints for all the available constraints, and penalties.

Examples

Run this code
# 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