# 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 ## Testthat Results: No output is good 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
## Testthat Results: No output is good

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.4.1 (2024-06-14)
## Platform: x86_64-apple-darwin20
## Running under: macOS Sonoma 14.5
##
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/Los_Angeles
## tzcode source: internal
##
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base
##
## other attached packages:
## [1] CVXR_1.0-15      testthat_3.2.1.1 here_1.0.1
##
## loaded via a namespace (and not attached):
##  [1] gmp_0.7-4         utf8_1.2.4        sass_0.4.9        clarabel_0.9.0
##  [5] slam_0.1-50       blogdown_1.19     lattice_0.22-6    digest_0.6.36
##  [9] magrittr_2.0.3    evaluate_0.24.0   grid_4.4.1        bookdown_0.40
## [13] pkgload_1.4.0     fastmap_1.2.0     rprojroot_2.0.4   jsonlite_1.8.8
## [17] Matrix_1.7-0      ECOSolveR_0.5.5   brio_1.1.5        fansi_1.0.6
## [21] Rmosek_10.2.0     codetools_0.2-20  jquerylib_0.1.4   cli_3.6.3
## [25] Rmpfr_0.9-5       rlang_1.1.4       Rglpk_0.6-5.1     bit64_4.0.5
## [29] cachem_1.1.0      yaml_2.3.9        tools_4.4.1       Rcplex_0.3-6
## [33] rcbc_0.1.0.9001   gurobi_11.0-0     assertthat_0.2.1  vctrs_0.6.5
## [37] R6_2.5.1          lifecycle_1.0.4   bit_4.0.5         desc_1.4.3
## [41] cccp_0.3-1        bslib_0.7.0       pillar_1.9.0      glue_1.7.0
## [45] Rcpp_1.0.12       xfun_0.45         knitr_1.48        htmltools_0.5.8.1
## [49] rmarkdown_2.27    compiler_4.4.1

R Markdown