add_neighbor_constraints: Add neighbor constraints

Description Usage Arguments Value See Also Examples

Description

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

Usage

1

Arguments

x

ConservationProblem-class object.

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.

See Also

constraints for all the available constraints.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# create basic problem
p1 <- problem(sim_pu_polygons, sim_features) %>%
  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)


# solve problems
s <- list(solve(p1), solve(p2), solve(p3), solve(p4))

# plot solutions
par(mfrow=c(2,2))

plot(s[[1]], main="basic solution")
plot(s[[1]][s[[1]]$solution==1, ], col = "darkgreen", add = TRUE)

plot(s[[2]], main="1 neighbor")
plot(s[[2]][s[[2]]$solution==1, ], col = "darkgreen", add = TRUE)

plot(s[[3]], main="2 neighbors")
plot(s[[3]][s[[3]]$solution==1, ], col = "darkgreen", add = TRUE)

plot(s[[4]], main="3 neighbors")
plot(s[[4]][s[[4]]$solution==1, ], col = "darkgreen", add = TRUE)

prioritizr/prioritizrutils documentation built on May 25, 2019, 12:20 p.m.