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.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin19.5.0 (64-bit)
## Running under: macOS Catalina 10.15.7
##
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.10_1/lib/libopenblasp-r0.3.10.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-9
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.5 knitr_1.28 magrittr_1.5 bit_1.1-15.2
## [5] lattice_0.20-41 R6_2.4.1 rlang_0.4.7 stringr_1.4.0
## [9] tools_4.0.2 grid_4.0.2 xfun_0.15 htmltools_0.5.0
## [13] yaml_2.2.1 bit64_0.9-7 digest_0.6.25 assertthat_0.2.1
## [17] bookdown_0.19 cccp_0.2-4 Matrix_1.2-18 gmp_0.6-0
## [21] ECOSolveR_0.5.3 Rglpk_0.6-4 codetools_0.2-16 slam_0.1-47
## [25] evaluate_0.14 rmarkdown_2.3 blogdown_0.19 Rcplex_0.3-3
## [29] gurobi_9.0.3.1 stringi_1.4.6 compiler_4.0.2 Rmpfr_0.8-1
## [33] Rmosek_9.2.3 rcbc_0.1.0.9001