Gurobi Solver Incorrectly Identifying Non-Convex MIQCP in a SOCP Model
回答済みHi,
I am encountering an issue with Gurobi where it incorrectly identifies my model as a non-convex MIQCP. However, I am certain that my model only contains second-order cone (SOCP) constraints, which are inherently convex.
for (int i = 0; i < totalNum - 1; i++) { //SOCP GRBQuadExpr cs1; cs1 = new GRBQuadExpr(); for (int j = 0; j < totalNum - 1; j++) { if (i != j && distance[i][j] >= Dmin) { cs1.addTerm(I[i][j]*I[i][j], z[j],z[j]); } } GRBQuadExpr fuzhuright = new GRBQuadExpr(); fuzhuright.addTerm(1,b[i],b[i]); model.addQConstr(fuzhuright,GRB.EQUAL,cs1,"fz_"+i); GRBLinExpr rhs = new GRBLinExpr(); rhs.addConstant(wMax[i]); rhs.addTerm(-wMax[i], z[i]); rhs.addTerm(1,w[i]); model.addConstr(b[i], GRB.LESS_EQUAL, rhs, "qrt_" + i); GRBQuadExpr w2 = new GRBQuadExpr(); w2.addTerm(1,w[i],w[i]); model.addQConstr(L[i],GRB.EQUAL,w2,"L_"+i); }
Could you please help me understand why Gurobi is classifying my model as non-convex and how I might correct this issue?
Best regards,
Chenhui
-
Hi Chenhui,
Could you please use the write method to generate a human-readable LP file.
model.write("myModel.lp")
will generate the file \(\texttt{myModel.lp}\) which you can analyze in any standard text editor.
With that file you should be able to determine whether the model indeed looks as expected or if something is off. If you cannot find anything wrong with the model, then please share the LP file. Note that uploading files in the Community Forum is not possible but we discuss an alternative in Posting to the Community Forum.
On a second view: I see that you are adding equality constraints with square terms, but second-order cone constraints are inequalities. Please note that equality constraints with any nonlinear terms are nonconvex.Best regards,
Jaromił1 -
Dear Jaromił,
Thank you very much for your suggestion! I recently modified the model and found that the main issue was that I should use inequalities. Your advice was very helpful! However, I have another question.
I want to build this model as a SOCP to solve it, but Gurobi does not indicate "Presolved model has * second-order cone constraints." Instead, it just says "Presolved model has 372 quadratic constraint(s)." How should I construct this model to solve it as an SOCP?
Best wishes,
Chenhui
0 -
Hi Chenhui,
I want to build this model as a SOCP to solve it, but Gurobi does not indicate "Presolved model has * second-order cone constraints." Instead, it just says "Presolved model has 372 quadratic constraint(s)." How should I construct this model to solve it as an SOCP?
It is possible that the constraints you generate are actually not second-order cones but just convex quadratic constraints. Could you please post the log output of an optimization run? There should be more hints to find out what is happening.
Best regards,
Jaromił0 -
Hi Jaromił,
Thank you for your reply!
This is the constraint which I suppose is a soc constraint:
I transformed this constraint into the following form for input into GUROBI:
Here is the corresponding code:
for (int i = 0; i < totalNum - 1; i++) {
GRBQuadExpr cs1;
cs1 = new GRBQuadExpr();
for (int j = 0; j < totalNum - 1; j++) {
if (i != j && distance[i][j] >= Dmin) {
cs1.addTerm(I[i][j] * I[i][j], z[j], z[j]);
}
}
GRBQuadExpr fuzhuright = new GRBQuadExpr();
fuzhuright.addTerm(1, b[i], b[i]);
model.addQConstr(fuzhuright, GRB.GREATER_EQUAL, cs1, "fz_" + i);//equal
GRBLinExpr rhs = new GRBLinExpr();
rhs.addConstant(wMax[i]);
rhs.addTerm(-wMax[i], z[i]);
rhs.addTerm(1, w[i]);
model.addConstr(b[i], GRB.LESS_EQUAL, rhs, "qrt_" + i);
}I'm not sure what went wrong that caused Gurobi not to recognize it as a soc constraint. And here is the log file, can you please help me look at it again? Thank you very much!
Set parameter Username
Academic license - for non-commercial use only - expires 2025-04-03
Set parameter Threads to value 4
Set parameter LazyConstraints to value 1
Warning: zero or small (< 1e-13) coefficients in quadratic constraints, ignored
Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored
Gurobi Optimizer version 11.0.1 build v11.0.1rc0 (win64 - Windows 11.0 (22631.2))
CPU model: 12th Gen Intel(R) Core(TM) i7-12700, instruction set [SSE2|AVX|AVX2]
Thread count: 12 physical cores, 20 logical processors, using up to 4 threads
Presolve removed 4237 rows and 2312 columns
Presolve time: 0.20s
Gurobi Optimizer version 11.0.1 build v11.0.1rc0 (win64 - Windows 11.0 (22631.2))
CPU model: 12th Gen Intel(R) Core(TM) i7-12700, instruction set [SSE2|AVX|AVX2]
Thread count: 12 physical cores, 20 logical processors, using up to 4 threads
Optimize a model with 9075 rows, 9920 columns and 92348 nonzeros
Model fingerprint: 0xe26477a7
Model has 78 quadratic constraints
Variable types: 1799 continuous, 8121 integer (8121 binary)
Coefficient statistics:
Matrix range [1e-12, 1e+01]
QMatrix range [2e-13, 1e+00]
QLMatrix range [1e+00, 1e+00]
Objective range [2e+01, 7e+03]
Bounds range [1e+00, 1e+00]
RHS range [2e-04, 1e+01]
Presolve removed 1816 rows and 1017 columns
Presolve time: 0.26s
Presolved: 7291 rows, 9230 columns, 82088 nonzeros
Presolved model has 372 quadratic constraint(s)
Variable types: 1956 continuous, 7274 integer (7274 binary)
Root relaxation: objective -1.285553e+04, 3307 iterations, 0.11 seconds (0.32 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 -12855.527 0 91 - -12855.527 - - 0s
H 0 0 -17460.85167 -12855.527 26.4% - 0s
H 0 0 -17184.50623 -12855.527 25.2% - 0s
H 0 0 -16536.73876 -12855.527 22.3% - 0s
0 0 -13141.378 0 117 -16536.739 -13141.378 20.5% - 1s
H 0 0 -14266.49000 -13280.549 6.91% - 1s
0 0 -13422.497 0 136 -14266.490 -13422.497 5.92% - 1s
0 0 -13422.497 0 124 -14266.490 -13422.497 5.92% - 4s
0 0 -13614.365 0 127 -14266.490 -13614.365 4.57% - 4s
0 0 -13670.267 0 123 -14266.490 -13670.267 4.18% - 4s
0 0 -13750.681 0 142 -14266.490 -13750.681 3.62% - 4s
0 0 -13750.681 0 121 -14266.490 -13750.681 3.62% - 4s
0 0 -13750.681 0 156 -14266.490 -13750.681 3.62% - 4s
0 0 -13776.858 0 143 -14266.490 -13776.858 3.43% - 4s
0 0 -13822.955 0 135 -14266.490 -13822.955 3.11% - 4s
0 0 -13833.117 0 132 -14266.490 -13833.117 3.04% - 4s
0 0 -13846.930 0 136 -14266.490 -13846.930 2.94% - 5s
0 0 -13854.808 0 126 -14266.490 -13854.808 2.89% - 5s
0 0 -13855.317 0 149 -14266.490 -13855.317 2.88% - 5s
0 0 -13865.596 0 139 -14266.490 -13865.596 2.81% - 5s
0 0 -13865.596 0 157 -14266.490 -13865.596 2.81% - 5s
0 0 -13867.601 0 167 -14266.490 -13867.601 2.80% - 5s
0 0 -13867.601 0 158 -14266.490 -13867.601 2.80% - 5s
0 0 -13872.369 0 140 -14266.490 -13872.369 2.76% - 5s
0 0 -13872.369 0 138 -14266.490 -13872.369 2.76% - 5s
0 0 -13875.786 0 141 -14266.490 -13875.786 2.74% - 5s
0 0 -13875.786 0 144 -14266.490 -13875.786 2.74% - 5s
0 0 -13885.595 0 145 -14266.490 -13885.595 2.67% - 5s
0 0 -13885.595 0 153 -14266.490 -13885.595 2.67% - 5s
0 0 -13885.595 0 162 -14266.490 -13885.595 2.67% - 5s
0 0 -13885.595 0 169 -14266.490 -13885.595 2.67% - 5s
0 0 -13885.595 0 175 -14266.490 -13885.595 2.67% - 5s
0 0 -13885.595 0 140 -14266.490 -13885.595 2.67% - 5s
0 0 -13886.511 0 141 -14266.490 -13886.511 2.66% - 5s
0 0 -13886.511 0 149 -14266.490 -13886.511 2.66% - 5s
0 0 -13888.459 0 157 -14266.490 -13888.459 2.65% - 5s
0 0 -13888.459 0 156 -14266.490 -13888.459 2.65% - 5s
0 0 -13888.459 0 176 -14266.490 -13888.459 2.65% - 5s
0 0 -13888.459 0 174 -14266.490 -13888.459 2.65% - 5s
0 0 -13888.459 0 168 -14266.490 -13888.459 2.65% - 5s
H 0 0 -14266.49000 -13890.148 2.64% - 5s
0 0 -13890.148 0 90 -14266.490 -13890.148 2.64% - 5s
0 0 -13890.148 0 135 -14266.490 -13890.148 2.64% - 5s
0 0 -13896.922 0 111 -14266.490 -13896.922 2.59% - 5s
0 0 -13903.270 0 136 -14266.490 -13903.270 2.55% - 5s
0 0 -13914.142 0 148 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 155 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 127 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 155 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 152 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 133 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 130 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 138 -14266.490 -13914.142 2.47% - 5s
0 0 -13914.142 0 138 -14266.490 -13914.142 2.47% - 5s
0 2 -13920.421 0 138 -14266.490 -13920.421 2.43% - 6s
* 217 41 6 -14068.69571 -13994.153 0.53% 26.6 6s
Cutting planes:
Gomory: 5
Lift-and-project: 2
Implied bound: 36
Clique: 1
MIR: 49
Flow cover: 41
Zero half: 3
Mod-K: 1
RLT: 1
Relax-and-lift: 10
PSD: 5
Explored 257 nodes (16987 simplex iterations) in 6.20 seconds (6.09 work units)
Thread count was 4 (of 20 available processors)
Solution count 5: -14068.7 -14266.5 -16536.7 ... -17460.9
No other solutions better than -14068.7
Optimal solution found (tolerance 1.00e-04)
Best objective -1.406869571130e+04, best bound -1.406869571130e+04, gap 0.0000%
User-callback calls 2264, time in user-callback 0.01 sec0 -
Hi Chenhui,
Your model has discrete variables
Variable types: 1799 continuous, 8121 integer (8121 binary)
In this case, Gurobi does not report second-order cone constraints but only the number of quadratic constraints. Internally, the constraints you constructed are still recognized to be convex and handled as such. However, due to the discrete variables, the Mixed-integer part of the code has to be executed. So all-in-all it looks like the behavior you see is correct and expected.
Best regards,
Jaromił0 -
Hi Jaromił,
Thank you very much for your support!!
Best wishes,
Chenhui
0
サインインしてコメントを残してください。
コメント
6件のコメント