Introduction

The aim of this tutorial is to provide a short introduction to the prioritizr R package. It is also intended to help conservation planners familiar the Marxan decision support tool (Ball et al. 2009) start using the package for their work.

Data

Let’s load the packages and data used in this tutorial. Since this tutorial uses data from the prioritizrdata R package, please ensure that it is installed. The data used in this tutorial were obtained from the Introduction to Marxan course. Specifically, the data were originally a subset of a larger spatial prioritization project performed under contract to Australia’s Department of Environment and Water Resources (Klein et al. 2007).

# load packages
library(prioritizrdata)
library(prioritizr)
library(sf)
library(raster)
library(vegan)
library(cluster)

# load planning unit data
data(tas_pu)

# load feature data
data(tas_features)

The tas_pu object contains planning units represented as spatial polygons (i.e., a SpatialPolygonsDataFrame object). This object has three columns that denote the following information for each planning unit: a unique identifier (id), unimproved land value (cost), and current conservation status (locked_in). Planning units that have at least half of their area overlapping with existing protected areas are denoted with a locked in value of 1, otherwise they are denoted with a value of 0. If you are familiar with the Marxan decision support tool, then you will notice that some of these columns are formatted similar conventions.

Now, let’s have a look at the planning unit data. We can see that the planning units correspond to hexagonal land parcels. We can also see that is a clear spatial pattern in the cost and conservation status the planning units.

# print planning unit data
print(tas_pu)
## class       : SpatialPolygonsDataFrame 
## features    : 1130 
## extent      : 298809.6, 613818.8, 5167775, 5502544  (xmin, xmax, ymin, ymax)
## crs         : +proj=utm +zone=55 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## variables   : 5
## names       :   id,              cost, status, locked_in, locked_out 
## min values  :    1, 0.192488262910798,      0,         0,          0 
## max values  : 1130,  61.9272727272727,      2,         1,          0
# plot map of planning unit costs
plot(st_as_sf(tas_pu[, "cost"]), main = "Planning unit costs")

# plot map of planning unit coverage by protected areas
plot(st_as_sf(tas_pu[, "locked_in"]), main = "Protected area coverage")

The tas_features object describes the spatial distribution of the features. Specifically, the feature data are expressed as a stack of 62 rasters (i.e., a RasterStack object). Each layer in the stack corresponds to one of 62 different vegetation communities. To describe the spatial distribution of a given vegetation community, each layer contains a spatially referenced grid of rectangular cells and each of these grid cells is associated with information on the distribution of the a given vegetation community. Specifically, these grid cells are assigned values that indicate if a given vegetation community is present (using value of 1) or absent (using value of 0) within the spatial extent of each grid cell.

Next, let’s examine the feature data. Here we will only plot the first four features as an example. The pixel values denote the presence (denoted by a value of 1) or absence (denoted by a value of zero) of each feature within the extent of the study area.

# print planning unit data
print(tas_features)
## class      : RasterStack 
## dimensions : 398, 359, 142882, 62  (nrow, ncol, ncell, nlayers)
## resolution : 1000, 1000  (x, y)
## extent     : 288801.7, 647801.7, 5142976, 5540976  (xmin, xmax, ymin, ymax)
## crs        : +proj=utm +zone=55 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## names      : tas_features.1, tas_features.2, tas_features.3, tas_features.4, tas_features.5, tas_features.6, tas_features.7, tas_features.8, tas_features.9, tas_features.10, tas_features.11, tas_features.12, tas_features.13, tas_features.14, tas_features.15, ... 
## min values :              0,              0,              0,              0,              0,              0,              0,              0,              0,               0,               0,               0,               0,               0,               0, ... 
## max values :              1,              1,              1,              1,              1,              1,              1,              1,              1,               1,               1,               1,               1,               1,               1, ...
# plot map of the first four vegetation classes
plot(tas_features[[1:4]], main = paste("Feature", 1:4))

The planning units in this tutorial are stored as spatial polygons. Although spatial polygons provide considerable flexibility in the shape and size of the planning units, such flexibility comes at a cost. This is because the spatial data processing routines needed to combine spatial polygon data and raster data for optimization can be very computationally expensive (e.g., calculating zonal statistics). As a consequence, we generally recommend using raster-based planning unit data where possible to reduce processing time. Another strategy is to complete spatial data processing routines manually using other software (e.g., ESRI ArcGIS) and use the pre-processed data directly with the prioritizr R package.

Problem formulation

