7
$\begingroup$

We have a large-scale optimization problem (~10K vars and ~10K constraints) in the form of LP format file (generated using Cplex library).

We wanted to solve that problem file using Cvxpy (with Gurobi solver - Note: Cvxpy is unavoidable), which doesn't accepts LP format file directly (rather constraint matrices/list).

So, is it possible to somehow read (/transform/parse) that LP format file into regular Numpy matrices?

$\endgroup$
13
  • 1
    $\begingroup$ Careful. 1) cvxpy is a modelling tool (with tons of overhead due to it's powerful concepts) and if you already have a LP modelled, it's questionable what cvxpy would offer here. It's basically a slow wrapper then (potentially destroying your problem in some more complex QP/PSD cases -> internal eigenvalue-checks). 2) Numpy only knows dense arrays. Most real-world LP-instances would not fit into your memory when stored densely. scipy.sparse is what you are interested in (cvxpy supports both). 3) The task itself is 99% LP-format parsing, so focus on finding an accessible parser (in python). $\endgroup$
    – sascha
    Feb 28 at 20:15
  • 1
    $\begingroup$ That Cvxpy should do transformations a presolve in good a commercial optimizer does not do sound right. $\endgroup$ Mar 1 at 9:19
  • 1
    $\begingroup$ I agree with @ErlingMOSEK. To answer the question though, I would write a parser using the original CPLEX model rather than the LP format, because that will be a lot of work. $\endgroup$
    – Richard
    Mar 1 at 9:53
  • 1
    $\begingroup$ The purpose of the Cvxpy transformations is to setup the data on the form that optimizer needs. Not to improve the formulation IMO. I think even the Cvxpy authors would be surprised by your statement/observation. $\endgroup$ Mar 1 at 10:22
  • 2
    $\begingroup$ There is this thing called performance variability in MIP (google it). For instance if CVXPY permutes the variables and or constraints you may see a big change in solution time. It is a random effect though. $\endgroup$ Mar 1 at 10:58

1 Answer 1

7
$\begingroup$

As has been discussed in the comments already, your suggested workflow is more complicated than it needs to be without providing any advantages. Gurobi is perfectly capable of handling LP files and if you want to solve the problem with Gurobi anyway there is no reasonable benefit of routing everything through cvxpy.

If you absolutely have to get the constraint matrix, then I still suggest using Gurobi:

import gurobipy as gp

m = gp.read("model.lp")
A = m.getA()

As was already mentioned, this matrix is stored as a sparse matrix (see Gurobi documentation on Model.getA() for more details) which is vastly superior to numpy's dense storage for practically any model.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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