Read LP files

Hello, I have a huge stochastic optimization model and JuMP is not fast enough to deal with it. I want to write the lp model in a file and then solve it.

Does JuMP have a method like read_LP(“file.lp”)? Or is there a better approach to my problem?

Thanks a lot

1 Like

Without looking at the docs: I’m guessing that JuMP has no such method, but the individual solver backends probably have it.

A quick search of the documentation doesn’t show a readLP function. JuMP is primarily a domain-specific language for defining an optimization problem. If you are already writing the relevant .lp file, it would probably be more efficient to feed this directly into the solver and then read the solution into Julia. I’ve gone full-circle before, specifying a linear program in JuMP, using writeLP to get the .lp file, then solving using CPLEX on a computer that didn’t have Julia installed, and then reading in the resulting .sol, which is just an XML file for postprocessing and visualization.

Try building your model without JuMP.

Use linprog() method

http://mathprogbasejl.readthedocs.io/en/latest/linprog.html?highlight=MathProgBase%20

The fowllowing should do the trick. Though there is no guarantee that it will be faster than creating the model in JuMP.

using CPLEX
import MathProgBase
const MPB=MathProgBase # shorthand for long module name
"This function takes an optional solver and loades a model from an LP file "
function loadLP(filename,solver=CplexSolver())
    model=buildlp([-1,0],[2 1],'<',1.5, solver) # create dummy model with correct solver
    MPB.loadproblem!(model,filename) # load what we actually want
    return model
end
lp = loadLP("file.lp")
MPB.optimize!(lp)

The correct way to generate an empty MPB model in this context is MPB.LinearQuadraticModel(solver).

Hi folks,

I’m trying to do the same thing of reading LP files. Thanks to your posts, I can read an LP file as a CplexMathProgModel. However, I would like to have a dictionary that maps the variables in the CplexMathProgModel to the variables in the LP file. I don’t think the variables in CplexMathProgModel have names. I wonder if you know some workaround that can get this done.

Thanks in advance.

Regards,
Can

Check out https://github.com/odow/LPWriter.jl. I haven’t tested on Julia 1.0 though. It might need some changes.

You can read and write MPS files using https://github.com/odow/MathOptFormat.jl, but you can only write LP files, not read. There’s an open issue to finish the LP migration https://github.com/odow/MathOptFormat.jl/issues/32

If you want to help, either updating LPWriter to Julia 1 or moving the LP reader to MathOptFormat would be a great contribution.

JuMP has a function to write your CPLEX or Gurobi model in lp or mps format (not limited to):
write_to_file(model, “filename.lp”)