if (FALSE) {
# load data
sim_pu_raster <- get_sim_pu_raster()
sim_features <- get_sim_features()
# create basic problem
p <-
problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_relative_targets(0.1) %>%
add_proportion_decisions()
# create vector to store plot names
n <- c()
# create empty list to store solutions
s <- c()
# if gurobi is installed: create problem with added gurobi solver
if (require("gurobi")) {
p1 <- p %>% add_gurobi_solver(verbose = FALSE)
n <- c(n, "gurobi")
s <- c(s, solve(p1))
}
# if cplexAPI is installed: create problem with added CPLEX solver
if (require("cplexAPI")) {
p2 <- p %>% add_cplex_solver(verbose = FALSE)
n <- c(n, "CPLEX")
s <- c(s, solve(p2))
}
# if rcbc is installed: create problem with added CBC solver
if (require("rcbc")) {
p3 <- p %>% add_cbc_solver(verbose = FALSE)
n <- c(n, "CBC")
s <- c(s, solve(p3))
}
# if highs is installed: create problem with added HiGHs solver
if (require("highs")) {
p4 <- p %>% add_highs_solver(verbose = FALSE)
n <- c(n, "HiGHS")
s <- c(s, solve(p4))
}
# create problem with added rsymphony solver
if (require("Rsymphony")) {
p5 <- p %>% add_rsymphony_solver(verbose = FALSE)
n <- c(n, "Rsymphony")
s <- c(s, solve(p5))
}
# if lpsymphony is installed: create problem with added lpsymphony solver
if (require("lpsymphony")) {
p6 <- p %>% add_lpsymphony_solver(verbose = FALSE)
n <- c(n, "lpsymphony")
s <- c(s, solve(p6))
}
# plot solutions
names(s) <- n
plot(terra::rast(s), axes = FALSE)
}
Run the code above in your browser using DataLab