Using Other Solvers

Introduction

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

  • Clarabel, a versatile solver written in Rust.
  • ECOS and its mixed integer cousin ECOS_BB. At some point, this solver will no longer be the default since the underlying C library for this solver is no longer actively maintained.
  • OSQP
  • SCS

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
CLARABEL clarabel
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" 
##  [7] "GLPK"     "SCS"      "GUROBI"   "MOSEK"    "CLARABEL" "OSQP"

Session Info

sessionInfo()
## R version 4.4.2 (2024-10-31)
## Platform: x86_64-apple-darwin20
## Running under: macOS Sequoia 15.1
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/Los_Angeles
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices datasets  utils     methods   base     
## 
## other attached packages:
## [1] kableExtra_1.4.0 magrittr_2.0.3   CVXR_1.0-15     
## 
## loaded via a namespace (and not attached):
##  [1] gmp_0.7-5         clarabel_0.9.0.1  sass_0.4.9        utf8_1.2.4       
##  [5] xml2_1.3.6        slam_0.1-54       blogdown_1.19     stringi_1.8.4    
##  [9] lattice_0.22-6    digest_0.6.37     evaluate_1.0.1    grid_4.4.2       
## [13] bookdown_0.41     fastmap_1.2.0     jsonlite_1.8.9    Matrix_1.7-1     
## [17] Rmosek_10.2.0     fansi_1.0.6       viridisLite_0.4.2 scales_1.3.0     
## [21] codetools_0.2-20  jquerylib_0.1.4   cli_3.6.3         Rmpfr_0.9-5      
## [25] rlang_1.1.4       Rglpk_0.6-5.1     bit64_4.5.2       munsell_0.5.1    
## [29] cachem_1.1.0      yaml_2.3.10       tools_4.4.2       Rcplex_0.3-6     
## [33] rcbc_0.1.0.9001   colorspace_2.1-1  gurobi_11.0-0     assertthat_0.2.1 
## [37] vctrs_0.6.5       R6_2.5.1          lifecycle_1.0.4   stringr_1.5.1    
## [41] bit_4.5.0         cccp_0.3-1        pkgconfig_2.0.3   bslib_0.8.0      
## [45] pillar_1.9.0      glue_1.8.0        Rcpp_1.0.13-1     systemfonts_1.1.0
## [49] xfun_0.49         tibble_3.2.1      highr_0.11        rstudioapi_0.17.1
## [53] knitr_1.48        htmltools_0.5.8.1 rmarkdown_2.29    svglite_2.1.3    
## [57] compiler_4.4.2

Source

R Markdown

References