Learn R Programming

prioritizr (version 4.1.5)

add_gurobi_solver: Add a Gurobi solver

Description

Specify that the Gurobi software 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.

Usage

add_gurobi_solver(x, gap = 0.1, time_limit = .Machine$integer.max,
  presolve = 2, threads = 1, first_feasible = 0,
  numeric_focus = FALSE, verbose = TRUE)

Arguments

gap

numeric gap to optimality. This gap is relative when solving problems using gurobi, and will cause the optimizer to terminate when the difference between the upper and lower objective function bounds is less than the gap times the upper bound. For example, a value of 0.01 will result in the optimizer stopping when the difference between the bounds is 1 percent of the upper bound.

time_limit

numeric time limit in seconds to run the optimizer. The solver will return the current best solution when this time limit is exceeded.

presolve

integer number indicating how intensively the solver should try to simplify the problem before solving it. The default value of 2 indicates to that the solver should be very aggressive in trying to simplify the problem.

threads

integer number of threads to use for the optimization algorithm. The default value of 1 will result in only one thread being used.

first_feasible

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.

numeric_focus

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.

verbose

logical should information be printed while solving optimization problems?

Value

ConservationProblem-class object with the solver added to it.

Details

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 in this package, however, it is also the only solver that 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.

See Also

solvers.

Examples

Run this code
# NOT RUN {
# 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()
# }
# NOT RUN {
# if the package is installed then add solver and generate solution
if (require("gurobi")) {
  # specify solver and generate solution
  s <- p %>% add_gurobi_solver(gap = 0.1, presolve = 2, time_limit = 5) %>%
             solve()

  # plot solutions
  plot(stack(sim_pu_raster, s), main = c("planning units", "solution"),
       axes = FALSE, box = FALSE)
}
# }

Run the code above in your browser using DataLab