Sys.setenv(ROI_LOAD_PLUGINS = "FALSE")
library(ROI)
library(ROI.plugin.glpk)
library(ROI.plugin.qpoases)
library(ROI.plugin.ecos)
library(ROI.plugin.scs)
library(ROI.plugin.alabama)
library(ROI.plugin.lpsolve)
library(ROI.plugin.gurobi)

Constructors

Optimization Problem

str(OP)
## function (objective, constraints, types, bounds, maximum = FALSE)

Objective

Linear objective

str(L_objective)
## function (L, names = NULL)

\[1 x + 2 y + 3 z\]

lo <- L_objective(c(1, 2, 3), c("x", "y", "z"))

Quadratic objective

str(Q_objective)
## function (Q, L = NULL, names = NULL)

\[\frac{1}{2} (x_1^2 + x_2^2 + x_3^2) + 1 x_1 + 2x_2 + 3x_3\]

qo <- Q_objective(diag(3), c(1, 2, 3), c("x_1", "x_2", "x_3"))

Functional objective}

str(F_objective)
## function (F, n, G = NULL, H = NULL, names = NULL)

\[x_1^2 + x_2^2\]

fo <- F_objective(F = function(x) sum(x^2), n = 2, 
                  G = function(x) 2*x, names = c("x_1", "x_2"))

Constraints

Linear constraints

str(L_constraint)
## function (L, dir, rhs, names = NULL)

\[ \nonumber \begin{array}{rrrrrrr} 3 x & + & 4 y & + & 1 z & \leq & 90 \\ 1 x & + & 0 y & + & 2 z & \geq & 5 \\ 1 x & + & 1 y & + & 0 z & = & 2 \end{array} \]

lc <- L_constraint(L = rbind(c(3, 4, 1), c(1, 0, 2), c(1, 1, 0)),
                   dir = c("<=", ">=", "=="), rhs = c(90, 5, 2),
                   names = c("x", "y", "z"))

Quadratic constraints

str(Q_constraint)
## function (Q, L, dir, rhs, names = NULL)

\[\frac{1}{2} (x^2 + y^2) + 1x + 2y \leq 3\]

qc1 <- Q_constraint(Q = diag(2), L = 1:2, dir = "<=", 
                    rhs = 3, names = c("x", "y"))

\[ \begin{array} x^2 + y^2 + 3x + 1y & \leq & 3 \nonumber \\ x + y & \leq & 4 \nonumber \\ \frac{1}{2} (3x^2 + 3y^2 + 2xy) + 2x + 5y & \leq & 9 \nonumber \end{array} \]

qc2 <- Q_constraint(Q = list(diag(2, 2), NULL, matrix(c(3, 1, 1, 3), 2)), 
                    L = rbind(c(3, 1), c(1, 1), c(2, 5)),
                    dir = c("<=", "<=", "<="),
                    rhs = c(3, 4, 9), names = c("x", "y"))

Functional constraints

str(F_constraint)
## function (F, dir, rhs, J = NULL, names = NULL)

\[ \begin{array} x^2 & \leq & 2 \nonumber \\ y^2 & \leq & 4 \nonumber \end{array} \]

fc1 <- F_constraint(F = function(x) x^2, dir = c("<=", "<="), rhs = c(2, 4),
                    J = function(x) diag(x = 2, nrow = 2) * x,
                    names = c("x", "y"))

or equivalently

fc2 <- F_constraint(F = list(function(x) x[1]^2, function(x) x[2]^2), 
                    dir = c("<=", "<="), rhs = c(2, 4),
                    J = list(function(x) rbind(c(2, 0) * x), 
                             function(x) rbind(c(0, 2) * x)),
                    names = c("x", "y"))

## TODO: create an example
## x <- OP(L_objective(c(1, 1)), fc1, maximum=TRUE)
## x <- OP(L_objective(c(1, 1)), fc2, maximum=TRUE)
## solution(ROI_solve(x, start=c(0, 1), solver="alabama"))

Bounds

Variable bounds

By default the variable bounds are set to \(0 \leq x_i \leq \infty \text{ for all } i = 1, ..., n.\)