Now we will formulate a conservation planing problem. To achieve this, we first specify which objects contain the planning unit and feature data (using the problem() function). Next, we specify that we want to use the minimum set objective function (using the add_min_set_objective() function). This objective function indicates that we wish to minimize the total cost of planning units selected by the prioritization. We then specify boundary penalties reduce spatial fragmentation in the resulting prioritization (using the add_boundary_penalties() function; see the Calibrating trade-offs vignette for details on calibrating the penalty value). We also specify representation targets to ensure the resulting prioritization provides adequate coverage of each vegetation community (using the add_relative_targets() function). Specifically, we specify targets to ensure at least 17% of the spatial extent of each vegetation community (based on the Aichi Target 11). Additionally, we set constraints to ensure that planning units predominately covered by existing protected areas are selected by the prioritization (using the add_locked_in_constraints() function). Finally, we specify that the prioritization should either select – or not select – planning units for prioritization (using the add_binary_decisions() function).

# build problem
p1 <- problem(tas_pu, tas_features, cost_column = "cost") %>%
      add_min_set_objective() %>%
      add_boundary_penalties(penalty = 0.005) %>%
      add_relative_targets(0.17) %>%
      add_locked_in_constraints("locked_in") %>%
      add_binary_decisions()

# print the problem
print(p1)
## Conservation Problem
##   planning units: SpatialPolygonsDataFrame (1130 units)
##   cost:           min: 0.19249, max: 61.92727
##   features:       tas_features.1, tas_features.2, tas_features.3, ... (62 features)
##   objective:      Minimum set objective 
##   targets:        Relative targets [targets (min: 0.17, max: 0.17)]
##   decisions:      Binary decision 
##   constraints:    <Locked in planning units [257 locked units]>
##   penalties:      <Boundary penalties [edge factor (min: 0.5, max: 0.5), penalty (0.005), zones]>
##   portfolio:      default
##   solver:         default

Prioritization

We can now solve the problem formulation (p1) to generate a prioritization (using the solve() function). The prioritizr R package supports a range of different exact algorithm solvers, including Gurobi, IBM CPLEX, CBC, HiGHS, Rsymphony, and lpsymphony. Although there are benefits and limitations associated with each of these different solvers, they should return similar results. Note that you will need at least one solver installed on your system to generate prioritizations. Since we did not specify a solver when building the problem, the prioritizr R package will automatically select the best available solver installed. We recommend using the Gurobi solver if possible, and have used it for this tutorial (see the Gurobi Installation Guide vignette for installation instructions). After solving the problem, the prioritization will be stored in the solution_1 column of the s1 object.

# solve problem
s1 <- solve(p1)
## Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (linux64)
## 
## CPU model: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz, instruction set [SSE2|AVX|AVX2|AVX512]
## Thread count: 4 physical cores, 8 logical processors, using up to 1 threads
## 
## Optimize a model with 6358 rows, 4278 columns and 14496 nonzeros
## Model fingerprint: 0x861c9b00
## Variable types: 0 continuous, 4278 integer (4278 binary)
## Coefficient statistics:
##   Matrix range     [2e-06, 4e+01]
##   Objective range  [5e-01, 2e+02]
##   Bounds range     [1e+00, 1e+00]
##   RHS range        [1e-01, 1e+02]
## Found heuristic solution: objective 36805.575211
## Found heuristic solution: objective 27817.085072
## Presolve removed 2077 rows and 1375 columns
## Presolve time: 0.12s
## Presolved: 4281 rows, 2903 columns, 9594 nonzeros
## Found heuristic solution: objective 24454.499456
## Variable types: 0 continuous, 2903 integer (2903 binary)
## Found heuristic solution: objective 23413.987477
## Root relaxation presolved: 4281 rows, 2903 columns, 9594 nonzeros
## 
## 
## Root relaxation: objective 1.955605e+04, 1793 iterations, 0.26 seconds (0.19 work units)
## 
##     Nodes    |    Current Node    |     Objective Bounds      |     Work
##  Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time
## 
##      0     0 19556.0531    0 1615 23413.9875 19556.0531  16.5%     -    0s
## H    0     0                    23045.733138 19556.0531  15.1%     -    0s
## H    0     0                    22977.771015 19556.0531  14.9%     -    0s
##      0     0 19835.6369    0 1833 22977.7710 19835.6369  13.7%     -    0s
## H    0     0                    21705.306602 19835.6369  8.61%     -    0s
## 
## Cutting planes:
##   Gomory: 2
##   Cover: 5
##   MIR: 5
##   GUB cover: 1
##   Zero half: 2
##   RLT: 11
## 
## Explored 1 nodes (2467 simplex iterations) in 0.99 seconds (0.55 work units)
## Thread count was 1 (of 8 available processors)
## 
## Solution count 7: 21705.3 22977.8 23045.7 ... 36805.6
## 
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.170530660204e+04, best bound 1.983563686947e+04, gap 8.6139%
# plot map of prioritization
plot(st_as_sf(s1[, "solution_1"]), main = "Prioritization",
     pal = c("grey90", "darkgreen"))

