Help with a code (calculating an area)
AnsweredHello everyone,
I'm rather new to gurobi, and I've been having some issues with what seems to be an easy code. Here it comes:
from gurobipy import *
import gurobipy as gp
from gurobipy import GRB
exemplo = Model('exemplo')
x = exemplo.addVar(lb = 0, ub=100,vtype = GRB.CONTINUOUS, name = 'x')
y = exemplo.addVar(lb= 0, ub=100, vtype =GRB.CONTINUOUS, name = 'y')
exemplo.setObjective(x*y, GRB.MAXIMIZE)
exemplo.addConstr(2*x+y<=100)
exemplo.addConstr(x+y>=0)
exemplo.update()
exemplo.optimize()
#after this point, this error keeps showing up
Gurobi Optimizer version 9.5.0 build v9.5.0rc5 (mac64[rosetta2])
Thread count: 8 physical cores, 8 logical processors, using up to 8 threads Optimize a model with 2 rows, 2 columns and 4 nonzeros
Model fingerprint: 0x0948f3a5
Model has 1 quadratic objective term
Coefficient statistics:
Matrix range [1e+00, 2e+00]
Objective range [0e+00, 0e+00]
QObjective range [2e+00, 2e+00]
Bounds range [1e+02, 1e+02]
RHS range [1e+02, 1e+02]
Presolve removed 1 rows and 0 columns
GurobiError
Traceback (most recent call last) <ipython-input-77-5f80b56325d4> in <module> ----> 1 exemplo.optimize()
src/gurobipy/model.pxi in gurobipy.Model.optimize()
GurobiError: Objective Q not PSD (diagonal adjustment of 1.0e+00 would be required). Set NonConvex parameter to 2 to solve model.
What could be the possible reason?
Regards,
Tullio
0
-
Hi Tullio,
Your objective is given by the bilinear term \(x\cdot y\) which is nonconvex. Gurobi will attempt to solve a nonconvex (MIQC)QP only if you set the parameter NonConvex=2. This is what the error message is referring to, i.e., in order to solve your model, you have to set the parameter NonConvex=2.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment