Skip to main content

NonConvex is set to 2, but gurobi still cannot solve non-PSD quadratic constraints

Answered

Comments

8 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff Gurobi Staff
    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?.
  • Matthias Miltenberger
    • Gurobi Staff Gurobi Staff

    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,
    Matthias

    0
  • Matthias Miltenberger
    • Gurobi Staff Gurobi Staff

    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!
    Matthias

    0
  • Alison Cozad
    • Gurobi Staff Gurobi Staff
    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, setting PSDTol = 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
  • Yoshihiro MURAKAMI
    • Gurobi-versary
    • First Comment
    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
  • Matthias Miltenberger
    • Gurobi Staff Gurobi Staff

    Dear Yoshihiro,

    I don't understand what you trying to tell us with your last message. Could you please elaborate?

    Thanks,
    Matthias

    0
  • Yoshihiro MURAKAMI
    • Gurobi-versary
    • First Comment

    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
  • Eli Towle
    • Gurobi Staff Gurobi Staff

    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.