Feature representation

Let’s examine how well the vegetation communities are represented by existing protected areas and the prioritization.

# create column with existing protected areas
tas_pu$pa <- round(tas_pu$locked_in)

# calculate feature representation statistics based on existing protected areas
tc_pa <- eval_target_coverage_summary(p1, tas_pu[, "pa"])
print(tc_pa)
## # A tibble: 62 × 9
##    feature         met   total…¹ absol…² absol…³ absol…⁴ relat…⁵ relat…⁶ relat…⁷
##    <chr>           <lgl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
##  1 tas_features.1  FALSE    33.9    5.77   0.556    5.21    0.17  0.0164  0.154 
##  2 tas_features.2  FALSE   170.    28.9   13.5     15.4     0.17  0.0796  0.0904
##  3 tas_features.3  FALSE    24.0    4.08   2.00     2.08    0.17  0.0832  0.0868
##  4 tas_features.4  FALSE    32.8    5.57   1.37     4.19    0.17  0.0420  0.128 
##  5 tas_features.5  FALSE    24.8    4.21   0        4.21    0.17  0       0.17  
##  6 tas_features.6  FALSE    22.0    3.74   0        3.74    0.17  0       0.17  
##  7 tas_features.7  FALSE    16.4    2.78   0        2.78    0.17  0       0.17  
##  8 tas_features.8  FALSE    43.0    7.31   5.12     2.19    0.17  0.119   0.0510
##  9 tas_features.9  FALSE   388.    66.0   22.4     43.5     0.17  0.0578  0.112 
## 10 tas_features.10 FALSE    14.5    2.47   0        2.47    0.17  0       0.17  
## # … with 52 more rows, and abbreviated variable names ¹​total_amount,
## #   ²​absolute_target, ³​absolute_held, ⁴​absolute_shortfall, ⁵​relative_target,
## #   ⁶​relative_held, ⁷​relative_shortfall
# calculate  feature representation statistics based on the prioritization
tc_s1 <- eval_target_coverage_summary(p1, s1[, "solution_1"])
print(tc_s1)
## # A tibble: 62 × 9
##    feature         met   total…¹ absol…² absol…³ absol…⁴ relat…⁵ relat…⁶ relat…⁷
##    <chr>           <lgl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
##  1 tas_features.1  TRUE     33.9    5.77    6.97       0    0.17   0.205       0
##  2 tas_features.2  TRUE    170.    28.9    44.8        0    0.17   0.264       0
##  3 tas_features.3  TRUE     24.0    4.08    5.00       0    0.17   0.208       0
##  4 tas_features.4  TRUE     32.8    5.57   12.4        0    0.17   0.378       0
##  5 tas_features.5  TRUE     24.8    4.21    4.49       0    0.17   0.181       0
##  6 tas_features.6  TRUE     22.0    3.74    9.10       0    0.17   0.414       0
##  7 tas_features.7  TRUE     16.4    2.78    3.00       0    0.17   0.183       0
##  8 tas_features.8  TRUE     43.0    7.31    8.12       0    0.17   0.189       0
##  9 tas_features.9  TRUE    388.    66.0    76.0        0    0.17   0.196       0
## 10 tas_features.10 TRUE     14.5    2.47    3          0    0.17   0.207       0
## # … with 52 more rows, and abbreviated variable names ¹​total_amount,
## #   ²​absolute_target, ³​absolute_held, ⁴​absolute_shortfall, ⁵​relative_target,
## #   ⁶​relative_held, ⁷​relative_shortfall
# explore representation by existing protected areas
## calculate number of features adequately represented by existing protected
## areas
sum(tc_pa$met)
## [1] 16
## summarize representation (values show percent coverage)
summary(tc_pa$relative_held * 100)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   0.000   4.845  13.909  16.995  58.488
## visualize representation  (values show percent coverage)
hist(tc_pa$relative_held * 100,
     main = "Feature representation by existing protected areas",
     xlim = c(0, 100),
     xlab = "Percent coverage of features (%)")

