lpsolveAPI in RStudio

linear-programming, r

Solution

Write it out to a file for examination

When I work with LPs using `lpSolveAPI`, I prefer to write them out to a file. The `lp` format works fine for my needs. I then examine the LP model using any text editor. If you click on the output file in the "Files" panel in RStudio, it will open it too, and you can inspect it.

 write.lp(lprec, "lpfilename.lp", "lp") #write it to a file in LP format

You can also write it out as `MPS` format if you so choose.

Here's the help file on `write.lp()`.

Hope that helps.

Problem

I am using the lpsolveAPI in RStudio. When I type the name of a model with few decision variables, I can read a printout of the current constraints in the model. For example ``` > lprec Model name: COLONE COLTWO COLTHREE COLFOUR Minimize 1 3 6.24 0.1 THISROW 0 78.26 0 2.9 >= 92.3 THATROW 0.24 0 11.31 0 <= 14.8 LASTROW 12.68 0 0.08 0.9 >= 4 Type Real Real Real Real Upper Inf Inf Inf 48.98 Lower 28.6 0 0 18 ``` But when I make a model that has more than 9 decision variables, it no longer gives the full summary and I instead see: ``` > lprec Model name: a linear program with 13 decision variables and 258 constraints ``` Does anyone know how I can see the same detailed summary of the model when there are large numbers of decision variables? Bonus Question: Is RStudio the best console for working with R? Here is an example: ``` >lprec <- make.lp(0,5) ``` This makes a new model called lprec, with 0 constraints and 5 variables. Even if you call the name now you get: ``` >lprec Model name: C1 C2 C3 C4 C5 Minimize 0 0 0 0 0 Kind Std Std Std Std Std Type Real Real Real Real Real Upper Inf Inf Inf Inf Inf Lower 0 0 0 0 0 ``` The C columns correspond to the 5 variables. Right now there are no constraints and the objective function is 0. You can add a constraint with ``` >add.constraint(lprec, c(1,3,4,2,-8), "<=", 0) ``` This is the constraint C1 + 3*C2 + 4*C3 + 2*C4 - 8*C5 <= 0. Now the print out is: ``` Model name: C1 C2 C3 C4 C5 Minimize 0 0 0 0 0 R1 1 3 4 2 -8 <= 0 Kind Std Std Std Std Std Type Real Real Real Real Real Upper Inf Inf Inf Inf Inf Lower 0 0 0 0 0 ``` Anyway the point is that no matter how many constraints, if there are more than 9 variables then I don't get the full print out. ``` >lprec <- make.lp(0,15) >lprec Model name: a linear program with 15 decision variables and 0 constraints ```

Original source