# 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.6.0 (2019-04-26)
## Platform: x86_64-apple-darwin18.5.0 (64-bit)
## Running under: macOS Mojave 10.14.5
##
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.6_1/lib/libopenblasp-r0.3.6.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-6
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.1 knitr_1.23 magrittr_1.5
## [4] bit_1.1-14 lattice_0.20-38 R6_2.4.0
## [7] stringr_1.4.0 tools_3.6.0 grid_3.6.0
## [10] xfun_0.7 R.oo_1.22.0 scs_1.2-3
## [13] htmltools_0.3.6 yaml_2.2.0 bit64_0.9-7
## [16] digest_0.6.19 bookdown_0.11 Matrix_1.2-17
## [19] gmp_0.5-13.5 ECOSolveR_0.5.2 R.utils_2.8.0
## [22] evaluate_0.14 rmarkdown_1.13 blogdown_0.12.1
## [25] stringi_1.4.3 compiler_3.6.0 Rmpfr_0.7-2
## [28] R.methodsS3_1.7.1 jsonlite_1.6 reticulate_1.12
```

## Source

## 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): 42–60. https://doi.org/10.1080/23307706.2017.1397554.