Solver Peculiarities

The default solver in CVXR is ECOS. However, it is not always the best solver to use. As an example, let us consider again the catenary problem.

We will change the problem slightly to use a finer discretization from 101 points to say 501.

## Problem data
m <- 501
L <- 2
h <- L / (m - 1)

## Form objective
x <- Variable(m)
y <- Variable(m)
objective <- Minimize(sum(y))

## Form constraints
constraints <- list(x[1] == 0, y[1] == 1,
                    x[m] == 1, y[m] == 1,
                    diff(x)^2 + diff(y)^2 <= h^2)

## Solve the catenary problem
prob <- Problem(objective, constraints)
result <- solve(prob)

The solution status is no longer optimal.

cat("Solution status is", result$status)
## Solution status is optimal_inaccurate

In such cases, using a different solver may give more accurate results. Let us try MOSEK for example.

result <- solve(prob, solver = "MOSEK")
cat("Solution status is", result$status)
## Solution status is optimal

This returns an optimal solution.

Here again, even commercial solvers differ; GUROBI, for example, does not completely solve the problem and in fact throws an error.

Further Development

Future versions of CVXR will improve support for the commercial solvers by taking advantage of problem reductions described in Agrawal et al. (2018) to hand the problem to solvers in a form that is closer to what the R packages (for those solvers) expect. This should provide better behavior and error reporting.

Session Info

sessionInfo()
## R version 3.5.0 (2018-04-23)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS High Sierra 10.13.4
## 
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] CVXR_0.99
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.17      knitr_1.20        magrittr_1.5     
##  [4] bit_1.1-13        lattice_0.20-35   R6_2.2.2         
##  [7] stringr_1.3.1     tools_3.5.0       grid_3.5.0       
## [10] xfun_0.1          R.oo_1.22.0       scs_1.1-1        
## [13] htmltools_0.3.6   bit64_0.9-7       yaml_2.1.19      
## [16] rprojroot_1.3-2   digest_0.6.15     bookdown_0.7     
## [19] Matrix_1.2-14     gmp_0.5-13.1      ECOSolveR_0.4    
## [22] R.utils_2.6.0     evaluate_0.10.1   rmarkdown_1.9.14 
## [25] blogdown_0.6.3    stringi_1.2.2     compiler_3.5.0   
## [28] Rmpfr_0.7-0       backports_1.1.2   R.methodsS3_1.7.1
## [31] jsonlite_1.5      reticulate_1.7.1

Source

R Markdown

References

Agrawal, Akshay, Robin Verschueren, Steven Diamond, and Stephen Boyd. 2018. “A Rewriting System for Convex Optimization Problems.” Journal of Control and Decision 5 (1). Taylor & Francis: 42–60. https://doi.org/10.1080/23307706.2017.1397554.