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.

## Usage

write_problem(x, path)

## Arguments

x

problem() 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

An invisible TRUE indicating success.

## Examples

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

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") %>%

# specify file path to save problem formulation
path <- file.path(tempdir(), "model.lp")
print(path)
#>  "/tmp/RtmpYxDe7o/model.lp"

# save problem to file
## note that the Rsymphony package needs to be installed
write_problem(p, path)

# print model file
#> \Problem name:
#>
#> Minimize
#> obj: 215.863839903 x0 + 212.782348080 x1 + 207.496243710 x2 + 208.932169949 x3
#> Subject To
#> cons0:  -0.277834862 x0 -0.277834862 x1 -0.277834862 x2 -0.277834862 x3 <= -0.277834862
#> cons1:  -0.127301294 x0 -0.127301294 x1 -0.127301294 x2 -0.127301294 x3 <= -0.127301294
#> cons2:  -0.316365081 x0 -0.316365081 x1 -0.316365081 x2 -0.316365081 x3 <= -0.316365081
#> cons3:  -0.121097955 x0 -0.121097955 x1 -0.121097955 x2 -0.121097955 x3 <= -0.121097955
#> 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
# }