Add constraints to a conservation planning problem to ensure that all selected planning units are spatially connected with each other and form a single contiguous unit.

# S4 method for ConservationProblem,ANY,ANY
add_contiguity_constraints(x, zones, data)

# S4 method for ConservationProblem,ANY,data.frame
add_contiguity_constraints(x, zones, data)

# S4 method for ConservationProblem,ANY,matrix
add_contiguity_constraints(x, zones, data)

Arguments

x

ConservationProblem-class object.

zones

matrix or Matrix object describing the connection scheme for different zones. Each row and column corresponds to a different zone in the argument to x, and cell values must contain binary numeric values (i.e. one or zero) that indicate if connected planning units (as specified in the argument to data) should be still considered connected if they are allocated to different zones. The cell values along the diagonal of the matrix indicate if planning units should be subject to contiguity constraints when they are allocated to a given zone. Note arguments to zones must be symmetric, and that a row or column has a value of one then the diagonal element for that row or column must also have a value of one. The default argument to zones is an identity matrix (i.e. a matrix with ones along the matrix diagonal and zeros elsewhere), so that planning units are only considered connected if they are both allocated to the same zone.

data

NULL, matrix, Matrix, data.frame object showing which planning units are connected with each other. The argument defaults to NULL which means that the connection data is calculated automatically using the connected_matrix function. See the Details section for more information.

Value

ConservationProblem-class object with the constraints added to it.

Details

This function uses connection data to identify solutions that form a single contiguous unit. In earlier versions of the prioritizr package, it was known as the add_connected_constraints function. It was inspired by the mathematical formulations detailed in \"Onal and Briers (2006).

The argument to data can be specified in several ways:

NULL

connection data should be calculated automatically using the connected_matrix function. This is the default argument. Note that the connection data must be manually defined using one of the other formats below when the planning unit data in the argument to x is not spatially referenced (e.g. in data.frame or numeric format).

matrix, Matrix

where rows and columns represent different planning units and the value of each cell indicates if the two planning units are connected or not. Cell values should be binary numeric values (i.e. one or zero). Cells that occur along the matrix diagonal have no effect on the solution at all because each planning unit cannot be a connected with itself.

data.frame

containing the fields (columns) "id1", "id2", and "boundary". Here, each row denotes the connectivity between two planning units following the Marxan format. The field boundary should contain binary numeric values that indicate if the two planning units specified in the fields "id1" and "id2" are connected or not. This data can be used to describe symmetric or asymmetric relationships between planning units. By default, input data is assumed to be symmetric unless asymmetric data is also included (e.g. if data is present for planning units 2 and 3, then the same amount of connectivity is expected for planning units 3 and 2, unless connectivity data is also provided for planning units 3 and 2).

References

\"Onal H and Briers RA (2006) Optimal selection of a connected reserve network. Operations Research, 54: 379--388.

See also

Examples