# explore representation by prioritization
## summarize representation (values show percent coverage)
summary(tc_s1$relative_held * 100)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   17.49   19.79   25.93   34.99   44.63  100.00
## calculate number of features adequately represented by the prioritization
sum(tc_s1$met)
## [1] 62
## visualize representation  (values show percent coverage)
hist(tc_s1$relative_held * 100,
     main = "Feature representation by prioritization",
     xlim = c(0, 100),
     xlab = "Percent coverage of features (%)")

We can see that representation of the vegetation communities by existing protected areas is remarkably poor. For example, many of the vegetation communities have nearly zero coverage by existing protected areas. In other words, are almost entirely absent from existing protected areas. We can also see that all vegetation communities have at least 17% coverage by the prioritization – meaning that it meets the representation targets for all of the features.

Irreplaceability

After generating the prioritization, we can examine the relative importance of planning units selected by the prioritization. This can be useful to identify critically important planning units for conservation – in other words, places that contain biodiversity features which cannot be represented anywhere else – and schedule implementation of the prioritization. To achieve this, we will use the Ferrier metric (Ferrier et al. 2000).

# calculate irreplaceability
irrep_s1 <- eval_ferrier_importance(p1, s1["solution_1"])
print(irrep_s1)
## class       : SpatialPolygonsDataFrame 
## features    : 1130 
## extent      : 298809.6, 613818.8, 5167775, 5502544  (xmin, xmax, ymin, ymax)
## crs         : +proj=utm +zone=55 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## variables   : 63
## names       :      tas_features.1,      tas_features.2,      tas_features.3,      tas_features.4,      tas_features.5,    tas_features.6,      tas_features.7,      tas_features.8,     tas_features.9,     tas_features.10,   tas_features.11,     tas_features.12,     tas_features.13,    tas_features.14,     tas_features.15, ... 
## min values  :                   0,                   0,                   0,                   0,                   0,                 0,                   0,                   0,                  0,                   0,                 0,                   0,                   0,                  0,                   0, ... 
## max values  : 0.00711824775612521, 0.00677617182804085, 0.00252250621218381, 0.00603461402882859, 0.00223116059711298, 0.226881579868195, 0.00357699100195298, 0.00367543492891132, 0.0074626121416326, 0.00701739172953936, 0.230759668693182, 0.00472477144676876, 0.00256953165096351, 0.0101913850980662, 0.00618368294591574, ...
# manually coerce values for planning units not selected in prioritization
# to NA, so that they are shown in white
irrep_s1$plot_total <- irrep_s1$total
irrep_s1$plot_total[s1$solution_1 < 0.5] <- NA_real_

# plot map of overall importance scores
plot(st_as_sf(irrep_s1[, "plot_total"]), main = "Overall importance")

Portfolios

Conservation planning exercises often involve generating multiple different prioritizations. This can help decision makers consider different options, and provide starting points for building consensus among stakeholders. To generate a range of different prioritizations given the same problem formulation, we can use portfolio functions. Here we will use the gap portfolio to generate 1000 solutions that are within 30% of optimality. Please note that you will need to have the Gurobi solver installed to use this specific portfolio. If you don’t have access to Gurobi, you could try using the shuffle portfolio instead (using the add_shuffle_portfolio() function).

# create new problem with a portfolio added to it
p2 <- p1 %>%
      add_gap_portfolio(number_solutions = 1000, pool_gap = 0.2)

