Solver Peculiarities

The default solver in CVXR used to be 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, solver = "ECOS")

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.

Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin21.6.0 (64-bit)
## Running under: macOS Ventura 13.0
## 
## Matrix products: default
## BLAS:   /usr/local/Cellar/openblas/0.3.21/lib/libopenblasp-r0.3.21.dylib
## LAPACK: /usr/local/Cellar/r/4.2.1_4/lib/R/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_1.0-11
## 
## loaded via a namespace (and not attached):
##  [1] gmp_0.6-6        Rcpp_1.0.9       bslib_0.4.0      compiler_4.2.1  
##  [5] jquerylib_0.1.4  tools_4.2.1      digest_0.6.30    bit_4.0.4       
##  [9] jsonlite_1.8.3   evaluate_0.17    lattice_0.20-45  rlang_1.0.6     
## [13] Matrix_1.5-1     gurobi_9.5-2     cli_3.4.1        Rglpk_0.6-4     
## [17] yaml_2.3.6       blogdown_1.13    xfun_0.34        cccp_0.2-9      
## [21] fastmap_1.1.0    ECOSolveR_0.5.4  Rmpfr_0.8-9      stringr_1.4.1   
## [25] knitr_1.40       sass_0.4.2       bit64_4.0.5      grid_4.2.1      
## [29] R6_2.5.1         rmarkdown_2.17   bookdown_0.29    magrittr_2.0.3  
## [33] rcbc_0.1.0.9001  codetools_0.2-18 htmltools_0.5.3  assertthat_0.2.1
## [37] Rcplex_0.3-5     stringi_1.7.8    Rmosek_10.0.25   cachem_1.0.6    
## [41] slam_0.1-50

Source

R Markdown

References