Using Other Solvers

Introduction

The default installation of CVXR comes with two (imported) open source solvers:

  • ECOS and its mixed integer cousin ECOS_BB via the CRAN package ECOSolveR
  • SCS via the CRAN package scs.

CVXR can also make use of several other open source solvers implemented in R packages.

  • The linear and mixed integer programming package lpSolve via the lpSolveAPI package
  • The linear and mixed integer programming package GLPK via the Rglpk package.

Since these are optional, you have to install these packages yourself.

lapply(list(LPSOLVE = "lpSolveAPI",
            GLPK = "Rglpk"),
       function(x) x %in% installed.packages()[, 1])
## $LPSOLVE
## [1] TRUE
## 
## $GLPK
## [1] TRUE

Once the packages are installed, a call to installed_solvers will indicate what solvers CVXR is aware of.

Commercial Solvers

A few commercial solvers are also currently supported: MOSEK and GUROBI.

At the moment, the support uses vendor python solver packages via reticulate, not R packages. Future versions will provide support directly using problem reductions, recently implemented in CVXPY version 1.0.

Thus, one needs two pre-requisites for using these commercial solvers:

  • a python installation in addition to R
  • the reticulate R package.

We also recommend that you ensure that reticulate is installed correctly and working. For example reticulate::py_eval('1+1') should return 2.

N.B. If you have an Anaconda installation in your path, you have to account for the fact that there may be interactions when using RStudio and rendering documents. In particular, Anaconda may include its own version of pandoc and other tools that may conflict with what Rstudio needs to do its work properly.

To be concrete, one problem we found was that the MOSEK solver was not recognized as being available in this rendered document, even though the command line interface showed it to be present. Ensuring an appropriate PATH variable solves the problem.

Installing MOSEK

MOSEK provides an academic version that is free of charge. As noted in the downloads page, Anaconda users can install merely via:

conda install -c mosek mosek

Others can use the pip command:

pip install -f https://download.mosek.com/stable/wheel/index.html Mosek

In addition, the license for the product has to be activated per instructions on the Sales section of the web page.

Once activated, you can check that CVXR recognizes the solver; installed_solvers() should list MOSEK. Otherwise, rinse and repeat until success.

Installing GUROBI

GUROBI also provides an academic version that is free of charge. They require you to register.

Once registered, install the Gurobi Optimizer software and activate your license as necessary.

Once activated, you can check that CVXR::installed_solvers() lists GUROBI. Otherwise, rinse and repeat until success.

Example session

installed_solvers()
## [1] "ECOS"    "ECOS_BB" "SCS"     "MOSEK"   "LPSOLVE" "GLPK"    "GUROBI"

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          lpSolveAPI_5.5.2.0-17 knitr_1.20           
##  [4] magrittr_1.5          bit_1.1-14            lattice_0.20-35      
##  [7] R6_2.3.0              stringr_1.3.1         tools_3.5.1          
## [10] grid_3.5.1            xfun_0.4              R.oo_1.22.0          
## [13] scs_1.1-1             htmltools_0.3.6       bit64_0.9-7          
## [16] yaml_2.2.0            rprojroot_1.3-2       digest_0.6.18        
## [19] bookdown_0.7          Matrix_1.2-15         gmp_0.5-13.2         
## [22] ECOSolveR_0.4         Rglpk_0.6-3           R.utils_2.7.0        
## [25] slam_0.1-43           evaluate_0.12         rmarkdown_1.10       
## [28] blogdown_0.9.2        stringi_1.2.4         compiler_3.5.1       
## [31] Rmpfr_0.7-1           backports_1.1.2       R.methodsS3_1.7.1    
## [34] jsonlite_1.5          reticulate_1.10

Source

R Markdown

References