NonConvex is set to 2, but gurobi still cannot solve non-PSD quadratic constraints
AnsweredHi, I'm using Gurobi 9.1.1 with python. I have already set NonConvex to 2, but I still get an error due to non-PSD. Here are the code and log. Thanks.
m = gp.Model()Here is the log:
m.params.NonConvex = 2
m.setParam('NonConvex', 2)
c1 = m.addVar(vtype=GRB.CONTINUOUS, name=f"c1")
c2 = m.addVar(vtype=GRB.CONTINUOUS, name=f"c2")
f1 = m.addVar(vtype=GRB.CONTINUOUS, name=f"f1")
f2 = m.addVar(vtype=GRB.CONTINUOUS, name=f"f2")
m.addConstr(c1 >=0)
m.addConstr(c2 >=0)
m.addConstr(f1 >=0)
m.addConstr(f2 >=0)
m.addConstr(f1 <= 69)
m.addConstr(f2 <= 100)
m.addConstr(c1 + c2 <=25165824)
m.addConstr(f1*(1-c1/1363148) + f2*(1-c2/20971520) <= 100)
m.setObjective(f1+f2, GRB.MAXIMIZE)
m.optimize()
Changed value of parameter NonConvex to 2
Prev: -1 Min: -1 Max: 2 Default: -1
Parameter NonConvex unchanged
Value: 2 Min: -1 Max: 2 Default: -1
Gurobi Optimizer version 9.1.1 build v9.1.1rc0 (linux64)
Thread count: 24 physical cores, 24 logical processors, using up to 24 threads
Optimize a model with 7 rows, 4 columns and 8 nonzeros
Model fingerprint: 0x2cf33d7d
Model has 1 quadratic constraint
Coefficient statistics:
Matrix range [1e+00, 1e+00]
QMatrix range [5e-08, 7e-07]
QLMatrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [0e+00, 0e+00]
RHS range [7e+01, 3e+07]
QRHS range [1e+02, 1e+02]
Presolve removed 6 rows and 0 columns
Continuous model is non-convex -- solving as a MIP.
Found heuristic solution: objective -0.0000000
Warning: diagonal adjustment of 1.3e-13 performed to make Q PSD
Presolve removed 6 rows and 0 columns
Presolve time: 0.00s
Presolved: 1 rows, 4 columns, 2 nonzeros
Presolved model has 1 quadratic constraint(s)
Variable types: 4 continuous, 0 integer (0 binary)
Explored 0 nodes (0 simplex iterations) in 0.00 seconds
Thread count was 1 (of 24 available processors)
Solution count 0
Solve interrupted (error code 10020)
Best objective -, best bound -, gap -
Traceback (most recent call last):
File "main.py", line 506, in <module>
reactive_perf = gurobi_policy(jobs, total_cache, total_bw)
File "main.py", line 100, in gurobi_policy
m.optimize()
File "src/gurobipy/model.pxi", line 847, in gurobipy.Model.optimize
gurobipy.GurobiError: Q matrix is not positive semi-definite (PSD). Set NonConvex parameter to 2 to solve model.
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Han,
This seems as if there is a second model generated that also needs to set the \(\texttt{NonConvex=2}\) parameter. Please check your code for additional models. The first one is clearly accepting the parameter and starts solving the model, while the error appears to be coming from another \(\tt{optimize()}\) call.
Cheers,
Matthias0 -
Hi Han,
My first analysis was incorrect. I can actually reproduce the error with the code you provided. We will handle this issue internally.
Thank you for the bug report!
Matthias0 -
After reviewing with Han and our developers, we found that Han's quadratic constraint in the model is nonconvex, but very close to a convex one. The Gurobi Developers will look into how to improve the handling of this situation in the future.
As a workaround, settingPSDTol = 0
resolves the issue. By setting the positive semi-definite tolerance to zero, Gurobi will effectively force the sole quadratic constraint to be treated as a nonconvex one.
Thanks again to Han for bringing this to our attention.0 -
m = gp.Model()
#m.params.NonConvex = 2
m.setParam('NonConvex', 2)
c1 = m.addVar(vtype=GRB.CONTINUOUS, name=f"c1")
c2 = m.addVar(vtype=GRB.CONTINUOUS, name=f"c2")
f1 = m.addVar(vtype=GRB.CONTINUOUS, name=f"f1")
f2 = m.addVar(vtype=GRB.CONTINUOUS, name=f"f2")
b1 = m.addVar(vtype=GRB.CONTINUOUS, lb=-GRB.INFINITY, name="b1")
b2 = m.addVar(vtype=GRB.CONTINUOUS, lb=-GRB.INFINITY, name="b2")
m.addConstr(c1 >=0)
m.addConstr(c2 >=0)
m.addConstr(f1 >=0)
m.addConstr(f2 >=0)
m.addConstr(f1 <= 69)
m.addConstr(f2 <= 100)
m.addConstr(c1 + c2 <=25165824)
m.addConstr(f1*b1 + f2*b2 <= 100) #
m.addConstr(b1==1-c1/1363148) #
m.addConstr(b2==1-c2/20971520) #
m.setObjective(f1+f2, GRB.MAXIMIZE)
m.optimize()0 -
Dear Yoshihiro,
I don't understand what you trying to tell us with your last message. Could you please elaborate?
Thanks,
Matthias0 -
Gurobi can not recognize the expression of f1*(1-c1/1363148) + f2*(1-c2/20971520) <= 100 as a second-order constraint. In such a case, by introducing variables b1 and b2, it should be the expression of f1*b1 + f2*b2 <= 100 shown above. To say more, the following transformation;
m.addConstr(f1*b1 + f2*b2 <= 100*1363148*20971520)
m.addConstr(b1==1363148-c1)
m.addConstr(b2==20971520-c2)is more preferable, and as a result m.setParam('NonConvex', 2) does not have to be used.
0 -
The recently released Gurobi 9.1.2 handles this issue a bit better and displays a more appropriate error message. Thanks for reporting this problem, Han.
0
Post is closed for comments.
Comments
8 comments