Using Other Solvers

Introduction

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

CVXR can also make use of commercial solvers and other open-source solvers:

  • The commercial solver MOSEK
  • The commercial solver GUROBI
  • The commercial solver CPLEX
  • The open source linear and mixed integer programming package GLPK via the Rglpk package.
  • The CBC solver via the R package rcbc. This is not yet on CRAN but can be installed directly from github.

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

NOTE: MOSEK ,GUROBI, and CPLEX require licenses to use them but free academic licenses are available for all three.

Solver capabilities

Table 1 below shows the capabilities of various solvers. Once the appropriate packages are installed, a call to CVXR::installed_solvers() will indicate what solvers CVXR is aware of.

Table 1: Solver Capabilities
Solver R package LP QP SOCP SDP EXP MIP
CBC rcbc
GLPK Rglpk
GLPK_MI Rglpk
OSQP osqp
CPLEX Rcplex
ECOS ECOSolveR
ECOS_BB ECOSolveR
GUROBI gurobi
MOSEK Rmosek
SCS scs

Commercial Solvers

Pre-1.0 versions of CVXR used vendor python solver packages via reticulate, not R packages. Version 1.x directly uses native R packages that have now become available, resulting in a cleaner, more efficient interface.

Brief pointers on installation follow.

Installing MOSEK

MOSEK provides an academic version that is free of charge: one can obtain the free academic license after registering. Once the license for the product has been activates, the Rmosek documentation provides all the details for installation. A quick check to ensure things are working is to run the example:

library(Rmosek)
example(mosek)

Once everything is working, 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. After registering, install the Gurobi Optimizer software and activate your license as necessary. The Gurobi documentation provides details.

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

Installing Rcplex

CPLEX is available in a community edition. After installation, the Rcplex package needs to be told where to find the libraries for linking. A sample session on macOS is shown below for reference.

R CMD INSTALL Rcplex_0.3-3.tar.gz --configure-args="--with-cplex-include=/Applications/CPLEX_Studio_Community129/cplex/include --with-cplex-lib='-L/Applications/CPLEX_Studio_Community129/cplex/lib/x86-64_osx/static_pic -lilocplex -lcplex'"

Example session

CVXR::installed_solvers()
##  [1] "ECOS"    "ECOS_BB" "CBC"     "CPLEX"   "CVXOPT"  "GLPK_MI" "GLPK"   
##  [8] "SCS"     "GUROBI"  "MOSEK"   "OSQP"

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] kableExtra_1.1.0 magrittr_1.5     CVXR_1.0-9      
## 
## loaded via a namespace (and not attached):
##  [1] gmp_0.6-0         Rcpp_1.0.5        highr_0.8         compiler_4.0.2   
##  [5] pillar_1.4.6      tools_4.0.2       digest_0.6.25     bit_1.1-15.2     
##  [9] viridisLite_0.3.0 evaluate_0.14     tibble_3.0.3      lifecycle_0.2.0  
## [13] lattice_0.20-41   pkgconfig_2.0.3   rlang_0.4.7       Matrix_1.2-18    
## [17] gurobi_9.0.3.1    rstudioapi_0.11   Rglpk_0.6-4       yaml_2.2.1       
## [21] blogdown_0.19     xfun_0.15         cccp_0.2-4        xml2_1.3.2       
## [25] httr_1.4.2        Rmpfr_0.8-1       stringr_1.4.0     knitr_1.28       
## [29] vctrs_0.3.2       hms_0.5.3         webshot_0.5.2     bit64_0.9-7      
## [33] grid_4.0.2        glue_1.4.1        R6_2.4.1          rmarkdown_2.3    
## [37] bookdown_0.19     readr_1.3.1       codetools_0.2-16  rcbc_0.1.0.9001  
## [41] scales_1.1.1      htmltools_0.5.0   ellipsis_0.3.1    assertthat_0.2.1 
## [45] rvest_0.3.5       colorspace_1.4-1  Rcplex_0.3-3      stringi_1.4.6    
## [49] Rmosek_9.2.3      munsell_0.5.0     slam_0.1-47       crayon_1.3.4

Source

R Markdown

References