Generate a portfolio of solutions for a conservation planning problem() by randomly reordering the data prior to solving the problem. This is recommended as a replacement for add_top_portfolio() when the Gurobi software is not available.

add_shuffle_portfolio(
x,
number_solutions = 10L,
remove_duplicates = TRUE
)

## Arguments

x problem() (i.e. ConservationProblem) object. integer number of attempts to generate different solutions. Defaults to 10. integer number of threads to use for the generating the solution portfolio. Defaults to 1. logical should duplicate solutions be removed? Defaults to TRUE.

## Value

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

## Details

This strategy for generating a portfolio of solutions often results in different solutions, depending on optimality gap, but may return duplicate solutions. In general, this strategy is most effective when problems are quick to solve and multiple threads are available for solving each problem separately.

## Examples

# set seed for reproducibility
set.seed(500)

data(sim_pu_raster, sim_features, sim_pu_zones_stack, sim_features_zones)

# create minimal problem with shuffle portfolio
p1 <- problem(sim_pu_raster, sim_features) %>%
add_default_solver(gap = 0.2, verbose = FALSE)

# \dontrun{
# solve problem and generate 10 solutions within 20 % of optimality
s1 <- solve(p1)

# plot solutions in portfolio
plot(stack(s1), axes = FALSE, box = FALSE) # }
# build multi-zone conservation problem with shuffle portfolio
p2 <- problem(sim_pu_zones_stack, sim_features_zones) %>%
add_relative_targets(matrix(runif(15, 0.1, 0.2), nrow = 5,
ncol = 3)) %>%
add_default_solver(gap = 0.2, verbose = FALSE)

# \dontrun{
# solve the problem
s2 <- solve(p2)

# print solution
str(s2, max.level = 1)#> List of 10
#>  $solution_1 :Formal class 'RasterStack' [package "raster"] with 11 slots #>$ solution_2 :Formal class 'RasterStack' [package "raster"] with 11 slots
#>  $solution_3 :Formal class 'RasterStack' [package "raster"] with 11 slots #>$ solution_4 :Formal class 'RasterStack' [package "raster"] with 11 slots
#>  $solution_5 :Formal class 'RasterStack' [package "raster"] with 11 slots #>$ solution_6 :Formal class 'RasterStack' [package "raster"] with 11 slots
#>  $solution_7 :Formal class 'RasterStack' [package "raster"] with 11 slots #>$ solution_8 :Formal class 'RasterStack' [package "raster"] with 11 slots
#>  $solution_9 :Formal class 'RasterStack' [package "raster"] with 11 slots #>$ solution_10:Formal class 'RasterStack' [package "raster"] with 11 slots
#>  - attr(*, "objective")= Named num [1:10] 12457 11858 11641 11843 11925 ...
#>   ..- attr(*, "names")= chr [1:10] "solution_1" "solution_2" "solution_3" "solution_4" ...
#>  - attr(*, "status")= Named chr [1:10] "OPTIMAL" "OPTIMAL" "OPTIMAL" "OPTIMAL" ...
#>   ..- attr(*, "names")= chr [1:10] "solution_1" "solution_2" "solution_3" "solution_4" ...
#>  - attr(*, "runtime")= Named num [1:10] 0.00502 0.00487 0.00528 0.00513 0.00503 ...
#>   ..- attr(*, "names")= chr [1:10] "solution_1" "solution_2" "solution_3" "solution_4" ...
# plot solutions in portfolio
plot(stack(lapply(s2, category_layer)), main = "solution", axes = FALSE,
box = FALSE) # }