# print problem
print(p2)
## Conservation Problem
##   planning units: SpatialPolygonsDataFrame (1130 units)
##   cost:           min: 0.19249, max: 61.92727
##   features:       tas_features.1, tas_features.2, tas_features.3, ... (62 features)
##   objective:      Minimum set objective 
##   targets:        Relative targets [targets (min: 0.17, max: 0.17)]
##   decisions:      Binary decision 
##   constraints:    <Locked in planning units [257 locked units]>
##   penalties:      <Boundary penalties [edge factor (min: 0.5, max: 0.5), penalty (0.005), zones]>
##   portfolio:      Gap portfolio [number_solutions (1000), pool_gap (0.2)]
##   solver:         default
# generate prioritizations
prt <- solve(p2)
## Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (linux64)
## 
## CPU model: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz, instruction set [SSE2|AVX|AVX2|AVX512]
## Thread count: 4 physical cores, 8 logical processors, using up to 1 threads
## 
## Optimize a model with 6358 rows, 4278 columns and 14496 nonzeros
## Model fingerprint: 0x861c9b00
## Variable types: 0 continuous, 4278 integer (4278 binary)
## Coefficient statistics:
##   Matrix range     [2e-06, 4e+01]
##   Objective range  [5e-01, 2e+02]
##   Bounds range     [1e+00, 1e+00]
##   RHS range        [1e-01, 1e+02]
## Found heuristic solution: objective 36805.575211
## Found heuristic solution: objective 27817.085072
## Presolve removed 1434 rows and 258 columns
## Presolve time: 0.05s
## Presolved: 4924 rows, 4020 columns, 10889 nonzeros
## Variable types: 0 continuous, 4020 integer (4020 binary)
## Found heuristic solution: objective 27660.082384
## Root relaxation presolved: 4924 rows, 4020 columns, 10889 nonzeros
## 
## 
## Root relaxation: objective 1.954728e+04, 1905 iterations, 0.26 seconds (0.18 work units)
## 
##     Nodes    |    Current Node    |     Objective Bounds      |     Work
##  Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time
## 
##      0     0 19547.2818    0 1731 27660.0824 19547.2818  29.3%     -    0s
## H    0     0                    26145.941445 19547.2818  25.2%     -    0s
## H    0     0                    24520.062189 19547.2818  20.3%     -    0s
##      0     0 19816.1878    0 1965 24520.0622 19816.1878  19.2%     -    0s
## H    0     0                    24498.644854 19816.1878  19.1%     -    0s
## H    0     0                    23263.485453 19816.1878  14.8%     -    0s
## H    0     0                    21847.828075 19816.1878  9.30%     -    1s
##      0     0 19840.6230    0 1954 21847.8281 19840.6230  9.19%     -    1s
##      0     0 19847.1941    0 1958 21847.8281 19847.1941  9.16%     -    1s
##      0     0 19917.2650    0 1884 21847.8281 19917.2650  8.84%     -    1s
## H    0     0                    21831.394553 19917.2650  8.77%     -    1s
##      0     0 19923.8717    0 1873 21831.3946 19923.8717  8.74%     -    1s
##      0     0 19924.7815    0 1874 21831.3946 19924.7815  8.73%     -    1s
##      0     0 19948.6397    0 1733 21831.3946 19948.6397  8.62%     -    1s
##      0     0 19950.6344    0 1733 21831.3946 19950.6344  8.61%     -    1s
##      0     0 19960.2198    0 1895 21831.3946 19960.2198  8.57%     -    2s
##      0     0 19960.8567    0 1896 21831.3946 19960.8567  8.57%     -    2s
##      0     0 19960.8917    0 1896 21831.3946 19960.8917  8.57%     -    2s
##      0     0 19970.1883    0 1895 21831.3946 19970.1883  8.53%     -    2s
##      0     0 19970.3008    0 1895 21831.3946 19970.3008  8.52%     -    2s
##      0     0 19970.5283    0 1895 21831.3946 19970.5283  8.52%     -    2s
##      0     0 19970.5509    0 1896 21831.3946 19970.5509  8.52%     -    2s
##      0     0 19970.6229    0 1896 21831.3946 19970.6229  8.52%     -    2s
##      0     0 19970.6229    0 1896 21831.3946 19970.6229  8.52%     -    2s
##      0     2 19971.7903    0 1896 21831.3946 19971.7903  8.52%     -    3s
## H   27    27                    21427.973036 19975.2817  6.78%   120    4s
## H   54    54                    21343.168882 19975.2817  6.41%   138    5s
## H   81    81                    21292.350054 19975.2817  6.19%   122    6s
## H  108   108                    21239.822239 19975.2817  5.95%   101    6s
## H  135   135                    21239.702905 19975.2817  5.95%  91.2    6s
## H  162   162                    21232.051862 19975.2817  5.92%  83.2    7s
## H  216   216                    21222.883764 19975.2817  5.88%  69.6    7s
##    605     1 21222.8838  439 1731 21222.8838 19978.3972  5.86%  26.5   10s
## H  605     1                    21195.666934 19978.3972  5.74%  26.5   10s
## H  623    12                    21194.542724 20008.2764  5.60%  25.7   16s
## H  631    16                    21189.637384 20011.2375  5.56%  25.4   18s
##    636    17 21189.6374  149 1924 21189.6374 20011.9849  5.56%  25.2   20s
##    654    10 21189.6374  545 1918 21189.6374 20015.5211  5.54%  31.5   25s
## H  656     6                    20893.967099 20015.5293  4.20%  31.4   30s
##    715    60 20560.8867   51 1363 20893.9671 20062.9713  3.98%  50.2   35s
##   1359   702 20331.7094   36 1446 20893.9671 20063.1001  3.98%  39.5   40s
##   1921  1261 20206.4844   30 1822 20893.9671 20063.6213  3.97%  38.4   45s
## H 1975  1313                    20878.142023 20063.6213  3.90%  42.4   49s
## H 2090  1428                    20863.500495 20063.6213  3.83%  41.8   50s
## H 2194  1531                    20853.295502 20063.6213  3.79%  40.1   50s
##   2595  1932 21020.0336  100   30 20853.2955 20063.6280  3.79%  39.1   55s
## H 2647  1981                    20843.749539 20063.6280  3.74%  38.6   55s
## H 2682  2010                    20838.509678 20063.6280  3.72%  38.2   56s
##   3554  2843 20176.9843   27 1810 20838.5097 20070.5529  3.69%  32.1   60s
##   3880  3035 21095.1349   77 1206 20838.5097 20085.4110  3.61%  34.1   65s
##   4137  2937 20735.2142   51 1375 20838.5097 20086.7867  3.61%  33.8   70s
##   4446  3030 21348.3418   73 1153 20838.5097 20087.5173  3.60%  35.2   75s
##   4837  3275 20182.0182   28 1660 20838.5097 20090.5771  3.59%  36.3   80s
## H 5081  3462                    20818.880749 20093.3229  3.49%  38.4   85s
##   5412  3512 21979.6034  100  239 20818.8807 20097.6132  3.46%  39.4   90s
##   5740  3789 21030.4728   53 1510 20818.8807 20100.1571  3.45%  40.2   95s
##   5984  3925 20260.8315   28 1843 20818.8807 20117.0908  3.37%  41.4  100s
##   6255  3878 20712.7473   45 1409 20818.8807 20126.0922  3.33%  42.3  106s
## H 6256  3877                    20780.195969 20126.0922  3.15%  42.3  107s
## 
## Cutting planes:
##   Gomory: 4
##   Cover: 4
##   MIR: 24
##   StrongCG: 5
##   Flow cover: 14
##   GUB cover: 1
##   Zero half: 27
##   RLT: 17
## 
## Explored 6302 nodes (271889 simplex iterations) in 107.99 seconds (61.30 work units)
## Thread count was 1 (of 8 available processors)
## 
## Solution count 1000: 20780.2 20818.9 20838.5 ... 22360.9
## 
## Optimal solution found (tolerance 1.00e-01)
## Best objective 2.078019596858e+04, best bound 2.012609216398e+04, gap 3.1477%
print(prt)
## class       : SpatialPolygonsDataFrame 
## features    : 1130 
## extent      : 298809.6, 613818.8, 5167775, 5502544  (xmin, xmax, ymin, ymax)
## crs         : +proj=utm +zone=55 +south +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
## variables   : 1005
## names       :   id,              cost, status, locked_in, locked_out, solution_1, solution_2, solution_3, solution_4, solution_5, solution_6, solution_7, solution_8, solution_9, solution_10, ... 
## min values  :    1, 0.192488262910798,      0,         0,          0,          0,          0,          0,          0,          0,          0,          0,          0,          0,           0, ... 
## max values  : 1130,  61.9272727272727,      2,         1,          0,          1,          1,          1,          1,          1,          1,          1,          1,          1,           1, ...