str(V_bound)
## function (li, ui, lb, ub, nobj, ld = 0, ud = Inf, names = NULL)

\[ -3 \leq x_1 \leq 3, \ -\infty \leq x_2 \leq 7, \ -9 \leq x_3 \leq \infty \]

vb <- V_bound(li = 1:3, ui = 1:3, lb = c(-3, -Inf, -9), ub = c(3, 7, Inf))

Basic examples

Linear programming (LP)

Example 1

\[ \begin{array}{rrrrr} \text{minimize} & 7 x_1 & + & 8 x_2 \\ \text{subject to} & 3 x_1 & + & 4 x_2 & = 9 \\ & 2 x_1 & + & 1 x_2 & \geq 3 \end{array} \]

\[ -100 \leq x_1, x_2, \leq 100\]

lp  <- OP(objective = L_objective(c(7, 8), names=c("x", "y")),
          constraints = L_constraint(L = rbind(c(3, 4), c(2, 1)), 
                                     dir = c("==", ">="), rhs = c(9, 3)),
          bounds = V_bound(li = 1:2, ui = 1:2, 
                           lb = c(-100, -100), ub = c(100, 100)))
ROI_applicable_solvers(lp)
## [1] "glpk"    "qpoases" "ecos"    "scs"     "alabama" "lpsolve" "gurobi"
(sol <- ROI_solve(lp, solver = "glpk"))
## Optimal solution found.
## The objective value is: 1.860000e+01
solution(sol)
##   x   y 
## 0.6 1.8

The solution can be accessed via the function , where

solution(sol)
##   x   y 
## 0.6 1.8
solution(sol, type = "primal")
##   x   y 
## 0.6 1.8

gives the primal solution,

solution(sol, type = "dual")
## [1] 0 0

the dual solution,

solution(sol, type = "msg")
## $optimum
## [1] 18.6
## 
## $solution
## [1] 0.6 1.8
## 
## $status
## [1] 5
## 
## $solution_dual
## [1] 0 0
## 
## $auxiliary
## $auxiliary$primal
## [1] 9 3
## 
## $auxiliary$dual
## [1] 1.8 0.8
## 
## 
## $sensitivity_report
## [1] NA

the original message returned from the solver.

Example 2

\[\begin{array}{rrrrrrr} \text{maximize} & 7 x_1 & + & 3 x_2 & + & 1 x_3 & \\ \text{subject to} & 6 x_1 & + & 4 x_2 & + & 5 x_3 & \leq 60 \\ & 8 x_1 & + & x_2 & + & 2 x_3 & \leq 80 \\ & 9 x_1 & + & 1 x_2 & + & 7 x_3 & \leq 70 \end{array} \] \[x_1, x_2, x_3 \geq 0\]

lp <- OP(objective = L_objective(c(7, 1, 3), c("x", "y", "z")),
         constraints = L_constraint(L = rbind(c(6, 4, 5), c(8, 0, 2), c(9, 1, 7)),
                                    dir = c("<=", "<=", "<="),
                                    rhs = c(60, 80, 70)),
         maximum = TRUE)
(sol <- ROI_solve(lp))
## Optimal solution found.
## The objective value is: 5.533333e+01
solution(sol)
##        x        y        z 
## 7.333333 4.000000 0.000000

Mixed integer linear programming (MILP)

\[\begin{array}{rrrrrrr} \text{maximize} & 7 x_1 & + & 3 x_2 & + & 1 x_3 & \\ \text{subject to} & 6 x_1 & + & 4 x_2 & + & 5 x_3 & \leq 60 \\ & 8 x_1 & + & x_2 & + & 2 x_3 & \leq 80 \\ & 9 x_1 & + & 1 x_2 & + & 7 x_3 & \leq 70 \end{array} \] \[x_1, x_3 \in \mathbb{Z}_{\geq 0}\] \[x_2 \geq 0\]

