This repository contains a Dockerfile to create a Docker image for solving linear programming optimization problems in R. The Docker image is available via Docker Hub.
Containers created based on this image will have R, R Studio, the Hadleyverse of R packages, and a suite of linear programming solvers. This image includes all the open source linear programming solvers, and their R package interfaces, listed in CRAN Task View for Optimization:
- lp_solve with R packages lpSolve and lpSolveAPI.
- COIN-OR Symphony with R packages Rsymphony, from CRAN, and lpsymphony, from Bioconductor.
- COIN-OR Clp with R package clpAPI.
- The GNU Linear Programming Kit with R packages glpkAPI and Rglpk.
- Gurobi and it's corresponding R package. This is the only commercial solver in the list and, if you intend on using it, you'll need to provide a license file. Further details below.
If you're on Mac or Windows, this will the Docker Quickstart Terminal, which is a Linux virtual machine that Docker runs in. Open this application or, if you're on Linux, just open a normal Terminal.
To start a container based on the
optimizr image use:
docker run -dp 8787:8787 mstrimas/optimizr
Now point your browser to the IP address given by
docker-machine ip, being sure to append this address with
:8787. For example, if
docker-machine ip returns
192.168.99.100, point your browser to
192.168.99.100:8787. To log in to RStudio use
rstudio for the username and password. You're now using RStudio running in the Docker container, which gives you access to all the linear programming solvers listed above.
Gurobi is an extremely powerful commercial solver for linear and quadratic programming. It is significantly faster than existing open source solvers, however, you'll need a license to use it. Fortunately, Gurobi does offer free academic licenses for those eligible. Note that a Gurobi license is only good for a single machine and therefore you'll need a new one for every Docker container you create. So, if you do go to the trouble of setting up Gurobi on a Docker container, you'll probably want to keep that container around to avoid having to get a new license.
This command needs to be run in the container to install the license. After you've started an
optimizr container, get its container ID using
docker ps, then run the
grbgetkey command with:
docker exec <container id> grbgetkey 19b2902a-XXXX-XXXX-XXXX-XXXXXXXXXXXX
You should now be able to use the
gurobi R package in the Docker container.