After generating all these prioritizations, we now want some way to visualize them. Because it would be onerous to look at each and every prioritization individually, we will use statistical analyses to help us. We can visualize the differences between these different prioritizations – based on which planning units they selected – using a hierarchical cluster analysis (Harris et al. 2014).

# extract solutions
prt_results <- prt@data[, startsWith(names(prt), "solution_"), ]

# calculate pair-wise distances between different prioritizations for analysis
prt_dists <- vegan::vegdist(t(prt_results), method = "jaccard", binary = TRUE)

# run cluster analysis
prt_clust <- hclust(as.dist(prt_dists), method = "average")

# visualize clusters
opar <- par()
par(oma = c(0, 0, 0, 0), mar= c(0, 4.1, 1.5, 2.1))
plot(prt_clust, labels = FALSE, sub = NA, xlab = "",
     main = "Different prioritizations in portfolio")
suppressWarnings(par(opar))

We can see that there are approximately six main groups of prioritizations in the portfolio. To explore these different groups, let’s conduct another cluster analysis (i.e., a k-medoids analysis) to extract the most representative prioritization from each of these groups. In other words, we will run another statistical analysis to find the most central prioritization within each group.

# run k-medoids analysis
prt_med <- pam(prt_dists, k = 6)

# extract names of prioritizations that are most central for each group.
prt_med_names <- prt_med$medoids
print(prt_med_names)
## [1] "solution_3"   "solution_36"  "solution_446" "solution_242" "solution_421"
## [6] "solution_502"
# create a copy of prt and set values for locked in planning units to -1
# so we can easily visualize differences between prioritizations
prt2 <- prt[, prt_med_names]
prt2@data[which(tas_pu$locked_in > 0.5), prt_med_names] <- -1

