TExcelTAD
Home › Optimization › Second-Order Cone and Semidefinite Programs

Second-Order Cone and Semidefinite Programs

LPs use the cone of non-negative vectors: x≥0\mathbf{x} \ge \mathbf{0}. Replace that cone with a richer one and you get far more modelling power while keeping interior-point efficiency. Second-order cone programs (SOCPs) handle norms and robust constraints; semidefinite programs (SDPs) optimize over positive semidefinite matrices and give the strongest known relaxations of hard combinatorial problems.

The cones

Cone Definition Program
non-negative orthant x≥0\mathbf{x} \ge \mathbf{0} LP
second-order (Lorentz, "ice cream") cone ∥u∥2≤t\lVert \mathbf{u} \rVert_2 \le t SOCP
PSD cone X=XTX = X^T, all eigenvalues ≥0\ge 0 (X⪰0X \succeq 0) SDP

Each class contains the previous one: x≥0x \ge 0 is a 1-dimensional second-order cone, and ∥u∥≤t\lVert \mathbf{u} \rVert \le t is equivalent to [tIuuTt]⪰0\begin{bmatrix} tI & \mathbf{u} \\ \mathbf{u}^T & t \end{bmatrix} \succeq 0.

Second-order cone programs

min⁡ fTxs.t.∥Aix+bi∥2≤ciTx+di,i=1,…,m\min\ \mathbf{f}^T\mathbf{x} \quad \text{s.t.} \quad \lVert A_i\mathbf{x} + \mathbf{b}_i \rVert_2 \le \mathbf{c}_i^T\mathbf{x} + d_i, \quad i = 1, \dots, m

What SOCPs can express: Euclidean norms and distances, convex QPs and quadratic constraints, hyperbolic constraints x2≤yzx^2 \le yz, and robust LPs. If each constraint vector ai\mathbf{a}_i is uncertain within an ellipsoid {aˉi+Piu:∥u∥≤1}\{\bar{\mathbf{a}}_i + P_i\mathbf{u} : \lVert \mathbf{u} \rVert \le 1\}, requiring aiTx≤bi\mathbf{a}_i^T\mathbf{x} \le b_i for every possible ai\mathbf{a}_i is exactly

aˉiTx+∥PiTx∥2≤bi\bar{\mathbf{a}}_i^T\mathbf{x} + \lVert P_i^T\mathbf{x} \rVert_2 \le b_i
python · try it yourself
import numpy as np
from scipy.optimize import linprog, minimize

# maximize 3a + 5b with uncertain constraint coefficients (radius 0.3 around the nominal rows)
A = np.array([[1.0, 2.0], [2.0, 1.0]]); b = np.array([8.0, 10.0]); r = 0.3
nominal = linprog([-3, -5], A_ub=A, b_ub=b, bounds=[(0, None)] * 2, method="highs").x
cons = [{"type": "ineq", "fun": lambda x, i=i: b[i] - A[i] @ x - r * np.linalg.norm(x)} for i in range(2)]
robust = minimize(lambda x: -(3 * x[0] + 5 * x[1]), [1.0, 1.0], constraints=cons,
                  bounds=[(0, None)] * 2, method="SLSQP").x
rng = np.random.default_rng(0)
def violation_rate(x, trials=20000):
    U = rng.normal(size=(trials, 2, 2)); U /= np.linalg.norm(U, axis=2, keepdims=True)
    U *= rng.uniform(0, 1, size=(trials, 2, 1))**0.5            # uniform in the disk
    rows = A[None] + r * U
    return np.mean(np.any(np.einsum("tij,j->ti", rows, x) > b + 1e-9, axis=1))
for name, x in [("nominal", nominal), ("robust", robust)]:
    print(f"{name:8s} x = {np.round(x, 3)}, profit = {3 * x[0] + 5 * x[1]:.3f}, violated in {violation_rate(x):.1%} of scenarios")
nominal  x = [4. 2.], profit = 22.000, violated in 74.6% of scenarios
robust   x = [3.593 1.613], profit = 18.843, violated in 0.0% of scenarios

The robust plan gives up some profit to stay feasible in every scenario of the uncertainty set.

Semidefinite programs

min⁡ tr⁡(CX)s.t.tr⁡(AiX)=bi,X⪰0\min\ \operatorname{tr}(CX) \quad \text{s.t.} \quad \operatorname{tr}(A_iX) = b_i, \quad X \succeq 0

