# 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.1 (2018-07-02)
## Platform: x86_64-apple-darwin17.7.0 (64-bit)
## Running under: macOS 10.14.1
##
## Matrix products: default
## BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.3/lib/libopenblasp-r0.3.3.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-2
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.19 knitr_1.20 magrittr_1.5
## [4] bit_1.1-14 lattice_0.20-35 R6_2.3.0
## [7] stringr_1.3.1 tools_3.5.1 grid_3.5.1
## [10] xfun_0.4 R.oo_1.22.0 scs_1.1-1
## [13] htmltools_0.3.6 bit64_0.9-7 yaml_2.2.0
## [16] rprojroot_1.3-2 digest_0.6.18 bookdown_0.7
## [19] Matrix_1.2-15 gmp_0.5-13.2 ECOSolveR_0.4
## [22] R.utils_2.7.0 evaluate_0.12 rmarkdown_1.10
## [25] blogdown_0.9.2 stringi_1.2.4 compiler_3.5.1
## [28] Rmpfr_0.7-1 backports_1.1.2 R.methodsS3_1.7.1
## [31] jsonlite_1.5 reticulate_1.10
```

## 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). Taylor & Francis: 42–60. doi:10.1080/23307706.2017.1397554.