# plot a map showing main different prioritizations
# dark grey: locked in planning units
# grey: planning units not selected
# green: selected planning units
plot(st_as_sf(prt2), pal = c("grey60", "grey90", "darkgreen"))

Marxan compatibility

The prioritizr R package provides functionality to help Marxan users generate prioritizations. Specifically, it can import conservation planning data prepared for Marxan, and can generate prioritizations using a similar problem formulation as Marxan (based on Beyer et al. 2016). Indeed, the problem formulation presented earlier in this vignette is very similar to that used by Marxan. The key difference is that the problem formulation we specified earlier uses “hard constraints” for feature representation, and Marxan uses “soft constraints” for feature representation. This means that prioritization we generated earlier was mathematically guaranteed to reach the targets for all features. However, if we used Marxan to generate the prioritization, then we could have produced a prioritization that would fail to reach targets (depending the Species Penalty Factors used to generate the prioritization). In addition to these differences in terms problem formulation, the prioritizr R package uses exact algorithms – instead of the simulated annealing algorithm – which ensures that we obtain prioritizations that are near optimal.

Here we will show the prioritizr R package can import Marxan data and generate a prioritization. To begin with, let’s import a conservation planning data prepared for Marxan.

# import data
## planning unit data
pu_path <- system.file("extdata/input/pu.dat", package = "prioritizr")
pu_data <- read.csv(pu_path, header = TRUE, stringsAsFactors = FALSE)
print(head(pu_data))
##   id       cost status    xloc     yloc
## 1  3      0.000      0 1116623 -4493479
## 2 30   7527.275      3 1110623 -4496943
## 3 56  37349.075      0 1092623 -4500408
## 4 58  16959.021      0 1116623 -4500408
## 5 84  34220.256      0 1098623 -4503872
## 6 85 178907.584      0 1110623 -4503872
## feature data
spec_path <- system.file("extdata/input/spec.dat", package = "prioritizr")
spec_data <- read.csv(spec_path, header = TRUE, stringsAsFactors = FALSE)
print(head(spec_data))
##   id prop spf   name
## 1 10  0.3   1  bird1
## 2 11  0.3   1  nvis2
## 3 12  0.3   1  nvis8
## 4 13  0.3   1  nvis9
## 5 14  0.3   1 nvis14
## 6 15  0.3   1 nvis20
## amount of each feature within each planning unit data
puvspr_path <- system.file("extdata/input/puvspr.dat", package = "prioritizr")
puvspr_data <- read.csv(puvspr_path, header = TRUE, stringsAsFactors = FALSE)
print(head(puvspr_data))
##   species  pu     amount
## 1      26  56 120.344884
## 2      26  58  45.167010
## 3      26  84  68.047375
## 4      26  85   9.735624
## 5      26  86   7.803476
## 6      26 111 478.327417
## boundary data
bound_path <- system.file("extdata/input/bound.dat", package = "prioritizr")
bound_data <- read.table(bound_path, header = TRUE, stringsAsFactors = FALSE)
print(head(bound_data))
##   id1 id2 boundary
## 1   3   3    16000
## 2   3  30     4000
## 3   3  58     4000
## 4  30  30    12000
## 5  30  58     4000
## 6  30  85     4000

After importing the data, we can now generate a prioritization based on the Marxan problem formulation (using the marxan_problem() function). Please note that this function does not generate prioritizations using Marxan. Instead, it uses the data to create an optimization problem formulation similar to Marxan – using hard constraints instead of soft constraints – and uses an exact algorithm solver to generate a prioritization.

# create problem
p2 <- marxan_problem(pu_data, spec_data, puvspr_data, bound_data,
                     blm = 0.0005)

