# NOT RUN {
# load data
data(sim_pu_raster, sim_features)
# create basic problem
p <- problem(sim_pu_raster, sim_features) %>%
add_min_set_objective() %>%
add_relative_targets(0.1) %>%
add_binary_decisions()
# create vector to store plot titles
titles <- c()
# create empty stack to store solutions
s <- stack()
# create problem with added rsymphony solver and limit the time spent
# searching for the optimal solution to 2 seconds
if (require("Rsymphony")) {
titles <- c(titles, "Rsymphony (2s)")
p1 <- p %>% add_rsymphony_solver(time_limit = 2)
s <- addLayer(s, solve(p1))
}
# create problem with added rsymphony solver and limit the time spent
# searching for the optimal solution to 5 seconds
if (require("Rsymphony")) {
titles <- c(titles, "Rsymphony (5s)")
p2 <- p %>% add_rsymphony_solver(time_limit = 5)
s <- addLayer(s, solve(p2))
}
# if the gurobi is installed: create problem with added gurobi solver
if (require("gurobi")) {
titles <- c(titles, "gurobi (5s)")
p3 <- p %>% add_gurobi_solver(gap = 0.1, presolve = 2, time_limit = 5)
s <- addLayer(s, solve(p3))
}
# if the lpsymphony is installed: create problem with added lpsymphony solver
# note that this solver is skipped on Linux systems due to instability
# issues
if (require("lpsymphony") &
isTRUE(Sys.info()[["sysname"]] != "Linux")) {
titles <- c(titles, "lpsymphony")
p4 <- p %>% add_lpsymphony_solver(gap = 0.1, time_limit = 10)
s <- addLayer(s, solve(p4))
}
# plot solutions
plot(s, main = titles, axes = FALSE, box = FALSE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab