Solver Interfaces in CVXR

by Anqi Fu and Balasubramanian Narasimhan

Introduction

In our previous blog post, 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 ECOSolveR
  • SCS via the CRAN package scs.

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 0.4.11, 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:

Installing MOSEK/GUROBI

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 https://download.mosek.com/stable/wheel/index.html 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.

Share Comments · ·

You may leave a comment below or discuss the post in the forum community.rstudio.com.