A <- rbind(c(6, 4, 5), c(8, 0, 2), c(9, 1, 7))
milp <- OP(objective = L_objective(c(7, 1, 3), c("x", "y", "z")),
           constraints = L_constraint(L = rbind(c(6, 4, 5), c(8, 0, 2), c(9, 1, 7)),
                                      dir = c("<=", "<=", "<="),
                                      rhs = c(60, 80, 70)),
           types = c("I", "C", "I"), 
           maximum = TRUE)
(sol <- ROI_solve(milp))
## Optimal solution found.
## The objective value is: 5.350000e+01
solution(sol)
##   x   y   z 
## 7.0 4.5 0.0

Quadratic programming

Quadratic objective with linear constraints (QP)

\[ \begin{array} \text{minimize} & & x_1 & + & 2x_2 & + & 3x_3 & + & \frac{1}{2} (x_1^2 + x_2^2 + x_3^2) \\ \text{subject to} & & x_1 & + & x_2 & & & \geq & 1 \nonumber \\ & & & & x_2 & + & x_3 & \geq & 2 \nonumber \\ & & x_1 & & & + & x_3 & \geq & 3 \nonumber \\ \end{array} \]

qp <- OP(Q_objective(diag(3), c(1, 2, 3), c("x", "y", "z")),
         L_constraint(L = rbind(c(1, 1, 0), c(0, 1, 1), c(1, 0, 1)), 
                      dir = c(">=", ">=", ">="), rhs = c(1, 2, 3)))
(sol <- ROI_solve(qp, solver = "qpoases"))
## Optimal solution found.
## The objective value is: 9.333333e+00
solution(sol)
##         x         y         z 
## 1.3333333 0.3333333 1.6666667

Quadratic objective with quadratic constraints (QCQP)

\[ \text{maximize} \ \ 90 x_1 + 110 x_2 + 160 x_3 - \frac{1}{2} (x_1^2 + x_2^2 + x_3^2) \] \[ \begin{array}{rrrrr} \text{subject to} & x_1^2 + x_2^2 + 4 x_3 & \leq & 4 & \\ & x_2^2 + x_3^2 + x_1 + x_3 & \leq & 3 & \\ & x_1^2 + x_3^2 + 2 x_1 x_3 & \leq & 2 & \\ & x_1, x_2, x_3 \geq 0 & & & \end{array} \]

qcqp <- OP(Q_objective(-diag(3), c(90, 110, 160), c("x", "y", "z")),
           Q_constraint(Q = list(rbind(c(2, 0, 0), c(0, 2, 0), c(0, 0, 0)),
                                 rbind(c(0, 0, 0), c(0, 2, 0), c(0, 0, 2)),
                                 rbind(c(2, 0, 2), c(0, 0, 0), c(2, 0, 2))),
                        L = rbind(c(0, 0, 4), c(1, 0, 1), c(0, 0, 0)),
                        dir = rep("<=", 3), rhs = c(4, 3, 2)),
           maximum = TRUE)
(sol <- ROI_solve(qcqp, solver = "gurobi"))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
##         x         y         z 
## 1.0606575 1.2086302 0.3535547

or equivalently

qc1 <- Q_constraint(Q = rbind(c(2, 0, 0), c(0, 2, 0), c(0, 0, 0)),
                    L = c(0, 0, 4), dir = "<=", rhs = 4)
qc2 <- Q_constraint(Q = rbind(c(0, 0, 0), c(0, 2, 0), c(0, 0, 2)),
                    L = c(1, 0, 1), dir = "<=", rhs = 3)
qc3 <- Q_constraint(Q = rbind(c(2, 0, 2), c(0, 0, 0), c(2, 0, 2)),
                    L = NULL, dir = "<=", rhs = 2)
qcqp <- OP(Q_objective(-diag(3), c(90, 110, 160), c("x", "y", "z")),
           c(qc1, qc2, qc3), maximum = TRUE)

(sol <- ROI_solve(qcqp, solver = "gurobi"))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
##         x         y         z 
## 1.0606575 1.2086302 0.3535547

Check how tight the bounds are.

sapply(as.function(constraints(qcqp)), function(F) F(solution(sol)))
## [1] 4.000000 3.000000 1.999996

