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, where CPLEX version 22.1 was installed in the standard Applications folder.

cplex_location <- "/Applications/CPLEX_Studio_Community221"
configure_args <- c(Rcplex = sprintf("--with-cplex-include='%s/cplex/include' --with-cplex-lib='-L%s/cplex/lib/x86-64_osx/static_pic -lilocplex -lcplex'", cplex_location, cplex_location))
install.packages("Rcplex", configure.args = configure_args)

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.2.1 (2022-06-23)
## Platform: x86_64-apple-darwin21.6.0 (64-bit)
## Running under: macOS Ventura 13.0
## 
## Matrix products: default
## BLAS:   /usr/local/Cellar/openblas/0.3.21/lib/libopenblasp-r0.3.21.dylib
## LAPACK: /usr/local/Cellar/r/4.2.1_4/lib/R/lib/libRlapack.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.3.4 magrittr_2.0.3   CVXR_1.0-11     
## 
## loaded via a namespace (and not attached):
##  [1] xfun_0.34         bslib_0.4.0       slam_0.1-50       lattice_0.20-45  
##  [5] Rmosek_10.0.25    colorspace_2.0-3  vctrs_0.5.0       htmltools_0.5.3  
##  [9] viridisLite_0.4.1 yaml_2.3.6        gmp_0.6-6         utf8_1.2.2       
## [13] rlang_1.0.6       jquerylib_0.1.4   pillar_1.8.1      glue_1.6.2       
## [17] Rmpfr_0.8-9       Rcplex_0.3-5      bit64_4.0.5       lifecycle_1.0.3  
## [21] stringr_1.4.1     munsell_0.5.0     blogdown_1.13     gurobi_9.5-2     
## [25] rvest_1.0.3       codetools_0.2-18  evaluate_0.17     knitr_1.40       
## [29] fastmap_1.1.0     cccp_0.2-9        fansi_1.0.3       highr_0.9        
## [33] Rcpp_1.0.9        scales_1.2.1      cachem_1.0.6      webshot_0.5.4    
## [37] jsonlite_1.8.3    systemfonts_1.0.4 bit_4.0.4         digest_0.6.30    
## [41] stringi_1.7.8     bookdown_0.29     Rglpk_0.6-4       grid_4.2.1       
## [45] cli_3.4.1         tools_4.2.1       sass_0.4.2        tibble_3.1.8     
## [49] pkgconfig_2.0.3   rcbc_0.1.0.9001   Matrix_1.5-1      xml2_1.3.3       
## [53] assertthat_0.2.1  rmarkdown_2.17    svglite_2.1.0     httr_1.4.4       
## [57] rstudioapi_0.14   R6_2.5.1          compiler_4.2.1

Source

R Markdown

References