Second-Order Cone and Semidefinite Programs
LPs use the cone of non-negative vectors: . 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 | LP | |
| second-order (Lorentz, "ice cream") cone | SOCP | |
| PSD cone | , all eigenvalues () | SDP |
Each class contains the previous one: is a 1-dimensional second-order cone, and is equivalent to .
Second-order cone programs
What SOCPs can express: Euclidean norms and distances, convex QPs and quadratic constraints, hyperbolic constraints , and robust LPs. If each constraint vector is uncertain within an ellipsoid , requiring for every possible is exactly
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
The variable is a symmetric matrix. SDPs appear in control (Lyapunov stability: find with ), 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:
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
LP ⊂ convex QP ⊂ SOCP ⊂ SDPAll 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_maxinto 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 in the second-order cone? ?
Answer
Yes (on the boundary); no.
Solution
, so holds and fails.
Exercise 2: PSD check
Is ? Is ?
Answer
Yes; no.
Solution
For symmetric matrices: PSD iff the diagonal entries and the determinant are non-negative. for the first; 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
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?
The variable in a semidefinite program is…
- an integer vector
- a symmetric matrix constrained to be PSD
- a probability
- a polynomial
A robust LP with ellipsoidal uncertainty in the constraint rows becomes…
- an LP
- an SOCP
- an integer program
- unsolvable