Conic programming (CP)

Second-order cone programming (SOCP)

\[\text{maximize } \ \ x + y\] \[\text{subject to } \ \ \sqrt{x^2 + y^2} \leq \sqrt{2}\] \[x, y \geq 0\]

socp1 <- OP(objective = L_objective(c(1, 1), names = c("x", "y")),
            constraints = C_constraint(rbind(c(0, 0), c(-1, 0), c(0, -1)),
                                       cones = K_soc(3), 
                                       rhs = c(sqrt(2), 0, 0)),
            maximum = TRUE)
(sol <- ROI_solve(socp1))
## Optimal solution found.
## The objective value is: 2.000000e+00
solution(sol)
## x y 
## 1 1

Positive semidefinite programming (SDP)

\[ \begin{array}{rl} \text{minimize} & x_1 + x_2 - x_3 \\ \text{subject to} & x_1 \begin{pmatrix} 10 & 3 \\ 3 & 10 \end{pmatrix} + x_2 \begin{pmatrix} 6 & -4 \\ -4 & 10 \end{pmatrix} + x_3 \begin{pmatrix} 8 & 1 \\ 1 & 6 \end{pmatrix} \preceq \begin{pmatrix} 16 & -13 \\ -13 & 60 \end{pmatrix} \\ & x_1, x_2, x_3 \geq 0 \nonumber \end{array} \]

A1 <- rbind(c(10, 3), c(3, 10))
A2 <- rbind(c(6, -4), c(-4, 10))
A3 <- rbind(c(8, 1), c(1, 6))
A4 <- rbind(c(16, -13), c(-13, 60))
psd <- OP(objective = L_objective(c(1, 1, -1)),
          constraints = C_constraint(L = vech(A1, A2, A3), 
                                     cones = K_psd(3),
                                     rhs = vech(A4)))
(sol <- ROI_solve(psd))
## Optimal solution found.
## The objective value is: -1.486461e+00
solution(sol)
## [1] -1.937019e-08 -5.371359e-08  1.486461e+00
as.matrix(solution(sol, "psd")[[1]])
##            [,1]        [,2]
## [1,] 0.11050022 0.031337481
## [2,] 0.03133748 0.008887201

The following example taken from the CVXOPT homepage.

\[ \begin{array}{rl} \text{minimize} & x_1 - x_2 + x_3 \\ \text{subject to} & x_1 \ \begin{pmatrix} -7 & -11 \\ -11 & 3 \end{pmatrix} + x_2 \ \begin{pmatrix} 7 & -18 \\ -18 & 8 \end{pmatrix} + x_3 \ \begin{pmatrix} -2 & -8 \\ -8 & 1 \end{pmatrix} \ \preceq \ \begin{pmatrix} 33 & -9 \\ -9 & 26 \end{pmatrix} \ \\ & x_1 \ \begin{pmatrix} -21 & -11 & 0 \\ -11 & 10 & 8 \\ 0 & 8 & 5 \end{pmatrix} + x_2 \ \begin{pmatrix} 0 & 10 & 16 \\ 10 & -10 & -10 \\ 16 & -10 & 3 \end{pmatrix} + x_3 \ \begin{pmatrix} -5 & 2 & -17 \\ 2 & -6 & 8 \\ -17 & 8 & 6 \end{pmatrix} \ \preceq \ \begin{pmatrix} 14 & 9 & 40 \\ 9 & 91 & 10 \\ 40 & 10 & 15 \end{pmatrix} \ \\ & x_1, x_2, x_3 \in \mathbb{R} \end{array} \nonumber \]

obj <- c(1, -1, 1)
A1 <- matrix(c(-7, -11, -11,  3), 2)
A2 <- matrix(c( 7, -18, -18,  8), 2)
A3 <- matrix(c(-2,  -8,  -8,  1), 2)
A4 <- matrix(c(33,  -9,  -9, 26), 2)
B1 <- matrix(c(-21, -11,  0, -11,  10,   8,  0,    8, 5), 3)
B2 <- matrix(c(  0,  10,  16, 10, -10, -10,  16, -10, 3), 3)
B3 <- matrix(c( -5,   2, -17,  2,  -6,   8, -17,   8, 6), 3)
B4 <- matrix(c( 14,   9,  40,  9,  91,  10,  40,  10,15), 3)
rhs <- c(vech(A4), vech(B4))