# print problem
print(p2)
## Conservation Problem
##   planning units: data.frame (1751 units)
##   cost:           min: 0, max: 415692.19382
##   features:       bird1, nvis2, nvis8, ... (17 features)
##   objective:      Minimum set objective 
##   targets:        Relative targets [targets (min: 0.3, max: 0.3)]
##   decisions:      default
##   constraints:    <Locked out planning units [1 locked units]
##                    Locked in planning units [317 locked units]>
##   penalties:      <Boundary penalties [edge factor (min: 1, max: 1), penalty (5e-04), zones]>
##   portfolio:      default
##   solver:         default
# solve problem
s2 <- solve(p2)
## Gurobi Optimizer version 10.0.0 build v10.0.0rc2 (linux64)
## 
## CPU model: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz, instruction set [SSE2|AVX|AVX2|AVX512]
## Thread count: 4 physical cores, 8 logical processors, using up to 1 threads
## 
## Optimize a model with 10075 rows, 6780 columns and 24778 nonzeros
## Model fingerprint: 0x37d7a0a1
## Variable types: 0 continuous, 6780 integer (6780 binary)
## Coefficient statistics:
##   Matrix range     [5e-05, 4e+03]
##   Objective range  [4e+00, 4e+05]
##   Bounds range     [1e+00, 1e+00]
##   RHS range        [5e+03, 3e+05]
## Found heuristic solution: objective 1.221202e+08
## Presolve removed 4707 rows and 3103 columns
## Presolve time: 0.14s
## Presolved: 5368 rows, 3677 columns, 12704 nonzeros
## Variable types: 0 continuous, 3677 integer (3677 binary)
## Found heuristic solution: objective 1.009944e+08
## Root relaxation presolved: 5368 rows, 3677 columns, 12704 nonzeros
## 
## 
## Root relaxation: objective 9.564790e+07, 521 iterations, 0.02 seconds (0.01 work units)
## 
##     Nodes    |    Current Node    |     Objective Bounds      |     Work
##  Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time
## 
##      0     0 9.5648e+07    0   20 1.0099e+08 9.5648e+07  5.29%     -    0s
## 
## Explored 1 nodes (521 simplex iterations) in 0.19 seconds (0.10 work units)
## Thread count was 1 (of 8 available processors)
## 
## Solution count 2: 1.00994e+08 1.2212e+08 
## 
## Optimal solution found (tolerance 1.00e-01)
## Best objective 1.009944489031e+08, best bound 9.564790440581e+07, gap 5.2939%
# print first six rows of solution object
print(head(s2))
##   id       cost status    xloc     yloc locked_in locked_out solution_1
## 1  3      0.000      0 1116623 -4493479     FALSE      FALSE          0
## 2 30   7527.275      3 1110623 -4496943     FALSE       TRUE          0
## 3 56  37349.075      0 1092623 -4500408     FALSE      FALSE          0
## 4 58  16959.021      0 1116623 -4500408     FALSE      FALSE          0
## 5 84  34220.256      0 1098623 -4503872     FALSE      FALSE          0
## 6 85 178907.584      0 1110623 -4503872     FALSE      FALSE          0

Conclusion

This tutorial shows how the prioritizr R package can be used to build a conservation problem, generate a prioritization, and evaluate it. Although we explored just a few functions, the package provides many different functions so that you can build and custom-tailor conservation planning problems to suit your needs. To learn more about the package, please see the package vignettes for an overview of the package, instructions for installing the Gurobi optimization suite, benchmarks comparing the performance of different solvers, and a record of publications that have cited the package. In addition to this tutorial, the package also provides tutorials on incorporating connectivity into prioritizations, calibrating trade-offs between different criteria (e.g., total cost and spatial fragmentation), and creating prioritizations that have multiple management zones or management actions.

References

Ball, I.R., Possingham, H. & Watts, M.E. (2009). Marxan and relatives: Software for spatial conservation prioritisation. Spatial Conservation Prioritisation: Quantitative Methods & Computational Tools (eds A. Moilanen, K.A. Wilson & H. Possingham), pp. 185–189. Oxford University Press, Oxford, UK.
Beyer, H.L., Dujardin, Y., Watts, M.E. & Possingham, H.P. (2016). Solving conservation planning problems with integer linear programming. Ecological Modelling, 328, 14–22.
Ferrier, S., Pressey, R.L. & Barrett, T.W. (2000). A new predictor of the irreplaceability of areas for achieving a conservation goal, its application to real-world planning, and a research agenda for further refinement. Biological Conservation, 93, 303–325.
Harris, L.R., Watts, M.E., Nel, R., Schoeman, D.S. & Possingham, H.P. (2014). Using multivariate statistics to explore trade-offs among spatial planning scenarios (P. Armsworth, Ed.). Journal of Applied Ecology, 51, 1504–1514.
Klein, C., Carwardine, J., Wilson, K., Watts, M. & Possingham, H. (2007). Spatial Prioritization Approaches for the Conservation of Biodiversity in Australia: Considering Conservation Costs, Ecological & Evolutionary Processes, and Large-Intact Areas. Report to the Department of Environment; Water Resources.