hamta
hamta

Reputation: 75

RuntimeError: Cannot write legal LP file. Objective 'Maximum_profit' has nonlinear terms that are not quadratic

I use pyomo and gurobi for solving a nonlinear optimization problem. but when I run my code, I get this error:

RuntimeError: Cannot write legal LP file.  Objective 'Maximum_profit' has nonlinear terms that are not quadratic.

(I don't have any problem when I use gurobi as a solver in a linear optimization problem.) My objective function is:

 Maximum_profit=pyo.Objective(doc="Profit Maximization", rule=lambda model: sum(pyo.log10(1+sum(pyo.log10(1.0 + model.t[i,k]) for i in model.N)) for k in model.J) - sum(sum(model.t[i,k] * model.p[i,k] for k in model.J) for i in model.N),sense=-1)

how can I fix it?

Upvotes: 1

Views: 3584

Answers (2)

Richard
Richard

Reputation: 276

Disclaimer: I work for Gurobi.

The problem here is pyomo, since Gurobi is able to solve non-convex mixed-integer quadratically constrained quadratic programming problems. In particular, the issue arises in the file cpxlp.py, which originally handled only the writing the CPLEX LP file, but now also handles the LP files for Gurobi. There, in line 500-650 you can see all the restrictions that apply, and that is where the exception is thrown.

I will post a github issue (if one does not already exist) so as to hopefully clarify this.

Upvotes: 4

gmavrom
gmavrom

Reputation: 440

Gurobi cannot solve nonlinear optimization models (except for some instances of quadratic models). With log terms in your objective you need a solver that can handle them, such as BARON or IPOPT.

Upvotes: 0

Related Questions