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

## 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 the Rsymphony package needs to be installed
write_problem(p, path)

# print model file
cat(readLines(path), sep = "\n")

## End(Not run)


prioritizr documentation built on Aug. 9, 2023, 1:06 a.m.