# load data data(sim_pu_raster, sim_features, sim_pu_zones_stack, sim_features_zones) # create minimal problem p1 <- problem(sim_pu_raster, sim_features) %>% add_min_set_objective() %>% add_relative_targets(0.2) %>% add_binary_decisions() # create problem with added connected constraints p2 <- p1 %>% add_contiguity_constraints()
# solve problems s <- stack(solve(p1), 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, 2e+01] #> Found heuristic solution: objective 4544.4850483 #> 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.899056e+03, 12 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3899.05601 0 4 4544.48505 3899.05601 14.2% - 0s #> H 0 0 3994.8945897 3899.05601 2.40% - 0s #> #> Explored 1 nodes (12 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3994.89 4544.49 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.994894589653e+03, best bound 3.899056011987e+03, gap 2.3990% #> Optimize a model with 236 rows, 234 columns and 1202 nonzeros #> Variable types: 0 continuous, 234 integer (234 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+01] #> Presolve removed 12 rows and 13 columns #> Presolve time: 0.01s #> Presolved: 224 rows, 221 columns, 1022 nonzeros #> Variable types: 0 continuous, 221 integer (221 binary) #> Presolved: 224 rows, 221 columns, 1022 nonzeros #> #> #> Root relaxation: objective 3.947815e+03, 153 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3947.81491 0 90 - 3947.81491 - - 0s #> 0 0 3950.02335 0 90 - 3950.02335 - - 0s #> 0 0 3969.69828 0 79 - 3969.69828 - - 0s #> 0 0 3972.75831 0 87 - 3972.75831 - - 0s #> 0 0 3972.97474 0 90 - 3972.97474 - - 0s #> 0 0 3982.34763 0 99 - 3982.34763 - - 0s #> 0 0 3982.41766 0 94 - 3982.41766 - - 0s #> 0 0 3982.41766 0 94 - 3982.41766 - - 0s #> 0 0 3982.41766 0 94 - 3982.41766 - - 0s #> H 0 0 4590.1395586 3982.41766 13.2% - 0s #> 0 2 3982.61532 0 94 4590.13956 3982.61532 13.2% - 0s #> H 10 8 4329.4350849 3990.95615 7.82% 40.4 0s #> #> Cutting planes: #> Gomory: 4 #> Zero half: 4 #> #> Explored 10 nodes (793 simplex iterations) in 0.07 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 4329.44 4590.14 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 4.329435084863e+03, best bound 3.990956145113e+03, gap 7.8181%
# plot solutions plot(s, main = c("basic solution", "connected solution"), axes = FALSE, box = FALSE)
# create minimal problem with multiple zones, and limit the solver to # 30 seconds to obtain solutions in a feasible period of time p3 <- problem(sim_pu_zones_stack, sim_features_zones) %>% add_min_set_objective() %>% add_relative_targets(matrix(0.2, ncol = 3, nrow = 5)) %>% add_default_solver(time_limit = 30) %>% add_binary_decisions() # create problem with added constraints to ensure that the planning units # allocated to each zone form a separate contiguous unit z4 <- diag(3) print(z4)
#> [,1] [,2] [,3] #> [1,] 1 0 0 #> [2,] 0 1 0 #> [3,] 0 0 1
p4 <- p3 %>% add_contiguity_constraints(z4) # create problem with added constraints to ensure that the planning # units allocated to each zone form a separate contiguous unit, # except for planning units allocated to zone 2 which do not need # form a single contiguous unit z5 <- diag(3) z5[3, 3] <- 0 print(z5)
#> [,1] [,2] [,3] #> [1,] 1 0 0 #> [2,] 0 1 0 #> [3,] 0 0 0
p5 <- p3 %>% add_contiguity_constraints(z5) # create problem with added constraints that ensure that the planning # units allocated to zones 1 and 2 form a contiguous unit z6 <- diag(3) z6[1, 2] <- 1 z6[2, 1] <- 1 print(z6)
#> [,1] [,2] [,3] #> [1,] 1 1 0 #> [2,] 1 1 0 #> [3,] 0 0 1
p6 <- p3 %>% add_contiguity_constraints(z6)
# solve problems s2 <- lapply(list(p3, p4, p5, p6), solve)
#> 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+01] #> Found heuristic solution: objective 13103.242827 #> Presolve time: 0.00s #> Presolved: 105 rows, 270 columns, 1620 nonzeros #> Variable types: 0 continuous, 270 integer (270 binary) #> Presolved: 105 rows, 270 columns, 1620 nonzeros #> #> #> Root relaxation: objective 1.199145e+04, 211 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 11991.4483 0 18 13103.2428 11991.4483 8.48% - 0s #> #> Explored 1 nodes (211 simplex iterations) in 0.01 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 1: 13103.2 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.310324282660e+04, best bound 1.199144828715e+04, gap 8.4849% #> Optimize a model with 801 rows, 705 columns and 3888 nonzeros #> Variable types: 0 continuous, 705 integer (705 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+01] #> Presolve removed 63 rows and 63 columns #> Presolve time: 0.04s #> Presolved: 738 rows, 642 columns, 3270 nonzeros #> Variable types: 0 continuous, 642 integer (642 binary) #> Presolved: 738 rows, 642 columns, 3270 nonzeros #> #> #> Root relaxation: objective 1.207868e+04, 759 iterations, 0.02 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 12078.6848 0 232 - 12078.6848 - - 0s #> 0 0 12085.5969 0 257 - 12085.5969 - - 0s #> 0 0 12085.7681 0 260 - 12085.7681 - - 0s #> 0 0 12089.6741 0 261 - 12089.6741 - - 0s #> 0 0 12089.7376 0 256 - 12089.7376 - - 0s #> 0 0 12090.1799 0 296 - 12090.1799 - - 0s #> 0 0 12090.1799 0 297 - 12090.1799 - - 0s #> 0 0 12090.3692 0 314 - 12090.3692 - - 0s #> 0 0 12090.3866 0 298 - 12090.3866 - - 0s #> 0 0 12090.3892 0 301 - 12090.3892 - - 0s #> 0 0 12090.7541 0 293 - 12090.7541 - - 0s #> 0 0 12090.9158 0 288 - 12090.9158 - - 0s #> 0 0 12090.9158 0 289 - 12090.9158 - - 0s #> 0 0 12090.9158 0 289 - 12090.9158 - - 0s #> 0 2 12090.9420 0 288 - 12090.9420 - - 0s #> H 281 176 14047.713034 12098.0721 13.9% 66.9 1s #> H 283 175 14037.892140 12098.0721 13.8% 66.5 1s #> H 475 231 13646.439309 12099.0668 11.3% 68.2 1s #> H 488 217 13512.549977 12099.0668 10.5% 66.7 1s #> H 502 230 13507.591329 12099.0668 10.4% 65.0 1s #> H 513 227 13505.730681 12099.0668 10.4% 63.7 2s #> H 526 224 13489.865400 12099.0668 10.3% 62.1 2s #> H 533 218 13488.620825 12099.0668 10.3% 61.3 2s #> H 591 230 13224.713963 12101.2606 8.50% 66.9 3s #> #> Cutting planes: #> Gomory: 6 #> Flow cover: 1 #> Inf proof: 2 #> Zero half: 19 #> #> Explored 591 nodes (40890 simplex iterations) in 3.84 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 9: 13224.7 13488.6 13489.9 ... 14047.7 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.322471396275e+04, best bound 1.210126057434e+04, gap 8.4951% #> Optimize a model with 569 rows, 560 columns and 3132 nonzeros #> Variable types: 0 continuous, 560 integer (560 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+01] #> Presolve removed 43 rows and 42 columns #> Presolve time: 0.02s #> Presolved: 526 rows, 518 columns, 2717 nonzeros #> Variable types: 0 continuous, 518 integer (518 binary) #> Presolved: 526 rows, 518 columns, 2717 nonzeros #> #> #> Root relaxation: objective 1.204897e+04, 503 iterations, 0.01 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 12048.9738 0 124 - 12048.9738 - - 0s #> 0 0 12064.8593 0 211 - 12064.8593 - - 0s #> 0 0 12064.9819 0 191 - 12064.9819 - - 0s #> 0 0 12065.2489 0 186 - 12065.2489 - - 0s #> 0 0 12066.8399 0 192 - 12066.8399 - - 0s #> 0 0 12067.5686 0 205 - 12067.5686 - - 0s #> 0 0 12067.5686 0 207 - 12067.5686 - - 0s #> 0 0 12067.5686 0 207 - 12067.5686 - - 0s #> 0 0 12067.5686 0 206 - 12067.5686 - - 0s #> H 0 0 14104.597125 12067.5686 14.4% - 0s #> H 0 0 14094.359470 12067.5686 14.4% - 0s #> H 0 0 14079.032410 12067.5686 14.3% - 0s #> H 0 0 14056.996635 12067.5686 14.2% - 0s #> 0 2 12067.5837 0 206 14056.9966 12067.5837 14.2% - 0s #> H 97 68 13409.658673 12070.6564 10.0% 39.8 0s #> #> Cutting planes: #> Gomory: 5 #> Clique: 6 #> Inf proof: 1 #> Zero half: 6 #> #> Explored 97 nodes (4719 simplex iterations) in 0.33 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 5: 13409.7 14057 14079 ... 14104.6 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.340965867313e+04, best bound 1.207065639504e+04, gap 9.9854% #> Optimize a model with 945 rows, 850 columns and 4468 nonzeros #> Variable types: 0 continuous, 850 integer (850 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+01] #> Presolve removed 70 rows and 73 columns #> Presolve time: 0.06s #> Presolved: 875 rows, 777 columns, 3840 nonzeros #> Variable types: 0 continuous, 777 integer (777 binary) #> Presolve removed 122 rows and 0 columns #> Presolved: 753 rows, 777 columns, 3474 nonzeros #> #> #> Root relaxation: objective 1.207105e+04, 801 iterations, 0.02 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 12071.0476 0 227 - 12071.0476 - - 0s #> 0 0 12083.8905 0 208 - 12083.8905 - - 0s #> 0 0 12084.9107 0 250 - 12084.9107 - - 0s #> 0 0 12086.3263 0 266 - 12086.3263 - - 0s #> 0 0 12087.8865 0 229 - 12087.8865 - - 0s #> 0 0 12087.9702 0 240 - 12087.9702 - - 0s #> 0 0 12088.0063 0 238 - 12088.0063 - - 0s #> 0 0 12088.0181 0 242 - 12088.0181 - - 0s #> 0 0 12088.0186 0 244 - 12088.0186 - - 0s #> 0 0 12088.2384 0 277 - 12088.2384 - - 0s #> 0 0 12088.3730 0 269 - 12088.3730 - - 0s #> 0 0 12088.3790 0 282 - 12088.3790 - - 0s #> 0 0 12088.4617 0 258 - 12088.4617 - - 0s #> 0 0 12088.9547 0 246 - 12088.9547 - - 0s #> 0 0 12088.9638 0 247 - 12088.9638 - - 0s #> 0 0 12089.1692 0 245 - 12089.1692 - - 0s #> 0 0 12089.2701 0 247 - 12089.2701 - - 0s #> 0 0 12089.2702 0 250 - 12089.2702 - - 0s #> 0 0 12089.2702 0 252 - 12089.2702 - - 0s #> 0 0 12089.2702 0 249 - 12089.2702 - - 0s #> 0 2 12089.2735 0 246 - 12089.2735 - - 0s #> H 107 79 13567.507336 12089.6253 10.9% 41.3 0s #> H 109 81 13563.547296 12089.6253 10.9% 40.6 0s #> * 114 86 62 13543.943995 12089.6253 10.7% 39.0 0s #> H 162 99 13261.539100 12089.7349 8.84% 42.8 0s #> #> Cutting planes: #> Gomory: 4 #> Clique: 3 #> Inf proof: 1 #> Zero half: 14 #> #> Explored 162 nodes (8747 simplex iterations) in 0.80 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 4: 13261.5 13543.9 13563.5 13567.5 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.326153910029e+04, best bound 1.208973486782e+04, gap 8.8361%
s2 <- lapply(s2, category_layer) s2 <- stack(s2) # plot solutions plot(s2, axes = FALSE, box = FALSE, main = c("basic solution", "p4", "p5", "p6"))
# create a problem that has a main "reserve zone" and a secondary # "corridor zone" to connect up import areas. Here, each feature has a # target of 30 % of its distribution. If a planning unit is allocated to the # "reserve zone", then the prioritization accrues 100 % of the amount of # each feature in the planning unit. If a planning unit is allocated to the # "corridor zone" then the prioritization accrues 40 % of the amount of each # feature in the planning unit. Also, the cost of managing a planning unit # in the "corridor zone" is 45 % of that when it is managed as the # "reserve zone". Finally, the problem has constraints which # ensure that all of the selected planning units form a single contiguous # unit, so that the planning units allocated to the "corridor zone" can # link up the planning units allocated to the "reserve zone" # create planning unit data pus <- sim_pu_zones_stack[[c(1, 1)]] pus[[2]] <- pus[[2]] * 0.45 print(pus)
#> class : RasterStack #> dimensions : 10, 10, 100, 2 (nrow, ncol, ncell, nlayers) #> resolution : 0.1, 0.1 (x, y) #> extent : 0, 1, 0, 1 (xmin, xmax, ymin, ymax) #> coord. ref. : NA #> names : layer.1.1, layer.1.2 #> min values : 190.13276, 85.55974 #> max values : 215.86384, 97.13873 #>
# create biodiversity data fts <- zones(sim_features, sim_features * 0.4, feature_names = names(sim_features), zone_names = c("reserve zone", "corridor zone")) print(fts)
#> Zones #> zones: reserve zone, corridor zone (2 zones) #> features: layer.1, layer.2, layer.3, ... (5 features) #> data type: RasterStack
# create targets targets <- tibble::tibble(feature = names(sim_features), zone = list(zone_names(fts))[rep(1, 5)], target = cellStats(sim_features, "sum") * 0.3, type = rep("absolute", 5)) print(targets)
#> # A tibble: 5 x 4 #> feature zone target type #> <chr> <list> <dbl> <chr> #> 1 layer.1 <chr [2]> 25.0 absolute #> 2 layer.2 <chr [2]> 9.36 absolute #> 3 layer.3 <chr [2]> 21.6 absolute #> 4 layer.4 <chr [2]> 12.8 absolute #> 5 layer.5 <chr [2]> 17.0 absolute
# create zones matrix z7 <- matrix(1, ncol = 2, nrow = 2) print(z7)
#> [,1] [,2] #> [1,] 1 1 #> [2,] 1 1
# create problem p7 <- problem(pus, fts) %>% add_min_set_objective() %>% add_manual_targets(targets) %>% add_contiguity_constraints(z7) %>% add_binary_decisions()
# solve problems s7 <- category_layer(solve(p7))
#> Optimize a model with 703 rows, 615 columns and 3172 nonzeros #> Variable types: 0 continuous, 615 integer (615 binary) #> Coefficient statistics: #> Matrix range [9e-02, 1e+00] #> Objective range [9e+01, 2e+02] #> Bounds range [1e+00, 1e+00] #> RHS range [1e+00, 2e+01] #> Presolve removed 48 rows and 47 columns #> Presolve time: 0.05s #> Presolved: 655 rows, 568 columns, 2764 nonzeros #> Variable types: 0 continuous, 568 integer (568 binary) #> Presolve removed 124 rows and 0 columns #> Presolved: 531 rows, 568 columns, 2392 nonzeros #> #> #> Root relaxation: objective 5.901727e+03, 161 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 5901.72702 0 53 - 5901.72702 - - 0s #> 0 0 5913.98711 0 46 - 5913.98711 - - 0s #> 0 0 5919.40013 0 75 - 5919.40013 - - 0s #> 0 0 5921.60014 0 76 - 5921.60014 - - 0s #> 0 0 5925.59486 0 77 - 5925.59486 - - 0s #> H 0 0 6482.8257651 5925.59486 8.60% - 0s #> #> Cutting planes: #> Gomory: 3 #> Zero half: 2 #> #> Explored 1 nodes (426 simplex iterations) in 0.09 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 1: 6482.83 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 6.482825765145e+03, best bound 5.925594864697e+03, gap 8.5955%
# plot solutions plot(s7, "solution", axes = FALSE, box = FALSE)