Skip to contents

Use lp_variable() to define the variables, lp_minimize() or lp_maximize() to define the objective function, lp_constraint() to add constraints and lp_solve() to find the optimum.

Usage

lp_problem()

Value

An lp_problem object with fields:

Examples

# ROI or a ROI plugin needs to be loaded for lp_solve() to work
library(ROI) |> suppressMessages()

lp_problem() |>
    lp_variable(x[1:2], lower = 0) |>
    lp_maximize(x[1] + x[2]) |>
    lp_constraint(
        2*x[1] +   x[2] <= 8,
        2*x[1] + 3*x[2] <= 12
    ) |>
    lp_solve()
#> $variables
#> $variables$x
#> 1:2
#> 1 2 
#> 3 2 
#> 
#> 
#> $objective
#> [1] 5
#> 
#> $status$code = 0  (Optimal)
#> 
#> Fields:
#> -- $objective --
#> -- $variables --
#> -- $aliases --
#> -- $variables_vec --
#> -- $status --
#> -- $message --
#> -- $model --

# For a Quick Start guide see `vignette("lpsugar", package = "lpsugar")`