Specify that the Gurobi software (Gurobi Optimization LLC 2021) should be used to solve a conservation planning problem(). This function can also be used to customize the behavior of the solver. It requires the gurobi package to be installed (see below for installation instructions).

  gap = 0.1,
  time_limit = .Machine$integer.max,
  presolve = 2,
  threads = 1,
  first_feasible = FALSE,
  numeric_focus = FALSE,
  verbose = TRUE



problem() (i.e. ConservationProblem) object.


numeric gap to optimality. This gap is relative and expresses the acceptable deviance from the optimal objective. For example, a value of 0.01 will result in the solver stopping when it has found a solution within 1% of optimality. Additionally, a value of 0 will result in the solver stopping when it has found an optimal solution. The default value is 0.1 (i.e. 10% from optimality).


numeric time limit (seconds) for generating solutions. The solver will return the current best solution when this time limit is exceeded. The default value is the largest integer value (i.e. .Machine$integer.max), effectively meaning that solver will keep running until a solution within the optimality gap is found.


integer number indicating how intensively the solver should try to simplify the problem before solving it. Available options are: (-1) automatically determine the intensity of pre-solving, (0) disable pre-solving, (1) conservative level of pre-solving, and (2) very aggressive level of pre-solving . The default value is 2.


integer number of threads to use for the optimization algorithm. The default value is 1.


logical should the first feasible solution be be returned? If first_feasible is set to TRUE, the solver will return the first solution it encounters that meets all the constraints, regardless of solution quality. Note that the first feasible solution is not an arbitrary solution, rather it is derived from the relaxed solution, and is therefore often reasonably close to optimality. Defaults to FALSE.


logical should extra attention be paid to verifying the accuracy of numerical calculations? This may be useful when dealing problems that may suffer from numerical instability issues. Beware that it will likely substantially increase run time (sets the Gurobi NumericFocus parameter to 3). Defaults to FALSE.


logical should information be printed while solving optimization problems? Defaults to TRUE.


Object (i.e. ConservationProblem) with the solver added to it.


Gurobi is a state-of-the-art commercial optimization software with an R package interface. It is by far the fastest of the solvers available for generating prioritizations, however, it is not freely available. That said, licenses are available to academics at no cost. The gurobi package is distributed with the Gurobi software suite. This solver uses the gurobi package to solve problems. For information on the performance of different solvers, please see Schuster et al. (2020) for benchmarks comparing the run time and solution quality of different solvers when applied to different sized datasets.


Please see the Gurobi Installation Guide vignette for details on installing the Gurobi software and the gurobi package. You can access this vignette online or using the following code:

vignette("gurobi_installation", package = "prioritizr")


Gurobi Optimization LLC (2021) Gurobi Optimizer Reference Manual. http://www.gurobi.com.

Schuster R, Hanson JO, Strimas-Mackey M, and Bennett JR (2020). Exact integer linear programming solvers outperform simulated annealing for solving conservation planning problems. PeerJ, 8: e9258.

See also


# \dontrun{ # load data data(sim_pu_raster, sim_features) # create problem p <- problem(sim_pu_raster, sim_features) %>% add_min_set_objective() %>% add_relative_targets(0.1) %>% add_binary_decisions() %>% add_gurobi_solver(gap = 0.1, verbose = FALSE) # generate solution %>% s <- solve(p) # plot solution plot(s, main = "solution", axes = FALSE, box = FALSE)
# }