Read optimization model files into Julia

I would like to read into Julia some optimization models like the one given in the link below
http://qplib.zib.de/QPLIB_0067.html

This is a quadratic optimization problem. It looks like it has formats including gms, lp, mod, qblib. But they are written in a way with expressions like - 42 b2*b4 - 32 b2*b5, instead of in matrix forms. My questions are

  1. How to read this model to JuMP and solve it with Gurobi? Since the model file is very long, it is hard to create the model in JuMP by creating the variables and objective manually.

  2. Even if there is a way to give the model directly to JuMP, how do I read the files into Julia and convert it into the matrix vector form b'Qb + d'b? So in other words, I would like to create the quadratic coefficient matrix Q and the coefficient vector for the linear term d in Julia. For example, if the file has 3 b1*b1 + 2 b1*b2+ 4 b2*b2 + 5 b1 + b2, then what is the way to read the file in Julia and give me Q=[3 1; 1 4], d=[5; 1]?

Thanks.

  1. You can read an LP file.
using JuMP, Gurobi
model = read_from_file("model.lp")
set_optimizer(model, Gurobi.Optimizer)
optimize!(model)
  1. Not really. You’ll have to play with objective_function(model) and constraint_object.
1 Like

Thanks! The downloaded file is named QPLIB_0067.lp.txt. I tried your comment with both QPLIB_0067.lp.txt and QPLIB_0067.lp, but I always got the error read! is not implemented for LP files. What would be the reason for this? I’m using JuMP 0.21 with Julia 1.4.2.

Also, is there a way to delete the constraints in this model, and only keep the objective and the variables? Or construct a new model with the same variables and objective as the one I read in?

What would be the reason for this?

I was wrong. JuMP can write LPs, but not read them. (The perils of not testing an answer!)

If your only options are gms, lp, or mod, there’s no easy way forward. You’ll have to write the file interface yourself.

Edit: I’ve opened an issue: Implement read! for LP file format · Issue #1675 · jump-dev/MathOptInterface.jl · GitHub

1 Like

Thanks a lot! I will try to do it that way!

Just a note that if you do have access to GAMS for some reason, their CONVERT utility has quite a few target formats, including a JuMP scalar format.
(If there is once off need for a given file or just conversion of QPLib, I could probably help out.)

2 Likes

Thank you! You mean the conversion of .qplib file? I’m manually copying the matrices in the qplib file into Julia. Some files have too many lines (more than 10000) which is not easy to do. Are you aware of a faster way?

I just observed that from the QPLIB website that each instance comes as a .gms GAMS model format file, which can be converted with the GAMS convert tool to a JuMP scalar format.