Save the mathematical formulation for a conservation planning problem() to a file for mixed integer programming solvers. Note that this function requires the Rsymphony package to be installed.

write_problem(x, path)

Arguments

x

problem() (i.e., ConservationProblem) object.

path

character file path to save the problem formulation. The argument should contain a ".lp" or .mps" file extension to specify whether the problem formulation will be saved in the LP or MPS format (respectively).

Value

Invisible TRUE indicating success.

Examples

# \dontrun{
# set seed for reproducibility
set.seed(500)

# load data
data(sim_pu_raster, sim_features)

# create minimal problem
p <- problem(sim_pu_sf[1:4, , drop = FALSE], 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")

# save problem to file (using the Rsymphony package)
write_problem(p, path)

# print model file
cat(readLines(path), sep = "\n")
#> \Problem name: 
#> 
#> Minimize
#> obj: 215.863839903 x0 + 212.782348080 x1 + 207.496243710 x2 + 208.932169949 x3
#> Subject To
#> cons0:  -0.277834868 x0 -0.277834868 x1 -0.277834868 x2 -0.277834868 x3 <= -0.277834868
#> cons1:  -0.127301291 x0 -0.127301291 x1 -0.127301291 x2 -0.127301291 x3 <= -0.127301291
#> cons2:  -0.316365083 x0 -0.316365083 x1 -0.316365083 x2 -0.316365083 x3 <= -0.316365083
#> cons3:  -0.121097958 x0 -0.121097958 x1 -0.121097958 x2 -0.121097958 x3 <= -0.121097958
#> cons4:  -0.176466230 x0 -0.176466230 x1 -0.176466230 x2 -0.176466230 x3 <= -0.176466230
#> Bounds
#>  0 <= x0 <= 1
#>  0 <= x1 <= 1
#>  0 <= x2 <= 1
#>  0 <= x3 <= 1
#> Integers
#> x0 x1 x2 x3 
#> End
# }