4
$\begingroup$

As an R user, I'm trying to read a CPLEX LP model from file by using the read.lp function from package lpSolveAPI. Here's the command line (from within RStudio):

lprec <- read.lp(filename="P01_a.lp",type = "lp")

I get this message:

Error in read.lp(filename = "P01_a.lp", type = "lp") :
could not interpret P01_a.lp as an lp file.

Could you please help me? There seems to be no examples out there. I attach the LP file "P01_a.lp" in CPLEX format:

Minimize
  cost: 12q1 + 14q2 + 16q3 + 18q4 + 10r1 + 12r2 + 14r3 + 16r4 + 3s1 + 3s2 + 3s3 + 3s4
Subject To
  d1: q1 +r1 - s1 = 100
  d2: s1 + q2 + r2 - s2 = 200
  d3: s2 + q3 + r3 - s3 = 150
  d4: s3 + q4 + r4 - s4 = 400
  l1: q1 - 200b1 >= 0
  l2: q2 - 200b2 >= 0
  l3: q3 - 200b3 >= 0
  l4: q4 - 200b4 >= 0
  m1: r1 - 10000b1 <= 0
  m2: r2 - 10000b2 <= 0
  m3: r3 - 10000b3 <= 0
  m4: r4 - 10000b4 <= 0
Bounds
  0 <= q1 <= 200
  0 <= q2 <= 200
  0 <= q3 <= 200
  0 <= q4 <= 200
Binary
  b1
  b2
  b3
  b4
End

Here's my environment:

sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)

Matrix products: default

locale:
[1] LC_COLLATE=Italian_Italy.1252  LC_CTYPE=Italian_Italy.1252    LC_MONETARY=Italian_Italy.1252
[4] LC_NUMERIC=C                   LC_TIME=Italian_Italy.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lpSolveAPI_5.5.2.0-17.7

loaded via a namespace (and not attached):
[1] compiler_4.0.2  htmltools_0.5.0 tools_4.0.2     yaml_2.2.1      rmarkdown_2.3   knitr_1.29      
xfun_0.16      
 [8] digest_0.6.27   rlang_0.4.7     evaluate_0.14  
$\endgroup$

1 Answer 1

3
$\begingroup$

The first issue is that "LP" format means different things to lpsolve and CPLEX. See the warning about that near the top of the lpsolve page describing their format. There are converters available, but I don't know if there are any packaged for R. So you may need to install one and then convert the CPLEX .lp file to lpsolve format outside of R (or by making a system call from R).

A second issue is that lpsolve (or the lpsolveAPI package) is rather sensitive to white space. I tried copying a couple of examples from the lpsolve web pages, pasting them into text files, and then reading those text files into R. Something as trivial as an end-of-line character at the end of the last line of text (creating an empty final line) would trigger an error message. So good luck with that.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.