Using CPLEX in R: Installing cplexAPI in Windows 10

January 26, 2017
By

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

I have a very large mixed integer problem to solve.   COIN‘s solver accessed through Rsymphony did a decent job, but had trouble finding feasible solutions.  I had been told that the IBM cplex  solver was the best on the market for mixed integer programming.

Installing cplex is a relatively easy task.  The difficulties began when I tried to install a link from R.  Either cplexAPI or Rcplex.  You can search and see that there is very little helpful information in the usual places.  I reached out to the developers and Jonathan of cplexAPI responded with very helpful troubleshooting and instructions.

We (honestly, all Jonathan) determined that the following sequence should correctly install cplexAPI.  First, read the directions.

After downloading, unpack the .tar.gz file someplace.  I am going to unpack mine on the desktop.

Open the newly created folder cplexAPI and you will find a directory labeled src.  Open the Makevars.win file within that folder.  I have Notepad++ installed, so I right click Makevars.win and open withNotepad++.  The instructions note that you will need to find each of these directories and type them in.  They may (and probably will if you are using any other version).

PKG_CPPFLAGS=-g -D_R_=1 -DUSE_R=1 -I"C:/Program Files/IBM/ILOG/CPLEX_Studio127/cplex/include"
PKG_LIBS=-L"C:/Program Files/IBM/ILOG/CPLEX_Studio127/cplex/bin/x64_win64" -lm -lcplex1270

After saving you will need to repackage cplexAPI.  Head over to the command line (remember I unpacked my tar.gz file on my desktop) and use the command:

R CMD build --no-build-vignettes --no-manual  --md5     C:\Users\{your name here}\Desktop\cplexAPI

This will repackage the folder, avoiding the md5 error you can find while searching for solutions.  After a successful repackage you can then install the package at the command line.

R CMD INSTALL --build --no-multiarch .\cplexAPI_1.3.3.tar.gz

At this point, you may have errors.  The key you are looking for is this output:

packaged installation of 'cplexAPI' as cplexAPI_1.3.3.zip
DONE (cplexAPI)

Now try it out.  Here is an example from Gabriel Gelius-Dietrich’s cplexAPI – Quick Start.

> library(cplexAPI)

env prob chgProbNameCPLEX(env, prob, "sample")
[1] 0
nc nr obj rhs sense lb ub cn rn beg cnt ind val copyLpwNamesCPLEX(env, prob, nc, nr, CPX_MAX, obj, rhs, sense,
+ beg, cnt, ind, val, lb, ub, NULL, cn, rn)
[1] 0
lpoptCPLEX(env, prob)
[1] 0
solutionCPLEX(env, prob)
$lpstat
[1] 1
$objval
[1] 13
$x
[1] 2 0 1
$pi
[1] 1 0 1
$slack
[1] 0 1 0
$dj
[1] 0 -3 0

I am looking forward to using cplexAPI for a larger problem!

For more R posts visit:http://www.R-bloggers.com

http://www.R-bloggers.com

To leave a comment for the author, please follow the link and comment on their blog: R – Jason unedited.

R-bloggers.com 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


Sponsors

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)