psd <- OP(objective = obj,
          constraints = C_constraint(L = rbind(vech(A1, A2, A3), vech(B1, B2, B3)), 
                                     cones = K_psd(c(3, 6)), rhs = rhs),
          bounds = V_bound(li=1:3, lb=rep(-Inf, 3)))

(sol <- ROI_solve(psd, solver = "scs"))
## Optimal solution found.
## The objective value is: -3.153545e+00
solution(sol)
## [1] -0.3677513  1.8983332 -0.8874604
lapply(solution(sol, type="psd"), as.matrix)
## $`5`
##              [,1]         [,2]
## [1,]  0.003961386 -0.004339146
## [2,] -0.004339146  0.004752929
## 
## $`6`
##              [,1]          [,2]         [,3]
## [1,]  0.055803080 -0.0024106686  0.024214084
## [2,] -0.002410669  0.0001041398 -0.001046038
## [3,]  0.024214084 -0.0010460378  0.010506980

Exponential cone

\[ \begin{array} \mathcal{K}_{exp} &=& \{(x, y, z) | y > 0, y e^{\frac{x}{y}} \leq z \} \cup \{(x, 0, z) | x \leq 0, z \geq 0\} \\ \mathcal{K}_{exp}^* &=& \{(u, v, w) | u < 0, -ue^\frac{v}{u} \leq ew\} \cup \{(0, v, w) | v \geq 0, w \geq 0\} \end{array} \]

Primal exponential cone

\[ \begin{array} \text{maximize} & x + y + z \\ \text{subject to} & y e^{\frac{x}{y}} \leq z \\ & x \geq 0, y > 0, z \in [0, e] \end{array} \]

expp <- OP(objective = L_objective(c(1, 1, 1)),
           constraints = C_constraint(diag(-1, 3), cones = K_expp(1), 
                                      rhs = rep(0, 3)),
           bounds = V_bound(li = 2, lb = 1e-12, ui = 3, ub = exp(1)),
           maximum = TRUE)
(sol <- ROI_solve(expp, tol=1e-8, solver="scs"))
## Optimal solution found.
## The objective value is: 5.436564e+00
solution(sol)
## [1] 2.614608e-08 2.718282e+00 2.718282e+00

Dual exponential cone

\[ \begin{array} \text{minimize} & u + v + w \\ \text{subject to} & -u e^{\frac{v}{u}} \leq ew \\ & u \in [-1, 0], y, z \geq 0 \end{array} \]

expd <- OP(objective = L_objective(c(1, 1, 1), names = c("u", "v", "w")),
           constraints = C_constraint(diag(x=-1, 3), cones = K_expd(1), 
                                      rhs = rep(0, 3)), 
           bounds = V_bound(li = 1, lb = -1, ui = 1, ub = 0, nobj = 3L))
(sol <- ROI_solve(expd))
## Optimal solution found.
## The objective value is: -6.321204e-01
solution(sol)
##             u             v             w 
## -9.999999e-01  3.483107e-07  3.678791e-01

Power cone

\[ \begin{array} \mathcal{K}_{pwr}^\alpha &=& \{(x, y, z) | x^\alpha y^{1-\alpha} \geq |z|, x, y \geq 0\}, \text{ where } \alpha \in [0, 1] \\ \left(\mathcal{K}_{pwr}^\alpha\right)^* &=& \left\{(u, v, w) | \left(\frac{u}{a}\right)^\alpha \left(\frac{v}{1-a}\right)^{(1-a)} \geq |w|, u \geq 0, v \geq 0 \right\} \end{array} \]

Primal power cone

\[ \begin{array} \text{minimize} & x + y \\ \text{subject to} & \sqrt{x} * \sqrt{y} \geq z \\ & x, y \geq 0, z = 4 \end{array} \]

