Add constraints to a conservation planning problem to ensure that specific planning units are not selected (or allocated to a specific zone) in the solution. For example, it may be useful to lock out planning units that have been degraded and are not suitable for conserving species. If specific planning units should be locked in to the solution, use add_locked_out_constraints. For problems with non-binary planning unit allocations (e.g. proportions), the add_manual_locked_constraints function can be used to lock planning unit allocations to a specific value.

add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,numeric
add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,logical
add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,matrix
add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,character
add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,Spatial
add_locked_out_constraints(x, locked_out)

# S4 method for ConservationProblem,Raster
add_locked_out_constraints(x, locked_out)

Arguments

x

ConservationProblem-class object.

locked_out

Object that determines which planning units that should be locked out. See the Details section for more information.

Examples

# set seed for reproducibility set.seed(500) # load data data(sim_pu_polygons, sim_features, sim_locked_out_raster) # create minimal problem p1 <- problem(sim_pu_polygons, sim_features, "cost") %>% add_min_set_objective() %>% add_relative_targets(0.2) %>% add_binary_decisions() # create problem with added locked out constraints using integers p2 <- p1 %>% add_locked_out_constraints(which(sim_pu_polygons$locked_out)) # create problem with added locked out constraints using a field name p3 <- p1 %>% add_locked_out_constraints("locked_out") # create problem with added locked out constraints using raster data p4 <- p1 %>% add_locked_out_constraints(sim_locked_out_raster) # create problem with added locked out constraints using spatial polygon data locked_out <- sim_pu_polygons[sim_pu_polygons$locked_out == 1, ] p5 <- p1 %>% add_locked_out_constraints(locked_out)
# solve problems s1 <- solve(p1)
#> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Coefficient statistics: #> Matrix range [2e-01, 9e-01] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [6e+00, 1e+01] #> Found heuristic solution: objective 3934.6218396 #> Presolve time: 0.00s #> Presolved: 5 rows, 90 columns, 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Presolved: 5 rows, 90 columns, 450 nonzeros #> #> #> Root relaxation: objective 3.496032e+03, 16 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3496.03193 0 4 3934.62184 3496.03193 11.1% - 0s #> H 0 0 3585.9601335 3496.03193 2.51% - 0s #> #> Explored 1 nodes (16 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3585.96 3934.62 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.585960133519e+03, best bound 3.496031931890e+03, gap 2.5078%
s2 <- solve(p2)
#> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Coefficient statistics: #> Matrix range [2e-01, 9e-01] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [6e+00, 1e+01] #> Found heuristic solution: objective 3953.6827496 #> Presolve removed 0 rows and 10 columns #> Presolve time: 0.00s #> Presolved: 5 rows, 80 columns, 400 nonzeros #> Variable types: 0 continuous, 80 integer (80 binary) #> Presolved: 5 rows, 80 columns, 400 nonzeros #> #> #> Root relaxation: objective 3.501746e+03, 10 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3501.74555 0 4 3953.68275 3501.74555 11.4% - 0s #> H 0 0 3591.1771615 3501.74555 2.49% - 0s #> #> Explored 1 nodes (10 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3591.18 3953.68 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.591177161528e+03, best bound 3.501745549307e+03, gap 2.4903%
s3 <- solve(p3)
#> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Coefficient statistics: #> Matrix range [2e-01, 9e-01] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [6e+00, 1e+01] #> Found heuristic solution: objective 3953.6827496 #> Presolve removed 0 rows and 10 columns #> Presolve time: 0.00s #> Presolved: 5 rows, 80 columns, 400 nonzeros #> Variable types: 0 continuous, 80 integer (80 binary) #> Presolved: 5 rows, 80 columns, 400 nonzeros #> #> #> Root relaxation: objective 3.501746e+03, 10 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3501.74555 0 4 3953.68275 3501.74555 11.4% - 0s #> H 0 0 3591.1771615 3501.74555 2.49% - 0s #> #> Explored 1 nodes (10 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3591.18 3953.68 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.591177161528e+03, best bound 3.501745549307e+03, gap 2.4903%
s4 <- solve(p4)
#> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Coefficient statistics: #> Matrix range [2e-01, 9e-01] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [6e+00, 1e+01] #> Found heuristic solution: objective 3953.6827496 #> Presolve removed 0 rows and 10 columns #> Presolve time: 0.00s #> Presolved: 5 rows, 80 columns, 400 nonzeros #> Variable types: 0 continuous, 80 integer (80 binary) #> Presolved: 5 rows, 80 columns, 400 nonzeros #> #> #> Root relaxation: objective 3.501746e+03, 10 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3501.74555 0 4 3953.68275 3501.74555 11.4% - 0s #> H 0 0 3591.1771615 3501.74555 2.49% - 0s #> #> Explored 1 nodes (10 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3591.18 3953.68 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.591177161528e+03, best bound 3.501745549307e+03, gap 2.4903%
s5 <- solve(p5)
#> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Variable types: 0 continuous, 90 integer (90 binary) #> Coefficient statistics: #> Matrix range [2e-01, 9e-01] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [6e+00, 1e+01] #> Found heuristic solution: objective 3953.6827496 #> Presolve removed 0 rows and 10 columns #> Presolve time: 0.00s #> Presolved: 5 rows, 80 columns, 400 nonzeros #> Variable types: 0 continuous, 80 integer (80 binary) #> Presolved: 5 rows, 80 columns, 400 nonzeros #> #> #> Root relaxation: objective 3.501746e+03, 10 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3501.74555 0 4 3953.68275 3501.74555 11.4% - 0s #> H 0 0 3591.1771615 3501.74555 2.49% - 0s #> #> Explored 1 nodes (10 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3591.18 3953.68 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.591177161528e+03, best bound 3.501745549307e+03, gap 2.4903%
# plot solutions par(mfrow = c(3,2), mar = c(0, 0, 4.1, 0)) plot(s1, main = "none locked out") plot(s1[s1$solution_1 == 1, ], col = "darkgreen", add = TRUE) plot(s2, main = "locked out (integer input)") plot(s2[s2$solution_1 == 1, ], col = "darkgreen", add = TRUE) plot(s3, main = "locked out (character input)") plot(s3[s3$solution_1 == 1, ], col = "darkgreen", add = TRUE) plot(s4, main = "locked out (raster input)") plot(s4[s4$solution_1 == 1, ], col = "darkgreen", add = TRUE) plot(s5, main = "locked out (polygon input)") plot(s5[s5$solution_1 == 1, ], col = "darkgreen", add = TRUE)
# create minimal multi-zone problem with spatial data p6 <- problem(sim_pu_zones_polygons, sim_features_zones, cost_column = c("cost_1", "cost_2", "cost_3")) %>% add_min_set_objective() %>% add_absolute_targets(matrix(rpois(15, 1), nrow = 5, ncol = 3)) %>% add_binary_decisions() # create multi-zone problem with locked out constraints using matrix data locked_matrix <- sim_pu_zones_polygons@data[, c("locked_1", "locked_2", "locked_3")] locked_matrix <- as.matrix(locked_matrix) p7 <- p6 %>% add_locked_out_constraints(locked_matrix)
# solve problem s6 <- solve(p6)
#> Optimize a model with 105 rows, 270 columns and 1620 nonzeros #> Variable types: 0 continuous, 270 integer (270 binary) #> Coefficient statistics: #> Matrix range [2e-01, 1e+00] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [1e+00, 3e+00] #> Found heuristic solution: objective 3524.7950998 #> Presolve removed 7 rows and 0 columns #> Presolve time: 0.00s #> Presolved: 98 rows, 270 columns, 990 nonzeros #> Variable types: 0 continuous, 270 integer (270 binary) #> Presolved: 98 rows, 270 columns, 990 nonzeros #> #> #> Root relaxation: objective 2.642776e+03, 9 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 2642.77567 0 5 3524.79510 2642.77567 25.0% - 0s #> H 0 0 2875.8073247 2642.77567 8.10% - 0s #> #> Explored 1 nodes (9 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 2875.81 3524.8 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 2.875807324677e+03, best bound 2.642775673413e+03, gap 8.1032%
# create new column representing the zone id that each planning unit # was allocated to in the solution s6$solution <- category_vector(s6@data[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) s6$solution <- factor(s6$solution) # plot solution spplot(s6, zcol = "solution", main = "solution", axes = FALSE, box = FALSE)
# create multi-zone problem with locked out constraints using field names p8 <- p6 %>% add_locked_out_constraints(c("locked_1", "locked_2", "locked_3"))
# solve problem s8 <- solve(p8)
#> Optimize a model with 105 rows, 270 columns and 1620 nonzeros #> Variable types: 0 continuous, 270 integer (270 binary) #> Coefficient statistics: #> Matrix range [2e-01, 1e+00] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [1e+00, 3e+00] #> Found heuristic solution: objective 3504.3738118 #> Presolve removed 7 rows and 14 columns #> Presolve time: 0.00s #> Presolved: 98 rows, 256 columns, 939 nonzeros #> Variable types: 0 continuous, 256 integer (256 binary) #> Presolved: 98 rows, 256 columns, 939 nonzeros #> #> #> Root relaxation: objective 2.642776e+03, 9 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 2642.77567 0 5 3504.37381 2642.77567 24.6% - 0s #> H 0 0 2875.8073247 2642.77567 8.10% - 0s #> #> Explored 1 nodes (9 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 2875.81 3504.37 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 2.875807324677e+03, best bound 2.642775673413e+03, gap 8.1032%
# create new column in s8 representing the zone id that each planning unit # was allocated to in the solution s8$solution <- category_vector(s8@data[, c("solution_1_zone_1", "solution_1_zone_2", "solution_1_zone_3")]) s8$solution[s8$solution == 1 & s8$solution_1_zone_1 == 0] <- 0 s8$solution <- factor(s8$solution) # plot solution spplot(s8, zcol = "solution", main = "solution", axes = FALSE, box = FALSE)
# create multi-zone problem with raster planning units p9 <- problem(sim_pu_zones_stack, sim_features_zones) %>% add_min_set_objective() %>% add_absolute_targets(matrix(rpois(15, 1), nrow = 5, ncol = 3)) %>% add_binary_decisions() # create raster stack with locked out units locked_out_stack <- sim_pu_zones_stack[[1]] locked_out_stack[!is.na(locked_out_stack)] <- 0 locked_out_stack <- locked_out_stack[[c(1, 1, 1)]] locked_out_stack[[1]][1] <- 1 locked_out_stack[[2]][2] <- 1 locked_out_stack[[3]][3] <- 1 # plot locked out stack
plot(locked_out_stack)
# add locked out raster units to problem p9 <- p9 %>% add_locked_out_constraints(locked_out_stack)
# solve problem s9 <- solve(p9)
#> Optimize a model with 105 rows, 270 columns and 1620 nonzeros #> Variable types: 0 continuous, 270 integer (270 binary) #> Coefficient statistics: #> Matrix range [2e-01, 1e+00] #> Objective range [2e+02, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [1e+00, 2e+00] #> Found heuristic solution: objective 3103.1168109 #> Presolve removed 9 rows and 3 columns #> Presolve time: 0.00s #> Presolved: 96 rows, 267 columns, 801 nonzeros #> Variable types: 0 continuous, 267 integer (267 binary) #> Presolved: 96 rows, 267 columns, 801 nonzeros #> #> #> Root relaxation: objective 2.202889e+03, 16 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 2202.88852 0 6 3103.11681 2202.88852 29.0% - 0s #> H 0 0 2461.3893584 2202.88852 10.5% - 0s #> H 0 0 2421.8731174 2202.88852 9.04% - 0s #> #> Explored 1 nodes (16 simplex iterations) in 0.01 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 3: 2421.87 2461.39 3103.12 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 2.421873117358e+03, best bound 2.202888524130e+03, gap 9.0420%
# plot solution plot(category_layer(s9), main = "solution", axes = FALSE, box = FALSE)