How to enter SOC constraints in the C interface
AnsweredTo represent the constraint {x,y}<z I tried adding lower variable bounds
lbound[0] = GRB_INFINITY; lbound[1] = GRB_INFINITY; lbound[2] =0.;
and then from the example tour document:
/* Cone: x^2 + y^2 <= z^2 */
qrow [0] = 0; qcol [0] = 0; qval [0] = 1.0;
qrow [1] = 1; qcol [1] = 1; qval [1] = 1.0;
qrow [2] = 2; qcol [2] = 2; qval [2] = 1.0;
error = GRBaddqconstr(model , 0, NULL , NULL , 3, qrow , qcol , qval ,'<' , 0.0, "qc0");
but when optimizing I get error 10020 (Q matrix in QP model is not positive semidefinite).
What is the best way to represent SOC constraints in the C interface?
Also I am wondering if only SOC constraints of type 'v is in K' are supported or one can add a constraint of type 'Av+b is in K'.

The above actually works for me without an error (after I fixed a mistyped index). The affine SOC constraint 'Av+b is in K' also worked.
0 
Actually the affine SOC constraint 'Av+b is in K' when rewritten in the form 1/2 v^T.Q.v + q.v <= b seems to work in some cases, such as for a diagonal A, but for a general rectangular matrix it doesn't seem recognized as a SOC constraint since I get error 10020 (Q matrix in QP model is not positive semidefinite) . Is this expected? I am using gurobi902.
0 
Gurobi accepts all SOC in standard form. But when it comes to rotated or affine SOCs, it may not be able to detect the structure. Then, it falls back to the regular Q constraint mechanism, which requires the Q matrix to be PSD (which is of course not true for SOCs).
Regards,
Tobias
0 
Tobias Achterberg, could you explain more on what affine SOCs are detectable and what are not? I found that diagonal Q works (for example Q = diag([a, b, c]) where a, b, c are all positive numbers). Also it seems that matrix in this form
[A 0]
[0, d]
where A is a positive definite matrix and d is a positive scalar also works.
Are there other affine SOCs that are detectable? If I shuffle the order of my variables (and hence shuffle the rows and columns of the Q matrix, would gurobi still detect it? It would be great if there is cleaner explanation for this.
I ask this question since I am writing a parser for Gurobi (similar to how YALMIP and cvxpy parses the program to Gurobi format). It would be greatly helpful if I know in which cases I can rely on Gurobi to detect the SOC constraint, and in which cases I need to add slack variables so that my affine SOC is converted to the standard form. I found these two approaches generate slightly different answers, especially when I adjust the tolerance (like BarConvTol).
0 
This is a delicate issue. We only promise that we will be able to detect the following two cases as convex:
1. x^T Q x <= d with PSD matrix Q
2. sum xj²  y² <= 0 with y >= 0But Gurobi will also be able to detect some other situations to be convex. But whether we will be able to detect those additional cases also depends on the presolve transformations that we apply. Only for the two cases above we make sure that presolve reductions do not destroy the structure (i.e., turn a constraint that is in one of the two forms into a constraint that no longer is in one of the two forms).
We also detect rotated second order cones and some additional special cases, but as I said, it depends on how exactly these constraints then look like after presolve whether we are able to detect them as convex.
0
Please sign in to leave a comment.
Comments
5 comments