write_problem: Write problem

View source: R/write_problem.R

write_problemR 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 the Rsymphony package to be installed.

Usage

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

## Not run: 
# 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")

## End(Not run)


prioritizr documentation built on Sept. 18, 2022, 1:05 a.m.