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 adjacency_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 adjacency_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() # \donttest{ # solve problems s <- stack(solve(p1), solve(p2))
#> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 5 rows, 90 columns and 450 nonzeros #> Model fingerprint: 0xac25e0fe #> 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 3988.8131278 3899.05601 2.25% - 0s #> #> Explored 1 nodes (12 simplex iterations) in 0.00 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 3988.81 4544.49 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 3.988813127763e+03, best bound 3.899056011987e+03, gap 2.2502% #> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 236 rows, 234 columns and 1202 nonzeros #> Model fingerprint: 0x6b9fa975 #> 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 3952.98944 0 79 - 3952.98944 - - 0s #> 0 0 3969.70422 0 80 - 3969.70422 - - 0s #> 0 0 3972.97474 0 89 - 3972.97474 - - 0s #> 0 0 3982.34764 0 98 - 3982.34764 - - 0s #> 0 0 3982.41767 0 94 - 3982.41767 - - 0s #> 0 0 3984.42060 0 91 - 3984.42060 - - 0s #> 0 0 3984.42060 0 90 - 3984.42060 - - 0s #> H 0 0 4608.4138755 3984.42060 13.5% - 0s #> 0 2 3984.65223 0 90 4608.41388 3984.65223 13.5% - 0s #> H 27 21 4285.2176945 3985.13341 7.00% 16.2 0s #> #> Cutting planes: #> Gomory: 3 #> Clique: 1 #> Zero half: 4 #> #> Explored 28 nodes (834 simplex iterations) in 0.13 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 2: 4285.22 4608.41 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 4.285217694549e+03, best bound 3.985133414355e+03, gap 7.0028%
# 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) # \donttest{ # solve problems s2 <- lapply(list(p3, p4, p5, p6), solve)
#> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 105 rows, 270 columns and 1620 nonzeros #> Model fingerprint: 0x168289c2 #> 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 0 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% #> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 801 rows, 705 columns and 3888 nonzeros #> Model fingerprint: 0x54884945 #> 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.03s #> 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, 691 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.1278 0 262 - 12085.1278 - - 0s #> 0 0 12085.1447 0 265 - 12085.1447 - - 0s #> 0 0 12087.6584 0 273 - 12087.6584 - - 0s #> 0 0 12090.4265 0 256 - 12090.4265 - - 0s #> 0 0 12090.5254 0 258 - 12090.5254 - - 0s #> 0 0 12090.5254 0 258 - 12090.5254 - - 0s #> 0 0 12091.6962 0 272 - 12091.6962 - - 0s #> 0 0 12091.8121 0 266 - 12091.8121 - - 0s #> 0 0 12092.4439 0 259 - 12092.4439 - - 0s #> 0 0 12092.6098 0 261 - 12092.6098 - - 0s #> 0 0 12092.6098 0 261 - 12092.6098 - - 0s #> 0 0 12092.6506 0 276 - 12092.6506 - - 0s #> 0 0 12092.8058 0 279 - 12092.8058 - - 0s #> 0 0 12092.8058 0 279 - 12092.8058 - - 0s #> 0 0 12092.8197 0 282 - 12092.8197 - - 0s #> 0 0 12092.8197 0 280 - 12092.8197 - - 0s #> 0 2 12092.8774 0 279 - 12092.8774 - - 0s #> H 353 196 14281.324921 12107.0007 15.2% 64.3 1s #> H 388 213 14265.457382 12108.7351 15.1% 64.9 1s #> H 407 231 14248.731873 12108.7351 15.0% 62.2 1s #> H 556 302 14240.536054 12109.8197 15.0% 74.4 3s #> H 591 298 14086.811847 12109.8197 14.0% 78.6 4s #> 746 337 12310.0176 42 232 14086.8118 12109.8197 14.0% 80.0 5s #> H 776 327 14084.986319 12109.8197 14.0% 78.8 5s #> H 1156 386 14084.426863 12111.7904 14.0% 77.1 6s #> H 1210 379 14082.625213 12111.9268 14.0% 76.0 7s #> H 1237 402 14071.909363 12112.0989 13.9% 76.5 7s #> H 1321 434 13960.361362 12112.8311 13.2% 75.4 7s #> H 1329 440 13957.579264 12112.8311 13.2% 75.0 7s #> * 1337 446 57 13954.627210 12112.8311 13.2% 74.6 7s #> * 1338 445 56 13952.714715 12112.8311 13.2% 74.6 7s #> H 1340 444 13943.797161 12112.8311 13.1% 74.5 7s #> H 1372 468 13926.909504 12112.9795 13.0% 74.7 8s #> H 1399 468 13733.550399 12113.2482 11.8% 74.2 8s #> H 1426 485 13732.040257 12113.3468 11.8% 74.1 8s #> H 1507 497 13501.418204 12114.2125 10.3% 73.8 8s #> 1945 691 12123.2645 23 268 13501.4182 12119.5487 10.2% 73.1 10s #> H 1978 654 13351.849112 12119.5487 9.23% 73.5 10s #> #> Cutting planes: #> Gomory: 7 #> Clique: 4 #> Inf proof: 10 #> Zero half: 22 #> #> Explored 1979 nodes (146817 simplex iterations) in 10.12 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 10: 13351.8 13501.4 13732 ... 13960.4 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.335184911249e+04, best bound 1.211954868919e+04, gap 9.2294% #> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 569 rows, 560 columns and 3132 nonzeros #> Model fingerprint: 0xc50b65ea #> 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.03s #> 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, 467 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 123 - 12048.9738 - - 0s #> 0 0 12055.7661 0 163 - 12055.7661 - - 0s #> 0 0 12066.3754 0 196 - 12066.3754 - - 0s #> 0 0 12066.7537 0 208 - 12066.7537 - - 0s #> 0 0 12068.5463 0 225 - 12068.5463 - - 0s #> 0 0 12068.8100 0 233 - 12068.8100 - - 0s #> 0 0 12069.3568 0 241 - 12069.3568 - - 0s #> 0 0 12069.3568 0 241 - 12069.3568 - - 0s #> H 0 0 14104.597125 12069.3568 14.4% - 0s #> H 0 0 14094.852035 12069.3568 14.4% - 0s #> 0 2 12069.3646 0 241 14094.8520 12069.3646 14.4% - 0s #> H 85 84 13139.068116 12069.4349 8.14% 25.6 0s #> #> Cutting planes: #> Gomory: 6 #> Clique: 3 #> Zero half: 7 #> #> Explored 86 nodes (3062 simplex iterations) in 0.36 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 3: 13139.1 14094.9 14104.6 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.313906811551e+04, best bound 1.206943489459e+04, gap 8.1409% #> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 945 rows, 850 columns and 4468 nonzeros #> Model fingerprint: 0x5b79ada6 #> 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.08s #> 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, 875 iterations, 0.03 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 12071.0476 0 229 - 12071.0476 - - 0s #> 0 0 12083.8905 0 211 - 12083.8905 - - 0s #> 0 0 12084.9202 0 249 - 12084.9202 - - 0s #> 0 0 12086.2128 0 262 - 12086.2128 - - 0s #> 0 0 12086.4955 0 263 - 12086.4955 - - 0s #> 0 0 12086.9402 0 271 - 12086.9402 - - 0s #> 0 0 12086.9750 0 270 - 12086.9750 - - 0s #> 0 0 12087.0002 0 244 - 12087.0002 - - 0s #> 0 0 12087.0048 0 267 - 12087.0048 - - 0s #> 0 0 12087.0326 0 250 - 12087.0326 - - 0s #> 0 0 12087.0326 0 242 - 12087.0326 - - 0s #> 0 2 12087.0595 0 242 - 12087.0595 - - 0s #> H 60 47 13531.146254 12087.0595 10.7% 29.3 0s #> H 60 47 13514.979731 12087.0595 10.6% 29.3 0s #> H 87 65 13512.830309 12087.2931 10.5% 42.3 0s #> H 141 76 13295.350187 12088.0827 9.08% 72.9 1s #> #> Cutting planes: #> Gomory: 7 #> MIR: 1 #> Inf proof: 2 #> Zero half: 5 #> #> Explored 142 nodes (12037 simplex iterations) in 1.27 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 4: 13295.4 13512.8 13515 13531.1 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 1.329535018732e+04, best bound 1.208808271922e+04, gap 9.0804%
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) #> crs : 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.2, type = rep("absolute", 5)) print(targets)
#> # A tibble: 5 x 4 #> feature zone target type #> <chr> <list> <dbl> <chr> #> 1 layer.1 <chr [2]> 16.7 absolute #> 2 layer.2 <chr [2]> 6.24 absolute #> 3 layer.3 <chr [2]> 14.4 absolute #> 4 layer.4 <chr [2]> 8.53 absolute #> 5 layer.5 <chr [2]> 11.3 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() # \donttest{ # solve problems s7 <- category_layer(solve(p7))
#> Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (linux64) #> Optimize a model with 703 rows, 615 columns and 3172 nonzeros #> Model fingerprint: 0xf807d970 #> 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 41 rows and 40 columns #> Presolve time: 0.08s #> Presolved: 662 rows, 575 columns, 2925 nonzeros #> Variable types: 0 continuous, 575 integer (575 binary) #> Presolve removed 128 rows and 0 columns #> Presolved: 534 rows, 575 columns, 2541 nonzeros #> #> #> Root relaxation: objective 3.896591e+03, 169 iterations, 0.00 seconds #> #> Nodes | Current Node | Objective Bounds | Work #> Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time #> #> 0 0 3896.59114 0 37 - 3896.59114 - - 0s #> H 0 0 4021.3095408 3896.59114 3.10% - 0s #> #> Explored 1 nodes (302 simplex iterations) in 0.10 seconds #> Thread count was 1 (of 4 available processors) #> #> Solution count 1: 4021.31 #> #> Optimal solution found (tolerance 1.00e-01) #> Best objective 4.021309540762e+03, best bound 3.896591139934e+03, gap 3.1014%
# plot solutions plot(s7, "solution", axes = FALSE, box = FALSE)
# }