Solver Interfaces in CVXR

July 8, 2018

(This article was first published on R Views, and kindly contributed to R-bloggers)


In our previous blog
, we
introduced CVXR, an R package for disciplined convex
optimization. The package allows one to describe an optimization
problem with Disciplined Convex Programming
rules using high level mathematical syntax. Passing this problem
definition along (with a list of constraints, if any) to the solve
function transforms it into a form that can be handed off to
a solver. The default installation of CVXR comes with two (imported)
open source solvers:

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

CVXR (version 0.99) 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.

About Solvers

The real work of finding a solution is done by solvers, and writing
good solvers is hard work. Furthermore, some solvers work particularly
well for certain types of problems (linear programs, quadratic
programs, etc.). Not surprisingly, there are commercial vendors who
have solvers that are designed for performance and scale. Two
well-known solvers are MOSEK and
GUROBI. R packages for these solvers are
also provided, but they require the problem data to be constructed in
a specific form. This necessitates a bit of work in the current version of
CVXR and is certainly something we plan to include in future versions.
However, it is also true that these commercial solvers expose a much
richer API to Python programmers than to R programmers. How, then, do we
interface such solvers with R as quickly as possible, at least
in the short term?

Reticulate to the Rescue

The current version of CVXR exploits the
reticulate package
for commercial solvers such as MOSEK and GUROBI. We took the Python solver interfaces in CVXPY version
, edited them
suitably to make them self-contained, and hooked them up to reticulate.

This means that one needs two prerequisites to use these commercial solvers in the current version of CVXR:


Both MOSEK and
GUROBI provide academic versions
(registration required) free of charge. For example,
Anaconda users can install MOSEK with the command:

conda install -c mosek mosek

Others can use the pip command:

pip install -f Mosek

GUROBI is handled in a similar fashion. The solvers must be activated using a
license provided by the vendor.

Once activated, one can check that CVXR recognizes the solver;
installed_solvers() should list them.

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

Further information

More information on these solvers, along with a number of tutorial examples are
available on the CVXR site. If you are
attending useR! 2018, you can catch
Anqi’s CVXR talk on Friday, July 13.

To leave a comment for the author, please follow the link and comment on their blog: R Views. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)