prioritizr
Uses mixed integer linear programming techniques to provide a flexible interface for building and solving conservation planning problems.
https://github.com/prioritizr/prioritizr
Category: Biosphere
Sub Category: Conservation and Restoration
Keywords
biodiversity conservation conservation-planner optimization prioritization r rstats solver spatial
Keywords from Contributors
ecology spatial-data
Last synced: about 19 hours ago
JSON representation
Repository metadata
Systematic conservation prioritization in R
- Host: GitHub
- URL: https://github.com/prioritizr/prioritizr
- Owner: prioritizr
- Created: 2017-02-04T22:45:17.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-04-17T00:54:58.000Z (10 days ago)
- Last Synced: 2025-04-20T09:44:33.824Z (7 days ago)
- Topics: biodiversity, conservation, conservation-planner, optimization, prioritization, r, rstats, solver, spatial
- Language: R
- Homepage: https://prioritizr.net
- Size: 165 MB
- Stars: 126
- Watchers: 12
- Forks: 26
- Open Issues: 18
- Releases: 7
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: CONTRIBUTING.Rmd
- Codeowners: .github/CODEOWNERS
README.Rmd
--- output: rmarkdown::github_document: html_preview: no --- # prioritizr## Systematic Conservation Prioritization in R [](https://lifecycle.r-lib.org/articles/stages.html) [](https://github.com/prioritizr/prioritizr/actions) [](https://github.com/prioritizr/prioritizr/actions) [](https://github.com/prioritizr/prioritizr/actions) [](https://github.com/prioritizr/prioritizr/actions) [](https://app.codecov.io/gh/prioritizr/prioritizr/branch/main) [](https://CRAN.R-project.org/package=prioritizr) [](https://www.theodorosploumis.com/en) [](https://doi.org/10.1111/cobi.14376) ```{r, include = FALSE} devtools::load_all() library(prioritizrdata) plot <- function(...) terra::plot(..., cex = 1.5) ``` ```{r, include = FALSE} # set parameters for figure sizes h <- 4.5 w <- 6.5 ow <- "500" knitr::opts_chunk$set( fig.height = h, fig.width = w, out.width = ow, fig.path = "man/figures/README-", fig.align = "center" ) ``` ```{r, include = FALSE} # set up print method print <- function(x, ...) { if (inherits(x, "ConservationProblem")) { prioritizr::knit_print.ConservationProblem(x) } else if (inherits(x, "OptimizationProblem")) { prioritizr::knit_print.OptimizationProblem(x) } else { base::print(x) } } ``` The _prioritizr R_ package uses mixed integer linear programming (MILP) techniques to provide a flexible interface for building and solving conservation planning problems. It supports a broad range of objectives, constraints, and penalties that can be used to custom-tailor conservation planning problems to the specific needs of a conservation planning exercise. Once built, conservation planning problems can be solved using a variety of commercial and open-source exact algorithm solvers. In contrast to the algorithms conventionally used to solve conservation problems, such as heuristics or simulated annealing, the exact algorithms used here are guaranteed to find optimal solutions. Furthermore, conservation problems can be constructed to optimize the spatial allocation of different management actions or zones, meaning that conservation practitioners can identify solutions that benefit multiple stakeholders. Finally, this package has the functionality to read input data formatted for the _Marxan_ conservation planning program, and find much cheaper solutions in a much shorter period of time than _Marxan_. ## Installation #### Official version The latest official version of the _prioritizr R_ package can be installed from the [Comprehensive R Archive Network (CRAN)](https://cran.r-project.org/) using the following _R_ code. ```{r, eval = FALSE} install.packages("prioritizr", repos = "https://cran.rstudio.com/") ``` #### Developmental version The latest development version can be installed to gain access to new functionality that is not yet present in the latest official version. Please note that the developmental version is more likely to contain coding errors than the official version. To install the developmental version, you can install it directly from the [GitHub online code repository](https://github.com/prioritizr/prioritizr) or from the [R Universe](https://prioritizr.r-universe.dev/prioritizr). In general, we recommend installing the developmental version from the [R Universe](https://prioritizr.r-universe.dev/prioritizr). This is because installation via [R Universe](https://prioritizr.r-universe.dev/prioritizr) does not require any additional software (e.g., [RTools](https://cran.r-project.org/bin/windows/Rtools/) for Windows systems, or [Xcode and gfortran](https://mac.r-project.org/tools/) for macOS systems). * To install the latest development version from [R Universe](https://prioritizr.r-universe.dev/prioritizr), use the following _R_ code. ```{r, eval = FALSE} install.packages( "prioritizr", repos = c( "https://prioritizr.r-universe.dev", "https://cloud.r-project.org" ) ) ``` * To install the latest development version from [GitHub](https://github.com/prioritizr/prioritizr), use the following _R_ code. ```{r, eval = FALSE} if (!require(remotes)) install.packages("remotes") remotes::install_github("prioritizr/prioritizr") ``` ## Citation Please cite the _prioritizr R_ package when using it in publications. To cite the package, please use: > Hanson JO, Schuster R, Strimas‐Mackey M, Morrell N, Edwards BPM, Arcese P, Bennett JR, and Possingham HP (2025) Systematic conservation prioritization with the prioritizr R package. _Conservation Biology_, **39**: e14376. Additionally, we keep a [record of publications](https://prioritizr.net/articles/publication_record.html) that use the _prioritizr R_ package. If you use this package in any reports or publications, please [file an issue on GitHub](https://github.com/prioritizr/prioritizr/issues/new) so we can add it to the record. ## Usage Here we provide a short example showing how the _prioritizr R_ package can be used to build and solve conservation problems. Specifically, we will use an example dataset available through the _prioritizrdata R_ package. Additionally, we will use the _terra R_ package to perform raster calculations. To begin with, we will load the packages. ```{r, eval = FALSE} # load packages library(prioritizr) library(prioritizrdata) library(terra) ``` We will use the Washington dataset in this example. To import the planning unit data, we will use the `get_wa_pu()` function. Although the _prioritizr R_ package can support many different types of planning unit data, here our planning units are represented as a single-layer raster (i.e., `terra::rast()` object). Each cell represents a different planning unit, and cell values denote land acquisition costs. Specifically, there are `r withr::with_options(list(scipen = 1000), as.character(terra::global(!is.na(get_wa_pu()), "sum", na.rm = TRUE)[[1]]))` planning units in total (i.e., cells with non-missing values). ```{r "planning_units"} # import planning unit data wa_pu <- get_wa_pu() # preview data print(wa_pu) # plot data plot(wa_pu, main = "Costs", axes = FALSE) ``` Next, we will use the `get_wa_features()` function to import the conservation feature data. Although the _prioritizr R_ package can support many different types of feature data, here our feature data are represented as a multi-layer raster (i.e., `terra::rast()` object). Each layer describes the spatial distribution of a feature. Here, our feature data correspond to different bird species. To account for migratory patterns, the breeding and non-breeding distributions of species are represented as different features. Specifically, the cell values denote the relative abundance of individuals, with higher values indicating greater abundance. ```{r "features", fig.height = w * 1.2, fig.width = w * 1.5, out.width = "800"} # import feature data wa_features <- get_wa_features() # preview data print(wa_features) # plot the first nine features plot(wa_features[[1:9]], nr = 3, axes = FALSE) ``` Let's make sure that you have a solver installed on your computer. This is important so that you can use optimization algorithms to generate spatial prioritizations. If this is your first time using the _prioritizr R_ package, please install the HiGHS solver using the following _R_ code. Although the HiGHS solver is relatively fast and easy to install, please note that you'll need to install the [Gurobi software suite and the _gurobi_ _R_ package](https://www.gurobi.com/) for best performance (see the [Gurobi Installation Guide](https://prioritizr.net/articles/gurobi_installation_guide.html) for details). ```{r, eval = FALSE} # if needed, install HiGHS solver install.packages("highs", repos = "https://cran.rstudio.com/") ``` Now, let's generate a spatial prioritization. To ensure feasibility, we will set a budget. Specifically, the total cost of the prioritization will represent a 5% of the total land value in the study area. Given this budget, we want the prioritization to increase feature representation, as much as possible, so that each feature would, ideally, have 20% of its distribution covered by the prioritization. In this scenario, we can either purchase all of the land inside a given planning unit, or none of the land inside a given planning unit. Thus we will create a new `problem()` that will use a minimum shortfall objective (via `add_min_shortfall_objective()`), with relative targets of 20% (via `add_relative_targets()`), binary decisions (via `add_binary_decisions()`), and specify that we want near-optimal solutions (i.e., 10% from optimality) using the best solver installed on our computer (via `add_default_solver()`). ```{r} # calculate budget budget <- terra::global(wa_pu, "sum", na.rm = TRUE)[[1]] * 0.05 # create problem p1 <- problem(wa_pu, features = wa_features) %>% add_min_shortfall_objective(budget) %>% add_relative_targets(0.2) %>% add_binary_decisions() %>% add_default_solver(gap = 0.1, verbose = FALSE) # print problem print(p1) ``` After we have built a `problem()`, we can solve it to obtain a solution. ```{r "minimal_solution"} # solve the problem s1 <- solve(p1) # extract the objective print(attr(s1, "objective")) # extract time spent solving the problem print(attr(s1, "runtime")) # extract state message from the solver print(attr(s1, "status")) # plot the solution plot(s1, main = "Solution", axes = FALSE) ``` After generating a solution, it is important to evaluate it. Here, we will calculate the number of planning units selected by the solution, and the total cost of the solution. We can also check how many representation targets are met by the solution. ```{r "eval_performance"} # calculate number of selected planning units by solution eval_n_summary(p1, s1) # calculate total cost of solution eval_cost_summary(p1, s1) # calculate target coverage for the solution p1_target_coverage <- eval_target_coverage_summary(p1, s1) print(p1_target_coverage) # check percentage of the features that have their target met given the solution print(mean(p1_target_coverage$met) * 100) ``` Although this solution helps meet the representation targets, it does not account for existing protected areas inside the study area. As such, it does not account for the possibility that some features could be partially -- or even fully -- represented by existing protected areas and, in turn, might fail to identify meaningful priorities for new protected areas. To address this issue, we will use the `get_wa_locked_in()` function to import spatial data for protected areas in the study area. We will then add constraints to the `problem()` to ensure they are selected by the solution (via `add_locked_in_constraints()`). ```{r "locked_in_constraints"} # import locked in data wa_locked_in <- get_wa_locked_in() # print data print(wa_locked_in) # plot data plot(wa_locked_in, main = "Existing protected areas", axes = FALSE) # create new problem with locked in constraints added to it p2 <- p1 %>% add_locked_in_constraints(wa_locked_in) # solve the problem s2 <- solve(p2) # plot the solution plot(s2, main = "Solution", axes = FALSE) ``` This solution is an improvement over the previous solution. However, there are some places in the study area that are not available for protected area establishment (e.g., due to land tenure). As a consequence, the solution might not be practical for implementation, because it might select some places that are not available for protection. To address this issue, we will use the `get_wa_locked_out()` function to import spatial data describing which planning units are not available for protection. We will then add constraints to the `problem()` to ensure they are not selected by the solution (via `add_locked_out_constraints()`). ```{r "locked_out_constraints"} # import locked out data wa_locked_out <- get_wa_locked_out() # print data print(wa_locked_out) # plot data plot(wa_locked_out, main = "Areas not available for protection", axes = FALSE) # create new problem with locked out constraints added to it p3 <- p2 %>% add_locked_out_constraints(wa_locked_out) # solve the problem s3 <- solve(p3) # plot the solution plot(s3, main = "Solution", axes = FALSE) ``` This solution is even better then the previous solution. However, we are not finished yet. The planning units selected by the solution are fairly fragmented. This can cause issues because fragmentation increases management costs and reduces conservation benefits through edge effects. To address this issue, we can further modify the problem by adding penalties that punish overly fragmented solutions (via `add_boundary_penalties()`). Here we will use a penalty factor (i.e., boundary length modifier) of 0.003, and an edge factor of 50% so that planning units that occur on the outer edge of the study area are not overly penalized. ```{r "boundary_penalties"} # create new problem with boundary penalties added to it p4 <- p3 %>% add_boundary_penalties(penalty = 0.003, edge_factor = 0.5) # solve the problem s4 <- solve(p4) # plot the solution plot(s4, main = "Solution", axes = FALSE) ``` Now, let's explore which planning units selected by the solution are most important for cost-effectively meeting the targets. To achieve this, we will calculate importance (irreplaceability) scores using an incremental rank approach. Briefly, the optimization problem is solved multiple times in an incremental process with increasing budgets, and planning units are assigned ranks based on which increment they are selected in. Planning units selected earlier on in the process are considered more important. ```{r "importance"} # calculate importance scores imp <- p4 %>% eval_rank_importance(s4, n = 5) # print scores print(imp) # set planning units that are locked in to -1 so we can easily # see importance scores for priority areas imp <- terra::mask(imp, s4, maskvalues = 0, updatevalue = -1) # plot the total importance scores ## planning units shown in purple were not selected in solution s4 ## planning units shown in blue are less important ## planning units shown in yellow are highly important ## note that locked in planning units are also shown in yellow plot(imp, axes = FALSE, main = "Importance scores") ``` This short example demonstrates how the _prioritizr R_ package can be used to build and customize conservation problems, and then solve them to generate solutions. Although we explored just a few different functions for modifying a conservation problem, the package provides many functions for specifying objectives, constraints, penalties, and decision variables, so that you can build and custom-tailor conservation planning problems to suit your planning scenario. ## Learning resources The [package website](https://prioritizr.net/index.html) contains information on the _prioritizr R_ package. Here you can find [documentation for every function and built-in dataset](https://prioritizr.net/reference/index.html), and [news describing the updates in each package version](https://prioritizr.net/news/index.html). It also contains the following articles and tutorials. * [**Getting started**](https://prioritizr.net/articles/prioritizr.html): Short tutorial on using the package. * [**Package overview**](https://prioritizr.net/articles/package_overview.html): Introduction to systematic conservation planning and a comprehensive overview of the package. * [**Connectivity tutorial**](https://prioritizr.net/articles/connectivity_tutorial.html): Tutorial on incorporating connectivity into prioritizations. * [**Calibrating trade-offs tutorial**](https://prioritizr.net/articles/calibrating_trade-offs_tutorial.html): Tutorial on running calibration analyses to satisfy multiple criteria. * [**Management zones tutorial**](https://prioritizr.net/articles/management_zones_tutorial.html): Tutorial on incorporating multiple management zones and actions into prioritizations. * [**Gurobi installation guide**](https://prioritizr.net/articles/gurobi_installation_guide.html): Instructions for installing the _Gurobi_ optimization suite for generating prioritizations. * [**Solver benchmarks**](https://prioritizr.net/articles/solver_benchmarks.html): Performance comparison of optimization solvers for generating prioritizations. * [**Publication record**](https://prioritizr.net/articles/publication_record.html): List of publications that have cited the package. Additional resources can also be found in [online repositories under the _prioritizr_ organization](https://github.com/prioritizr). These resources include [slides for talks and seminars about the package](https://github.com/prioritizr/teaching). Additionally, workshop materials are available too (e.g., the [Carleton 2023 workshop](https://prioritizr.github.io/workshop/) and [ECCB 2024 workshop](https://iiasa.github.io/eccb2024/)). ## Getting help If you have any questions about the _prioritizr R_ package or suggestions for improving it, please [post an issue on the code repository](https://github.com/prioritizr/prioritizr/issues/new).
Owner metadata
- Name: prioritizr
- Login: prioritizr
- Email:
- Kind: organization
- Description:
- Website:
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/25472841?v=4
- Repositories: 23
- Last ynced at: 2023-11-21T03:20:14.104Z
- Profile URL: https://github.com/prioritizr
GitHub Events
Total
- Issues event: 35
- Watch event: 3
- Delete event: 21
- Issue comment event: 164
- Push event: 74
- Pull request event: 11
- Pull request review event: 2
- Fork event: 2
- Create event: 5
Last Year
- Issues event: 35
- Watch event: 3
- Delete event: 21
- Issue comment event: 164
- Push event: 74
- Pull request event: 11
- Pull request review event: 2
- Fork event: 2
- Create event: 5
Committers metadata
Last synced: 4 days ago
Total Commits: 777
Total Committers: 10
Avg Commits per committer: 77.7
Development Distribution Score (DDS): 0.134
Commits in past year: 18
Committers in past year: 1
Avg Commits per committer in past year: 18.0
Development Distribution Score (DDS) in past year: 0.0
Name | Commits | |
---|---|---|
jeffreyhanson | j****n@u****u | 673 |
ricschuster | m****l@r****m | 61 |
Matt Strimas-Mackey | m****s@g****m | 19 |
NinaMorrell | m****a@g****m | 13 |
[email protected] | n****u@e****a | 4 |
NinaMorrell | n****l@u****a | 3 |
bird-team-bot | j****t@g****m | 1 |
Sandra Neubert | 7****t | 1 |
Paula Andrea | o****0 | 1 |
Jason Everett | j****t@g****m | 1 |
Committer domains:
- ubc.ca: 1
- ead.ubc.ca: 1
- richard-schuster.com: 1
- uqconnect.edu.au: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 289
Total pull requests: 82
Average time to close issues: 3 months
Average time to close pull requests: 8 days
Total issue authors: 78
Total pull request authors: 6
Average comments per issue: 5.33
Average comments per pull request: 6.17
Merged pull request: 79
Bot issues: 0
Bot pull requests: 0
Past year issues: 36
Past year pull requests: 14
Past year average time to close issues: about 2 months
Past year average time to close pull requests: 14 days
Past year issue authors: 17
Past year pull request authors: 1
Past year average comments per issue: 5.33
Past year average comments per pull request: 5.5
Past year merged pull request: 14
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- jeffreyhanson (108)
- ricschuster (23)
- jflowernet (16)
- momeni133 (10)
- lizlaw (8)
- mstrimas (6)
- ninzyfb (6)
- MillerJeju (6)
- Martin-Jung (6)
- XavierCLL (4)
- Carina-Firkowski (4)
- jaseeverett (4)
- javierfajnolla (3)
- IsaakBM (3)
- ninsbl (3)
Top Pull Request Authors
- jeffreyhanson (77)
- sandra-neubert (1)
- mstrimas (1)
- jaseeverett (1)
- edwardsmarc (1)
- orchid00 (1)
Top Issue Labels
- question (85)
- bug (63)
- feature propsal (39)
- documentation (38)
- enhancement (14)
- v5 (8)
- wontfix (1)
- help wanted (1)
Top Pull Request Labels
- enhancement (1)
- v5 (1)
Package metadata
- Total packages: 1
-
Total downloads:
- cran: 1,396 last-month
- Total docker downloads: 9
- Total dependent packages: 1
- Total dependent repositories: 4
- Total versions: 23
- Total maintainers: 1
cran.r-project.org: prioritizr
Systematic Conservation Prioritization in R
- Homepage: https://prioritizr.net
- Documentation: http://cran.r-project.org/web/packages/prioritizr/prioritizr.pdf
- Licenses: GPL-3
- Latest release: 8.0.6 (published 4 months ago)
- Last Synced: 2025-04-25T12:08:52.918Z (2 days ago)
- Versions: 23
- Dependent Packages: 1
- Dependent Repositories: 4
- Downloads: 1,396 Last month
- Docker Downloads: 9
-
Rankings:
- Forks count: 3.341%
- Stargazers count: 3.577%
- Docker downloads count: 6.448%
- Average: 9.838%
- Downloads: 13.194%
- Dependent repos count: 14.8%
- Dependent packages count: 17.666%
- Maintainers (1)
Dependencies
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- actions/cache v2 composite
- actions/checkout v2 composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v1 composite
- R >= 3.5.0 depends
- proto >= 1.0.0 depends
- raster >= 3.5 depends
- sf >= 0.8 depends
- sp * depends
- Matrix * imports
- ape >= 5.5 imports
- assertthat >= 0.2.0 imports
- doParallel >= 1.0.16 imports
- exactextractr >= 0.2.0 imports
- fasterize >= 1.0.2 imports
- igraph >= 1.2.9 imports
- magrittr >= 2.0.1 imports
- methods * imports
- parallel * imports
- plyr >= 1.8.6 imports
- rgeos >= 0.5 imports
- slam >= 0.1 imports
- tibble >= 2.0.0 imports
- utils * imports
- uuid >= 1.0 imports
- withr >= 2.3.0 imports
- PBSmapping >= 2.73.0 suggests
- Rsymphony >= 0.1 suggests
- cplexAPI >= 1.4.0 suggests
- data.table >= 1.14.2 suggests
- gurobi >= 8.0 suggests
- knitr >= 1.36 suggests
- lpsymphony >= 1.17.0 suggests
- maptools >= 1.1 suggests
- prioritizrdata >= 0.2.4 suggests
- rcbc >= 0.1.0.9001 suggests
- rmarkdown >= 2.11 suggests
- roxygen2 >= 7.1.2 suggests
- scales >= 1.1.1 suggests
- testthat >= 3.1.0 suggests
- actions/checkout v2 composite
Score: 14.525160810623234