powp <- OP(objective = L_objective(c(1, 1, 0), names = c("x", "y", "z")), 
           constraints = C_constraint(diag(-1, 3), cones = K_powp(0.5), rhs = rep(0, 3)),
           bounds = V_bound(li = 3, ui = 3, lb = 4, ub = 4))
(sol <- ROI_solve(powp))
## Optimal solution found.
## The objective value is: 7.999993e+00
solution(sol)
##        x        y        z 
## 3.999996 3.999996 4.000000

Dual power cone

\[ \begin{array} \text{minimize} & u + v \\ \text{subject to} & \sqrt{2 u} * \sqrt{2 v} \geq 4 \\ & u, v \geq 0, z = 4 \end{array} \]

powd <- OP(objective = L_objective(c(1, 1, 0), names = c("x", "y", "z")), 
           constraints = C_constraint(diag(-1, 3), cones = K_powd(0.5), rhs = rep(0, 3)),
           bounds = V_bound(li = 3, ui = 3, lb = 4, ub = 4))
(sol <- ROI_solve(powd))
## Optimal solution found.
## The objective value is: 4.000001e+00
solution(sol)
##        x        y        z 
## 2.000001 2.000001 4.000000

Nonlinear Programming

The quadratic problem from above can also be solved by a general purpose solver.

(sol <- ROI_solve(qcqp, solver = "alabama", start = double(3)))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
##         x         y         z 
## 1.0606602 1.2086300 0.3535534

or equivalently

f <- function(x) {
    90 * x[1] + 110 * x[2] + 160 * x[3] - 1 / 2 * (x[1]^2 + x[2]^2 + x[3]^2)
}
g <- function(x) {
    c((x[1]^2 + x[2]^2 + 4 * x[3]),
      (x[2]^2 + x[3]^2 + x[1] + x[3]),
      (x[1]^2 + x[3]^2 + 2 * x[1] * x[3]))
}
nlp <- OP(F_objective(f, n=3), 
          F_constraint(g, dir = rep("<=", 3), rhs = c(4, 3, 2)),
          maximum = TRUE)
(sol <- ROI_solve(nlp, solver = "alabama", start = double(3)))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
## [1] 1.0606602 1.2086300 0.3535534

or equivalently

nlp <- OP(Q_objective(-diag(3), c(90, 110, 160), c("x", "y", "z")), 
          F_constraint(g, dir = rep("<=", 3), rhs = c(4, 3, 2)),
          maximum = TRUE)
(sol <- ROI_solve(nlp, solver = "alabama", start = double(3)))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
##         x         y         z 
## 1.0606602 1.2086300 0.3535534

or equivalently

nlp <- OP(F_objective(f, n=3), 
          Q_constraint(Q = list(rbind(c(2, 0, 0), c(0, 2, 0), c(0, 0, 0)),
                                rbind(c(0, 0, 0), c(0, 2, 0), c(0, 0, 2)),
                                rbind(c(2, 0, 2), c(0, 0, 0), c(2, 0, 2))),
                       L = rbind(c(0, 0, 4), c(1, 0, 1), c(0, 0, 0)),
                       dir = rep("<=", 3), rhs = c(4, 3, 2)),
          maximum = TRUE)
(sol <- ROI_solve(nlp, solver = "alabama", start = double(3)))
## Optimal solution found.
## The objective value is: 2.836219e+02
solution(sol)
## [1] 1.0606602 1.2086300 0.3535534

Read / Writing optimization problems

Optimization problems are commonly stored and shared in specialized plain text files. For LP and MIP the file formats 'mps', 'lp', 'sif' and 'freemps' are commonly used.

Read LP / MILP

ROI_registered_reader()
##         type  solver
## 1  mps_fixed    glpk
## 2   mps_free    glpk
## 3   lp_cplex    glpk
## 4   mathprog    glpk
## 5 lp_lpsolve lpsolve
## 6  mps_fixed lpsolve
## 7   mps_free lpsolve

To read the capri example from the netlib connection the following code can be used.

