Skip to content

Commit

Permalink
Mosek: enable convex QCP #229 #192
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Jan 12, 2024
1 parent 155f992 commit af15c5d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/mp/flat/redef/conic/cones.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ class ConicConverter : public MCKeeper<MCType> {
&& (MC().NumQC2SOCPAttempted() > MC().NumQC2SOCPSucceeded()
|| MC().HasQPObjective())) // and quadratics left in
|| // Some QC -> SOCP but not all
(((MC().NumQC2SOCPAttempted() > MC().NumQC2SOCPSucceeded()
&& !MC().IfConvertSOCP2QC()) // and not decided to convert
((MC().NumQC2SOCPAttempted() > MC().NumQC2SOCPSucceeded()
|| MC().HasQPObjective()) // or a quadratic obj
&& MC().NumQC2SOCPSucceeded()) // Warn only if some succeeded
&& MC().NumQC2SOCPSucceeded() // Warn only if some succeeded
&& !MC().IfConvertSOCP2QC()) // and not decided to convert
) {
MC().AddWarning("Mix QC+cones",
"Not all quadratic constraints could "
Expand Down
15 changes: 12 additions & 3 deletions include/mp/flat/redef/conic/qcones2qc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ class QConeConverter :
for (auto& coef: c)
coef *= coef;
c[0] = -c[0];
GetMC().NarrowVarBounds(x[0], 0.0, GetMC().Infty());
auto qc {QuadConLE{ {{}, {c, x, x}}, {0.0} }};
GetMC().AddConstraint(std::move(qc));
if (!GetMC().is_fixed(x[0])) {
GetMC().NarrowVarBounds(x[0], 0.0, GetMC().Infty());
auto qc {QuadConLE{ {{}, {c, x, x}}, {0.0} }};
GetMC().AddConstraint(std::move(qc));
} else { // produce fixed RHS, better for Mosek
auto rhs = -c[0] * GetMC().fixed_value(x[0]);
c.erase(c.begin());
auto x0 = x;
x0.erase(x0.begin());
auto qc {QuadConLE{ {{}, {c, x0, x0}}, {rhs} }};
GetMC().AddConstraint(std::move(qc));
}
}

/// Reuse the stored ModelConverter
Expand Down
8 changes: 8 additions & 0 deletions test/end2end/cases/categorized/fast/conic/modellist.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
"x": 3651.48
}
},
{
"name" : "socp_10_qpobj",
"tags" : ["quadratic"],
"objective" : 0.0,
"values": {
"solve_result_num": 0
}
},
{
"name" : "expcones_01__plain",
"objective" : 0.7821882953,
Expand Down
6 changes: 6 additions & 0 deletions test/end2end/cases/categorized/fast/conic/socp_10_qpobj.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# From #229.
# This is actually convex quadratic, not conic.

var x {1..7} >= 0;
minimize qobj: sum {j in 1..7} x[j]^2;
subj to qconstr: sum {j in 1..7} x[j]^2 <= 1000;

0 comments on commit af15c5d

Please sign in to comment.