solve.RestoptProblem {restoptr} | R Documentation |
Solve a restoration optimization problem
Description
Solve a restoration optimization problem to generate a solution.
Usage
## S3 method for class 'RestoptProblem'
solve(a, b, ...)
Arguments
a |
|
b |
Argument not used. |
... |
Additional arguments:
|
Details
This function relies on the Choco-solver (https://choco-solver.org/) to solve a restoration optimization problem. If the solver finds a solution, it outputs a raster with 5 possible values: NA : NA (or NO_DATA) areas from the input habitat raster. 0 : non-habitat areas that were locked out. 1 : non-habitat areas that were available for selection. 2 : habitat areas. 3 : selected planning units for restoration. If the solve function return a no-solution error, it is either because the solver could not find a solution within the time limit that was set (see add_settings), or because the solver has detected that this is not possible to satisfy the constraints (the constraints are contradictory). In the first case, you can try to increase the time limit. In the second case, you should modify your targets.
Value
A restopt_solution()
object.
Examples
# load data
habitat_data <- rast(
system.file("extdata", "habitat_hi_res.tif", package = "restoptr")
)
available <- vect(
system.file("extdata", "accessible_areas.gpkg", package = "restoptr")
)
# create problem with locked out constraints
p <- restopt_problem(
existing_habitat = habitat_data,
aggregation_factor = 16,
habitat_threshold = 0.7
) %>%
set_max_mesh_objective() %>%
add_restorable_constraint(
min_restore = 5,
max_restore = 5,
) %>%
add_available_areas_constraint(available) %>%
add_settings(time_limit = 1)
# print problem
print(p)
# solve problem
s <- solve(p)
# plot solution
plot(s)