ROI_solve: Solve an Optimization Problem

Description Usage Arguments Value Author(s) Examples

View source: R/roi.R

Description

Solve a given optimization problem. This function uses the given solver (or searches for an appropriate solver) to solve the supplied optimization problem.

Usage

1
ROI_solve(x, solver, control = list(), ...)

Arguments

x

an optimization problem of class "OP".

solver

a character vector specifying the solver to use. If missing, then the default solver returned by ROI_options is used.

control

a list with additional control parameters for the solver. This is solver specific so please consult the corresponding documentation.

...

a list of control parameters (overruling those specified in control).

Value

a list containing the solution and a message from the solver.

Author(s)

Stefan Theussl

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Rosenbrock Banana Function
## -----------------------------------------
## objective
f <- function(x) {
   return( 100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2 )
}
## gradient
g <- function(x) {
   return( c( -400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
             200 * (x[2] - x[1] * x[1])) )
}
## bounds
b <- V_bound(li = 1:2, ui = 1:2, lb = c(-3, -3), ub = c(3, 3))
op <- OP( objective = F_objective(f, n = 2L, G = g),
          bounds = b )
res <- ROI_solve( op, solver = "nlminb", control = list(start = c( -1.2, 1 )) )
solution( res )
## Portfolio optimization - minimum variance
## -----------------------------------------
## get monthly returns of 30 US stocks
data( US30 )
r <- na.omit( US30 )
## objective function to minimize
obj <- Q_objective( 2*cov(r) )
## full investment constraint
full_invest <- L_constraint( rep(1, ncol(US30)), "==", 1 )
## create optimization problem / long-only
op <- OP( objective = obj, constraints = full_invest )
## solve the problem - only works if a QP solver is registered
## Not run: 
res <- ROI_solve( op )
res
sol <- solution( res )
names( sol ) <- colnames( US30 )
round( sol[ which(sol > 1/10^6) ], 3 )

## End(Not run)

Example output

ROI.plugin.qpoases: R Optimization Infrastructure
Registered solver plugins: nlminb, clp, glpk, qpoases.
Default solver: auto.
[1] 1 1
Optimal solution found.
The objective value is: 9.326635e-04
  IBM   MCD   MRK    PG     T    VZ   WMT   XOM 
0.165 0.301 0.005 0.138 0.031 0.091 0.169 0.101 

ROI documentation built on Aug. 29, 2020, 3:01 p.m.

Related to ROI_solve in ROI...