Skip to main content

Why is my quadratic expression not convex?

Answered

Comments

14 comments

  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Daniele,

    This seminar might answer some of your questions:

    Non-Convex Quadratic Optimization - Gurobi

    In general, nonconvex constraints usually make a problem much harder to solve - this is not guaranteed, though, and you should always check how the solver handles a certain model instance.

    Cheers,
    Matthias

    1
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Daniele,

    Maybe I am missing something here, but if you are trying to solve a model that contains a nonconvex constraint, you need to set the Nonconvex parameter to 2. What makes you think that this is not appropriate?

    Cheers,
    Matthias

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Thanks for your answer Matthias.
    My explanation wasn't the best... I'll try yo make it simpler so that it's clearer and easier for me to explain:

    1. I have a quadratic expression made of only non-negative rational coefficients (so 0 is included), hence it is a convex function (is it?)
    2. I am using this expression as objective function; the model is solved flawlessly (if the o.f. isn't convex guroby tells me about it and asks for NonConvex parameter to be set to 2, right?)
    3. I am later using another objective function (linear) for the same model
    4. I am using the quadratic expression from point 1., for a quadratic equality constraint
    5. I get guroby saying that the quadratic constraint isn't convex
    6. I adjust the PSD tolerance to 0
    7. guroby still says that the quadratic constraint isn't convex

    At this point my question is: (if gurobi would have warned the user in the opposite case) why was the quadratic function convex when used as o.f. but it is later identified as non-convex? Is it convex? Is it not?
    What I didn't specify is that I am using python.

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Thank you, Daniele,

    The issue here is with the quadratic constraints being formulated as equality. This is always nonconvex.

    Best regards,
    Matthias

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Thanks for your reply Matthias.
    At this point I am a bit confused: I am running the algorithm I've implemented (from which the piece of code I posted is taken) with different datasets. All the attempts involve the solution of a problem having a quadratic equality constraint; by the way, I am not always getting the "nonconvex" error from gurobi. I've noticed that it happens only when I have some very little coefficients in the quadratic expression and a certain number of variables (for example it happens when I run the algorithm over a 25 variables model, but not with a 10 one). That's why I thought the issue could be related to the PSD tolerance and that's the reason that led me to test the code with the PSDTol parameter set to 0 (without success).
    The algorithm implies some reworking of the data: only 4 decimal digits of each coefficient are taken and, after this approximation, each coefficient is multiplied by 10^3. As mentioned before, I've encountered the "nonconvex" problem only when having coefficients to the tune of 10^(-5) and when solving a 25 variables model (I run the algorithm over models with 5, 10 and 25 variables).
    I really hope this is useful for some further understanding.
    Thanks again for your time.

    Daniele

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Additional information: when using an inequality constraint, I am not getting the "nonconvex" error but the non-positive-semidefinite one, that follows

    gurobipy.GurobiError: Q matrix is not positive semi-definite (PSD). Set NonConvex parameter to 2 to solve model.

    even if the PSD tolerance parameter is set to 0.

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Daniele,

    Do you mind sharing your model so we can have a better understanding of what might be going on here? It may happen that your constraints can be reformulated in presolving to avoid the nonconvexity issue.

    If the Q matrix is not PSD (and this is not just some very minor non-PSDness) then adjusting the PSDTol is not going to make a difference.

    Cheers,
    Matthias

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Hi Matthias,

    one thing I forgot to say: the model has only integer variables.
    The algorithm I've implemented is made of more than 1 python script. I'll try to do my best posting below the significant pieces of code.

    Wrapper script, calling different functions:

    # number of floating point digits taken into account
    digits = ".0001"
    # multiplicative factor
    mult_fac = "1000"

    # data is red by certain files in certain folders
    # mean
    c = np.loadtxt("mean_" + FOLDER + "_n" + NUMBER + ".txt")
    # constraints
    A = np.loadtxt("a_" + FOLDER + "_n" + NUMBER + ".txt")
    # covariance matrix
    Q = np.loadtxt("cov_" + FOLDER + "_n" + NUMBER + ".txt")

    # we need this to be negative
    c = -c

    # c_q, Q_q and A_q are created here

    # data reworking
    for i in range(len(c)):
    c_q[i] = Decimal(mult_fac) * (Decimal(c[i]).quantize(Decimal(digits)))
    A_q[i] = Decimal(A[i]).quantize(Decimal(digits))

    for j in range(len(c)):
    Q_q[i, j] = Decimal(mult_fac) * (Decimal(Q[i, j]).quantize(Decimal(digits)))

    num_var = len(c)
    num_constr = 1
    rows = num_constr
    cols = num_var
    sense = [GRB.LESS_EQUAL] * num_var
    rhs = [10 * np.sum(A)]
    lb = [0] * num_var
    ub = [GRB.INFINITY] * num_var
    vtype = [GRB.INTEGER] * num_var

    # generating the gurobi model
    model, vars_s, lin, lin_sym, quad, quad_sym = \
    model_generator_star(rows, cols, c_q, Q_q, A_q, sense, rhs, lb, ub, vtype)

    epsilon, y_id_i1, y_i1, y_i1_sym = \
    lambd(c, Q, model, vars_s, lin, lin_sym, quad, quad_sym, digits, mult_fac, FILENAME, 0)

    # goes on but the problem occurs in the "lambd" function


    Function which creates an instance of the gurobi model


    def model_generator_star(rows, cols, c, Q, A, sense, rhs, lb, ub, vtype):

    model = gp.Model()

    # Gurobi variables
    vars_g = []

    # sympy variables
    vars_s = []

    # definng variables (gurobi and symbolic)
    for j in range(cols):
    vars_g.append(model.addVar(lb = lb[j], ub = ub[j], vtype = vtype[j], name = "x" + str(j + 1)))
    vars_s.append(Symbol("x" + str(j + 1)))

    # defining the only linear constraint
    expr = gp.LinExpr()
    for j in range(cols):
    expr += A[j]*vars_g[j]
    model.addLConstr(expr, sense[0], rhs[0])

    # quadratic component of he o. f. (gurobi and symboic)
    quad = gp.QuadExpr()
    quad_sym = 0

    for i in range(cols):
    for j in range(cols):
    if Q[i][j] != 0:
    quad += Q[i][j]*vars_g[i]*vars_g[j]
    quad_sym += Q[i][j]*vars_s[i]*vars_s[j]

    # linear component of the o. f.(gurobi and symboic)
    lin = gp.LinExpr()
    lin_sym = 0

    for j in range(cols):
    if c[j] != 0:
    lin += c[j]*vars_g[j]
    lin_sym += c[j]*vars_s[j]

    return model, vars_s, lin, lin_sym, quad, quad_sym

     

    Function in which the problem occurs:

    def lambd(c, Q, model, sym_vars, lin, lin_sym, quad, quad_sym,\
    DIGITS, MULT_FAC, FILENAME, choice = 0):

    # choosing the permutation {i1, i2}
    # !!! in this case we choose "choice = 0"
    if choice == 0:
    y_i1 = lin
    y_i1_sym = lin_sym
    y_i2 = quad
    elif choice == 1:
    y_i1 = quad
    y_i1_sym = quad_sym
    y_i2 = lin

    ############# x cap
    # optimizing y_i2
    model.setObjective(y_i2, GRB.MINIMIZE)
    model.optimize() ###

    # adding constraint: y_i2 must be equal to its optimum value
    y_i2_id = model.ObjVal
    if choice == 0:
    model.addQConstr(y_i2 == y_i2_id, name = "first")
    elif choice == 1:
    model.addLConstr(y_i2 == y_i2_id, name = "first")

    # finding the lex. solution by optimizing y_i1 with the new constraint
    model.setObjective(y_i1, GRB.MINIMIZE)
    model.optimize() ###

    # get variables value at the lex. solution
    if model.status == GRB.OPTIMAL:
    x_cap = model.getAttr(GRB.Attr.X, model.getVars())
    else:
    raise ValueError("Mmm... C'è qualquadra che non cosa\n")

    # removing the added constraint for recycliing the model
    if choice == 0:
    model.remove(model.getQConstrs()[-1])
    elif choice == 1:
    model.remove(model.getConstrs()[-1])

    ############# x line
    # optimizing y_i1
    model.setObjective(y_i1, GRB.MINIMIZE)
    model.optimize() ###

    # adding constraint: y_i1 must be equal to its optimum value
    y_i1_id = model.ObjVal
    if choice == 0:
    model.addLConstr(y_i1 == y_i1_id, name = "second")
    elif choice == 1:
    model.addQConstr(y_i1 == y_i1_id, name = "second")


    # finding the lex. solution by optimizing y_i2 with the new constraint
    model.setObjective(quad, GRB.MINIMIZE)
    model.optimize() ###

    # get variables value at the lex. solution
    if model.status == GRB.OPTIMAL:
    x_line = model.getAttr(GRB.Attr.X, model.getVars())
    else:
    raise ValueError("Mmm... C'è qualquadra che non cosa\n")

    # removing the added constraint for recycliing the model
    if choice == 0:
    model.remove(model.getConstrs()[-1])
    elif choice == 1:
    model.remove(model.getQConstrs()[-1])

    # goes on but the problem occurs above


    It follows one of the Q matrixes giving the problem:

     

    8.183518770305490270e-03 2.297365666522668218e-03 2.834869211770885394e-03 3.448364922738532054e-03 1.524895470308772899e-03 1.259279441586560805e-03 3.916504118835039371e-03 1.812342619474992776e-03 4.261601188608944712e-03 3.337707625892217481e-03 5.197285458943386388e-04 3.985203821602604189e-03 3.966875606112349462e-03 3.946954130262378922e-03 1.981797238519999744e-03 2.430652804265091317e-03 3.340419247538666068e-03 2.315352310723218978e-03 4.255939471385788292e-03 3.657394831090152437e-03 1.815302182074037462e-03 2.859098122105526232e-03 3.005214552267041535e-03 3.327639184208631713e-03 4.432160272815478634e-03
    2.297365666522668218e-03 3.605745713328692165e-03 1.579539257214147363e-03 1.905474886032905999e-03 1.551503191625135114e-03 9.277837302281550201e-04 1.740421309932530837e-03 1.279942871206428455e-03 1.510676732133104652e-03 4.459362824098448796e-04 2.865246673558643868e-04 2.344086294971239708e-03 2.156068519668383979e-03 1.998782826267762273e-03 1.209468020711617969e-03 1.400485668480815982e-03 1.908156368236996712e-03 1.247801119804743588e-03 2.267440573775253345e-03 1.942217465442079398e-03 1.033150170372880558e-03 2.410364638688832634e-03 2.220470525133016928e-03 1.416920896887645213e-03 2.348783713287319521e-03
    2.834869211770885394e-03 1.579539257214147363e-03 7.239535269883899150e-03 2.480088782952216166e-03 1.654763685466621899e-03 9.261195516831389378e-04 2.054228907799679569e-03 1.658023397670166333e-03 4.852077964507480606e-03 -1.438544955635962170e-04 8.801527608168022848e-04 3.717598104306782305e-03 3.281728107574348116e-03 2.605219599722515336e-03 1.634548095070292558e-03 2.063339510181302558e-03 2.495029604049811642e-03 1.317769511193337328e-03 4.295731697735197425e-03 3.116140575162981794e-03 9.070186316162302332e-04 1.594163279202065985e-03 2.992402340776277331e-03 1.613046642016633357e-03 3.375568657675624262e-03
    3.448364922738532054e-03 1.905474886032905999e-03 2.480088782952216166e-03 4.226515823649083965e-03 1.695933992524550340e-03 9.767023635254060403e-04 2.920065164960743750e-03 1.866476738124951294e-03 3.287403784886695074e-03 1.826979901064389178e-03 2.411333486996756982e-04 3.162024342513527781e-03 3.302480353691441151e-03 3.336090496234135703e-03 1.744497708042673989e-03 2.354388412656911473e-03 3.523550518682201649e-03 1.425764548232013760e-03 3.445870459251399245e-03 2.777441816338213024e-03 1.452288241553629025e-03 1.475470410979717699e-03 2.602070601602235207e-03 2.445207345012177704e-03 3.615086828902234605e-03
    1.524895470308772899e-03 1.551503191625135114e-03 1.654763685466621899e-03 1.695933992524550340e-03 3.603409864536454271e-03 1.156500740221985029e-03 1.568327652083019311e-03 1.876232770973321673e-03 1.711121936995317616e-03 -8.843278314514507038e-05 8.961713430522319892e-04 1.910561673757856004e-03 2.130715856828735606e-03 1.623973730693543992e-03 9.842884968486930938e-04 1.266261066825570330e-03 1.830451761977406602e-03 9.750115638116579712e-04 2.046927204121419454e-03 1.101126333769868529e-03 1.315830065318598441e-03 1.059861710978575759e-03 1.665936974177800733e-03 1.301552848817857455e-03 2.151820587102729315e-03
    1.259279441586560805e-03 9.277837302281550201e-04 9.261195516831389378e-04 9.767023635254060403e-04 1.156500740221985029e-03 2.189775210054166910e-03 1.127079464661659642e-03 1.482881042857063514e-03 1.418952096397672847e-03 1.235893123280300742e-03 5.395254569928968754e-04 1.714192927537804825e-03 1.401286233455856060e-03 1.158058839923301270e-03 1.058666653723559651e-03 1.227264115883330104e-03 1.147095189799985726e-03 8.535050724452788963e-04 1.098938171917760885e-03 1.105640763580663941e-03 1.123099040742471045e-03 1.001023384892498272e-03 1.169071192648993155e-03 8.076474793669686332e-04 1.651134111805354319e-03
    3.916504118835039371e-03 1.740421309932530837e-03 2.054228907799679569e-03 2.920065164960743750e-03 1.568327652083019311e-03 1.127079464661659642e-03 5.025597177330362771e-03 2.782742730224426007e-03 3.320446212087365800e-03 3.495870269047735360e-03 -3.612119299298511356e-05 3.457435204465295845e-03 3.114292097039385917e-03 2.941100615352985458e-03 1.808714409591146268e-03 1.934082203981915505e-03 3.038143212968136709e-03 1.392504070130226200e-03 3.347535991932929032e-03 2.820627070407118100e-03 1.506739936742092743e-03 2.006292091247909633e-03 2.544602208648853812e-03 2.568269737381929582e-03 3.442910437752849575e-03
    1.812342619474992776e-03 1.279942871206428455e-03 1.658023397670166333e-03 1.866476738124951294e-03 1.876232770973321673e-03 1.482881042857063514e-03 2.782742730224426007e-03 9.477323931415372951e-03 1.339561667871555549e-03 9.005886057847765263e-04 9.860754215598344519e-04 2.952461366018991132e-03 2.802266674364729728e-03 1.847623775837391137e-03 1.666753992147926083e-03 1.912258397335470095e-03 2.141838894371167912e-03 1.222105887693835345e-03 2.514563940796460308e-03 1.334599603925609723e-03 2.120220844865310875e-03 2.470381053455439953e-03 1.607080960078010679e-03 1.248947361532743230e-03 1.972987168242520007e-03
    4.261601188608944712e-03 1.510676732133104652e-03 4.852077964507480606e-03 3.287403784886695074e-03 1.711121936995317616e-03 1.418952096397672847e-03 3.320446212087365800e-03 1.339561667871555549e-03 1.282247709081596292e-02 4.356577625809109761e-03 1.288201909195511733e-03 4.826091892534945492e-03 3.693043055531176899e-03 3.446537047400571267e-03 2.335399020716930497e-03 3.112767688145677818e-03 2.954106668701415167e-03 1.854971466634236206e-03 4.684488967564176022e-03 4.701904233557926277e-03 1.306947836279931949e-03 1.497709349037556516e-03 4.002859321238383221e-03 2.313437529751975578e-03 4.003116845972843132e-03
    3.337707625892217481e-03 4.459362824098448796e-04 -1.438544955635962170e-04 1.826979901064389178e-03 -8.843278314514507038e-05 1.235893123280300742e-03 3.495870269047735360e-03 9.005886057847765263e-04 4.356577625809109761e-03 9.181709767663497057e-02 -1.637419121598945307e-03 1.240631226689023090e-03 2.791136599249803476e-03 2.781882905048414095e-03 1.613285180864818891e-03 1.770139193727297659e-03 2.903555674057832926e-03 1.234535454087629623e-03 1.019810184683838218e-03 4.031874616082992743e-04 -8.752500102501011665e-04 3.953023648043715432e-04 2.249720357647124131e-04 1.342816698760200675e-03 2.868768607810693108e-03
    5.197285458943386388e-04 2.865246673558643868e-04 8.801527608168022848e-04 2.411333486996756982e-04 8.961713430522319892e-04 5.395254569928968754e-04 -3.612119299298511356e-05 9.860754215598344519e-04 1.288201909195511733e-03 -1.637419121598945307e-03 4.371015113461122065e-02 1.435866731379197058e-03 4.603521055800930892e-04 1.193389841850708497e-03 3.282839190578784269e-04 5.721692111477763229e-04 7.476920063761309564e-04 9.932598188812096114e-04 1.055855599423752246e-03 8.035520919595076292e-04 1.723935625009731043e-03 3.342180397933259601e-05 8.799114998732532897e-04 -1.968577161462686537e-03 1.593666900279860519e-03
    3.985203821602604189e-03 2.344086294971239708e-03 3.717598104306782305e-03 3.162024342513527781e-03 1.910561673757856004e-03 1.714192927537804825e-03 3.457435204465295845e-03 2.952461366018991132e-03 4.826091892534945492e-03 1.240631226689023090e-03 1.435866731379197058e-03 8.285489678876540101e-03 4.132555265496893129e-03 3.108516126143896080e-03 2.326171825335489329e-03 2.681508144658071094e-03 2.873676869624379807e-03 2.132841596040406171e-03 4.291385104859768429e-03 4.551292782038834916e-03 2.281402902281054208e-03 2.176245410403336144e-03 3.275875603113908349e-03 1.756781734256971641e-03 4.766890026109149754e-03
    3.966875606112349462e-03 2.156068519668383979e-03 3.281728107574348116e-03 3.302480353691441151e-03 2.130715856828735606e-03 1.401286233455856060e-03 3.114292097039385917e-03 2.802266674364729728e-03 3.693043055531176899e-03 2.791136599249803476e-03 4.603521055800930892e-04 4.132555265496893129e-03 6.438362298699444076e-03 3.642088999236394505e-03 2.242614821411409790e-03 2.474476012393473159e-03 3.529880463139959974e-03 2.161231159881791836e-03 4.827179270675078723e-03 3.037561647558351379e-03 1.883626626804303780e-03 1.824007998535089785e-03 2.849644455143485102e-03 2.536911765691617082e-03 4.650204607276404306e-03
    3.946954130262378922e-03 1.998782826267762273e-03 2.605219599722515336e-03 3.336090496234135703e-03 1.623973730693543992e-03 1.158058839923301270e-03 2.941100615352985458e-03 1.847623775837391137e-03 3.446537047400571267e-03 2.781882905048414095e-03 1.193389841850708497e-03 3.108516126143896080e-03 3.642088999236394505e-03 4.881581792036613666e-03 1.945528317048744868e-03 2.068601716832707549e-03 2.959355851191454011e-03 1.856394689917944098e-03 3.664764991884160786e-03 2.446968358202243361e-03 1.519968379056712464e-03 1.785395782941072819e-03 2.563466779914471902e-03 3.165203757722427017e-03 4.253178997679809246e-03
    1.981797238519999744e-03 1.209468020711617969e-03 1.634548095070292558e-03 1.744497708042673989e-03 9.842884968486930938e-04 1.058666653723559651e-03 1.808714409591146268e-03 1.666753992147926083e-03 2.335399020716930497e-03 1.613285180864818891e-03 3.282839190578784269e-04 2.326171825335489329e-03 2.242614821411409790e-03 1.945528317048744868e-03 3.416444797877222009e-03 1.619680186957819313e-03 1.735506311120619226e-03 1.117105257340516482e-03 2.805936694377429447e-03 1.694799444980286214e-03 1.100704746132358464e-03 -8.915371535429784337e-05 1.911216041929473218e-03 1.458542017832874455e-03 2.361097400100625309e-03
    2.430652804265091317e-03 1.400485668480815982e-03 2.063339510181302558e-03 2.354388412656911473e-03 1.266261066825570330e-03 1.227264115883330104e-03 1.934082203981915505e-03 1.912258397335470095e-03 3.112767688145677818e-03 1.770139193727297659e-03 5.721692111477763229e-04 2.681508144658071094e-03 2.474476012393473159e-03 2.068601716832707549e-03 1.619680186957819313e-03 3.800335939246881397e-03 2.316986437545601792e-03 1.496627833230707244e-03 2.745294020630159159e-03 2.644951483073497422e-03 1.193420144176224502e-03 1.355871071568670290e-03 2.046029035280692420e-03 1.448661688451464416e-03 2.699698871507372287e-03
    3.340419247538666068e-03 1.908156368236996712e-03 2.495029604049811642e-03 3.523550518682201649e-03 1.830451761977406602e-03 1.147095189799985726e-03 3.038143212968136709e-03 2.141838894371167912e-03 2.954106668701415167e-03 2.903555674057832926e-03 7.476920063761309564e-04 2.873676869624379807e-03 3.529880463139959974e-03 2.959355851191454011e-03 1.735506311120619226e-03 2.316986437545601792e-03 6.393129987123358747e-03 1.814031533968907739e-03 3.794955984716745240e-03 2.526924141683992500e-03 1.495031912184736347e-03 1.991171355698409876e-03 2.547682139840644604e-03 2.135381381073856496e-03 3.486306018755716812e-03
    2.315352310723218978e-03 1.247801119804743588e-03 1.317769511193337328e-03 1.425764548232013760e-03 9.750115638116579712e-04 8.535050724452788963e-04 1.392504070130226200e-03 1.222105887693835345e-03 1.854971466634236206e-03 1.234535454087629623e-03 9.932598188812096114e-04 2.132841596040406171e-03 2.161231159881791836e-03 1.856394689917944098e-03 1.117105257340516482e-03 1.496627833230707244e-03 1.814031533968907739e-03 4.307101303627714796e-03 2.491580262963362640e-03 2.140493839886429325e-03 1.347726473887804260e-03 1.131743325427621858e-03 1.246370151976768309e-03 1.126885380333231051e-03 2.233304191650051489e-03
    4.255939471385788292e-03 2.267440573775253345e-03 4.295731697735197425e-03 3.445870459251399245e-03 2.046927204121419454e-03 1.098938171917760885e-03 3.347535991932929032e-03 2.514563940796460308e-03 4.684488967564176022e-03 1.019810184683838218e-03 1.055855599423752246e-03 4.291385104859768429e-03 4.827179270675078723e-03 3.664764991884160786e-03 2.805936694377429447e-03 2.745294020630159159e-03 3.794955984716745240e-03 2.491580262963362640e-03 1.004980158553998686e-02 2.919251152789937697e-03 1.929740781124311168e-03 1.852590668409269435e-03 3.620299497001286480e-03 2.410199274815167172e-03 4.746367289751878341e-03
    3.657394831090152437e-03 1.942217465442079398e-03 3.116140575162981794e-03 2.777441816338213024e-03 1.101126333769868529e-03 1.105640763580663941e-03 2.820627070407118100e-03 1.334599603925609723e-03 4.701904233557926277e-03 4.031874616082992743e-04 8.035520919595076292e-04 4.551292782038834916e-03 3.037561647558351379e-03 2.446968358202243361e-03 1.694799444980286214e-03 2.644951483073497422e-03 2.526924141683992500e-03 2.140493839886429325e-03 2.919251152789937697e-03 1.166368658423207368e-02 1.199776898285764403e-03 1.835812013977507770e-03 3.430810018321211585e-03 1.208307397979586613e-03 3.355166908997606057e-03
    1.815302182074037462e-03 1.033150170372880558e-03 9.070186316162302332e-04 1.452288241553629025e-03 1.315830065318598441e-03 1.123099040742471045e-03 1.506739936742092743e-03 2.120220844865310875e-03 1.306947836279931949e-03 -8.752500102501011665e-04 1.723935625009731043e-03 2.281402902281054208e-03 1.883626626804303780e-03 1.519968379056712464e-03 1.100704746132358464e-03 1.193420144176224502e-03 1.495031912184736347e-03 1.347726473887804260e-03 1.929740781124311168e-03 1.199776898285764403e-03 3.108282089170134790e-03 1.178141745913269473e-03 1.460239964755815495e-03 1.109619396700610135e-03 2.095257305979588997e-03
    2.859098122105526232e-03 2.410364638688832634e-03 1.594163279202065985e-03 1.475470410979717699e-03 1.059861710978575759e-03 1.001023384892498272e-03 2.006292091247909633e-03 2.470381053455439953e-03 1.497709349037556516e-03 3.953023648043715432e-04 3.342180397933259601e-05 2.176245410403336144e-03 1.824007998535089785e-03 1.785395782941072819e-03 -8.915371535429784337e-05 1.355871071568670290e-03 1.991171355698409876e-03 1.131743325427621858e-03 1.852590668409269435e-03 1.835812013977507770e-03 1.178141745913269473e-03 1.492214655857134788e-02 1.586838419783477214e-03 2.059185499214491628e-03 2.473788681164188191e-03
    3.005214552267041535e-03 2.220470525133016928e-03 2.992402340776277331e-03 2.602070601602235207e-03 1.665936974177800733e-03 1.169071192648993155e-03 2.544602208648853812e-03 1.607080960078010679e-03 4.002859321238383221e-03 2.249720357647124131e-04 8.799114998732532897e-04 3.275875603113908349e-03 2.849644455143485102e-03 2.563466779914471902e-03 1.911216041929473218e-03 2.046029035280692420e-03 2.547682139840644604e-03 1.246370151976768309e-03 3.620299497001286480e-03 3.430810018321211585e-03 1.460239964755815495e-03 1.586838419783477214e-03 4.674259359658456715e-03 2.034748472013195308e-03 2.838599206244461857e-03
    3.327639184208631713e-03 1.416920896887645213e-03 1.613046642016633357e-03 2.445207345012177704e-03 1.301552848817857455e-03 8.076474793669686332e-04 2.568269737381929582e-03 1.248947361532743230e-03 2.313437529751975578e-03 1.342816698760200675e-03 -1.968577161462686537e-03 1.756781734256971641e-03 2.536911765691617082e-03 3.165203757722427017e-03 1.458542017832874455e-03 1.448661688451464416e-03 2.135381381073856496e-03 1.126885380333231051e-03 2.410199274815167172e-03 1.208307397979586613e-03 1.109619396700610135e-03 2.059185499214491628e-03 2.034748472013195308e-03 5.330989011258720905e-03 3.475908228508777214e-03
    4.432160272815478634e-03 2.348783713287319521e-03 3.375568657675624262e-03 3.615086828902234605e-03 2.151820587102729315e-03 1.651134111805354319e-03 3.442910437752849575e-03 1.972987168242520007e-03 4.003116845972843132e-03 2.868768607810693108e-03 1.593666900279860519e-03 4.766890026109149754e-03 4.650204607276404306e-03 4.253178997679809246e-03 2.361097400100625309e-03 2.699698871507372287e-03 3.486306018755716812e-03 2.233304191650051489e-03 4.746367289751878341e-03 3.355166908997606057e-03 2.095257305979588997e-03 2.473788681164188191e-03 2.838599206244461857e-03 3.475908228508777214e-03 8.611740537407937268e-03
    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Thank you for posting the code, Daniele. It's not going to help much, though, because this is not reproducible. Could you please try posting a minimal reproducible code example or the mathematical formulation of the constraint in question?

    Thanks,
    Matthias

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    What do you mean by "reproducible" here?
    At this point I think I will ask for permission for posting here all the4 needed files, but I don't know how to do it actually. The constraint is just a quadratic expression: given Q the coefficients matrix and x the variable vector (column vector), the constraint is x^TQx = constant.

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Stackoverflow provides a nice summary of how to write a good question:

    How to create a Minimal, Reproducible Example

    Please understand that you need to provide us with the necessary information to help you. Simply pasting your entire code and requiring us or other community members to work through it is not the way to go. Please try making your code as concise as possible.

    In any case, I still don't understand why setting the Nonconvex parameter to 2 is not an option.

    Cheers,
    Matthias

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Thanks for your answer Matthias.
    I am not really used to ask for help on communities so I apology for any inconvenient that I am causing. I understood how it should be done now. I'll see if it is the case to create a minimal, reproducible example and post it here. I thought it was being requested to just look at the code or to execute it as a whole, but I now got that it is not the case.

    About the NonConvex parameter: it was very strange to get those nonconvexity errors because I didn't experience nothing like that with other instances (just different data and number of variables) of the very same model and because I am pretty sure that the matrix I am getting the quadratic expression from is PSD and the expression convex. At this point the question is: what does change with respect to gurobi's performances when allowing non-convex expressions ?

    0
  • Daniele Patria
    Gurobi-versary
    First Question
    Conversationalist

    Dear Matthias,

    I've been investigating the problem and I finally understood what was happening.
    A quadratic equality constraint, as you suggested, always takes to a non-convex feasible set (with appropriate hypothesis, clearly holding in this case). Unfortunately (and luckily, at the same time) gurobi pre-resolves models and it was very frequently happening that the notorious quadratic constraint was being ignored during the actual resolution, due to the pre-resolution of the model. Indeed, it only happened a few times that the "non-convex" error was thrown and it confused me about the meaning of the error and about what was actually happening. To sum everything up: I've learn something new about gurobi, and that's great!
    Thanks for your time and support.

    Best wishes,
    Daniele

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    It's great to read that you could resolve this issue! Indeed, presolving is an often underestimated part of solving complex problems and is even able to simplify the problem class (like getting rid of nonconvexity). Sometimes, it is difficult to convey this information to the user via the log file.

    Cheers,
    Matthias

    0

Please sign in to leave a comment.