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

Question:

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?

Asked By: hamta

||

Answers:

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.

Answered By: gmavrom

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.

Answered By: Richard

I encountered the same issue and I double-checked my modeling code to make sure it’s linear or in the form of MILP. But this error keeps bothering me. Neither my code did have some nonlinear terms nor pyomo has something wrong unsolved.

Answered By: Betristor
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.