pub fn compute_kkt_jacobian(
q: &[Vec<f64>],
g: &[Vec<f64>],
a: &[Vec<f64>],
x: &[f64],
lam: &[f64],
nu: &[f64],
) -> Vec<Vec<f64>>Expand description
Build the KKT Jacobian matrix ∂F/∂z for the QP:
min ½ x’Qx + c’x s.t. Gx ≤ h (m inequalities) Ax = b (p equalities)
The KKT conditions (with slacks absorbed into complementarity) are:
F₁ = Qx + c + G’diag(λ) + A’ν = 0 (stationarity, n eqs) F₂ = diag(λ)(Gx - h) = 0 (complementarity, m eqs) F₃ = Ax - b = 0 (primal equality, p eqs)
The Jacobian w.r.t. z = (x, λ, ν) is the (n+m+p) × (n+m+p) matrix:
┌ Q G’diag(λ)? A’ ┐ │ diag(λ)G diag(Gx-h) 0 │ └ A 0 0 ┘
For the complementarity row the correct linearisation is: ∂F₂/∂x = diag(λ) G ∂F₂/∂λ = diag(Gx - h) (= diag(s) where s = h - Gx ≥ 0 at optimum)
§Arguments
q– n*n cost matrix (row-majorVec<Vec<f64>>).g– m×n inequality constraint matrix.a– p×n equality constraint matrix.x– optimal primal (length n).lam– optimal inequality duals (length m).nu– optimal equality duals (length p).
§Returns
The full KKT Jacobian as a flat (n+m+p) × (n+m+p) row-major matrix.