The variable is a symmetric matrix. SDPs appear in control (Lyapunov stability: find P≻0P \succ 0 with ATP+PA≺0A^TP + PA \prec 0), in combinatorial relaxations (Goemans-Williamson MAX-CUT gives a 0.878 approximation guarantee), in sum-of-squares polynomial optimization, and in statistics.

A classic SDP-flavoured task is the nearest correlation matrix: an estimated correlation matrix (from incomplete data) is not PSD; find the closest valid one. Alternating projections onto the PSD cone and onto "unit diagonal" matrices (with Dykstra's correction) solve it:

python · try it yourself
import numpy as np

C = np.array([[1.0, 0.9, 0.7], [0.9, 1.0, -0.3], [0.7, -0.3, 1.0]])   # inconsistent "correlations"
print("eigenvalues of C:", np.round(np.linalg.eigvalsh(C), 4))
def proj_psd(X):
    w, V = np.linalg.eigh((X + X.T) / 2)
    return V @ np.diag(np.maximum(w, 0)) @ V.T
Y, dS = C.copy(), np.zeros_like(C)
for _ in range(500):
    R = Y - dS
    X = proj_psd(R)
    dS = X - R
    Y = X.copy(); np.fill_diagonal(Y, 1.0)
print("nearest correlation matrix:\n", np.round(Y, 4))
print("eigenvalues:", np.round(np.linalg.eigvalsh(Y), 4) + 0, " distance:", round(float(np.linalg.norm(Y - C)), 4))
eigenvalues of C: [-0.2967  1.2894  2.0074]
nearest correlation matrix:
 [[ 1.      0.7229  0.5531]
 [ 0.7229  1.     -0.1757]
 [ 0.5531 -0.1757  1.    ]]
eigenvalues: [0.     1.1691 1.8309]  distance: 0.3698

The input has a negative eigenvalue (no random variables can have those correlations); the result is the closest valid correlation matrix in the Frobenius norm, with smallest eigenvalue at zero.

The hierarchy

text
LP  ⊂  convex QP  ⊂  SOCP  ⊂  SDP

All of them are solved by primal-dual interior-point methods in polynomial time, with cost growing quickly from left to right. Pick the smallest class that expresses your problem.

In software

  • CVXPY with Clarabel, ECOS, SCS or MOSEK solves SOCPs and SDPs from a natural description; it reformulates norms, quadratic forms and lambda_max into cone constraints automatically.
  • Finance libraries use SOCPs for robust portfolios and tracking-error limits; control toolboxes use SDPs (LMIs) for controller synthesis.

Exercises

Exercise 1: Cone membership

Is (u,t)=((3,4),5)(\mathbf{u}, t) = ((3, 4), 5) in the second-order cone? ((3,4),4)((3, 4), 4)?

Answer

Yes (on the boundary); no.

Solution

∥(3,4)∥=5\lVert (3, 4) \rVert = 5, so 5≤55 \le 5 holds and 5≤45 \le 4 fails.

Exercise 2: PSD check

Is [2111]⪰0\begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} \succeq 0? Is [1221]\begin{bmatrix} 1 & 2 \\ 2 & 1 \end{bmatrix}?

Answer

Yes; no.

Solution

For 2×22 \times 2 symmetric matrices: PSD iff the diagonal entries and the determinant are non-negative. det⁡=1≥0\det = 1 \ge 0 for the first; det⁡=1−4=−3<0\det = 1 - 4 = -3 < 0 for the second.

Exercise 3: Robustness margin (code)

For the robust LP, what profit does the robust plan lose compared with the nominal plan, in percent?

Answer

About 14%: the robust profit is about 18.84 versus 22.

Solution
python · try it yourself
nominal, robust = 22.0, 18.843
print(f"{(nominal - robust) / nominal:.1%}")
14.3%

This is the "price of robustness": choosing the uncertainty radius trades expected profit against the risk of infeasibility.

Test yourself

Which constraint is a second-order cone constraint?

  1. ∥Ax+b∥2≤cTx+d\lVert A\mathbf{x} + \mathbf{b} \rVert_2 \le \mathbf{c}^T\mathbf{x} + d
  2. x1x2=1x_1x_2 = 1
  3. x∈{0,1}x \in \{0, 1\}
  4. ∥x∥2≥1\lVert \mathbf{x} \rVert_2 \ge 1

The variable in a semidefinite program is…

  1. an integer vector
  2. a symmetric matrix constrained to be PSD
  3. a probability
  4. a polynomial

A robust LP with ellipsoidal uncertainty in the constraint rows becomes…

  1. an LP
  2. an SOCP
  3. an integer program
  4. unsolvable