tmpfile <- tempfile()
con <- gzcon(url("http://www.zib.de/koch/perplex/data/netlib/mps/capri.mps.gz"))
writeLines(readLines(con), tmpfile)
close(con)
(capri <- ROI_read(tmpfile, type="mps_fixed", "lpsolve"))
## ROI Optimization Problem:
## 
## Minimize a linear objective function of length 353 with
## - 353 continuous objective variables,
## 
## subject to
## - 271 constraints of type linear.
## - 30 lower and 147 upper non-standard variable bounds.
(sol <- ROI_solve(capri))
## Optimal solution found.
## The objective value is: 2.690013e+03

Write LP / MILP

ROI_registered_writer()
##         type  solver
## 1  mps_fixed    glpk
## 2   mps_free    glpk
## 3   lp_cplex    glpk
## 4 lp_lpsolve lpsolve
## 5  mps_fixed lpsolve
## 6   mps_free lpsolve
tmpfile <- tempfile()
ROI_write(milp, tmpfile, type = "lp_lpsolve")
cat(readLines(tmpfile), sep="\n")
## /* Objective function */
## max: +7 C1 +C2 +3 C3;
## 
## /* Constraints */
## +6 C1 +4 C2 +5 C3 <= 60;
## +8 C1 +2 C3 <= 80;
## +9 C1 +C2 +7 C3 <= 70;
## 
## /* Integer definitions */
## int C1,C3;

Test collections

NETLIB-LP

The software repository NETLIB contains among many other software also a linear programming test collection.

library("ROI.models.netlib")
netlib()
##  [1] "adlittle" "afiro"    "agg"      "agg2"     "agg3"     "bandm"   
##  [7] "beaconfd" "blend"    "bnl1"     "bnl2"     "boeing1"  "boeing2" 
## [13] "bore3d"   "brandy"   "capri"    "cycle"    "czprob"   "d2q06c"  
## [19] "d6cube"   "degen2"   "degen3"   "dfl001"   "e226"     "etamacro"
## [25] "fffff800" "finnis"   "fit1d"    "fit1p"    "fit2d"    "fit2p"   
## [31] "forplan"  "ganges"   "gfrd.pnc" "greenbea" "greenbeb" "grow15"  
## [37] "grow22"   "grow7"    "israel"   "kb2"      "lotfi"    "maros.r7"
## [43] "maros"    "modszk1"  "nesm"     "perold"   "pilot.ja" "pilot"   
## [49] "pilot.we" "pilot4"   "pilot87"  "pilotnov" "recipe"   "sc105"   
## [55] "sc205"    "sc50a"    "sc50b"    "scagr25"  "scagr7"   "scfxm1"  
## [61] "scfxm2"   "scfxm3"   "scorpion" "scrs8"    "scsd1"    "scsd6"   
## [67] "scsd8"    "sctap1"   "sctap2"   "sctap3"   "seba"     "share1b" 
## [73] "share2b"  "shell"    "ship04l"  "ship04s"  "ship08l"  "ship08s" 
## [79] "ship12l"  "ship12s"  "sierra"   "stair"    "standata" "standmps"
## [85] "stocfor1" "stocfor2" "stocfor3" "truss"    "tuff"     "vtp.base"
## [91] "wood1p"   "woodw"    "x25fv47"  "x80bau3b"
problem_name <- "boeing1"
netlib("metainfo")[problem_name, -(2:5)]
##            name br optimal_value
## boeing1 BOEING1 BR     -335.2136
(model <- netlib(problem_name))
## ROI Optimization Problem:
## 
## Minimize a linear objective function of length 384 with
## - 384 continuous objective variables,
## 
## subject to
## - 440 constraints of type linear.
## - 6 lower and 156 upper non-standard variable bounds.
(x <- ROI_solve(model))
## Optimal solution found.
## The objective value is: -3.352136e+02

MILP

library("ROI.models.miplib")
miplib("air04")
## ROI Optimization Problem:
## 
## Minimize a linear objective function of length 8904 with
## - 8904 binary objective variables,
## 
## subject to
## - 823 constraints of type linear.
## - 0 lower and 8904 upper non-standard variable bounds.

Options