write_problem {prioritizr} | R Documentation |
Write problem
Description
Save the mathematical formulation for a conservation planning problem to a file for mixed integer programming solvers. Note that this function requires either the Rsymphony or gurobi package to be installed.
Usage
write_problem(x, path, solver = NULL)
Arguments
x |
|
path |
|
solver |
|
Value
An invisible TRUE
indicating success.
Examples
## Not run:
# set seed for reproducibility
set.seed(500)
# load data
sim_pu_polygons <- get_sim_pu_polygons()
sim_features <- get_sim_features()
# subset data to extract first four planning units
sim_pu_polygons <- sim_pu_polygons[1:4, ]
# create minimal problem
p <-
problem(sim_pu_polygons, sim_features, cost_column = "cost") %>%
add_min_set_objective() %>%
add_relative_targets(0.1) %>%
add_binary_decisions()
# specify file path to save problem formulation
path <- file.path(tempdir(), "model.lp")
print(path)
# save problem to file
## note that either the gurobi or Rsymphony package needs to be installed
write_problem(p, path)
# print model file
cat(readLines(path), sep = "\n")
## End(Not run)