Active-Set Methods
If you knew which inequality constraints are active at the optimum, a QP would reduce to an equality-constrained QP, solved by one linear system. Active-set methods guess this set, solve, and update the guess one constraint at a time using the multipliers and step lengths. They are the QP analogue of the simplex method and excel at small and medium problems and at warm starts, as in model predictive control.
The primal active-set method
Keep a feasible point and a working set of constraints treated as equalities. Each iteration:
- Solve the equality-constrained QP for a step that keeps the working constraints active.
- If : compute the multipliers , . If all , stop: KKT holds. Otherwise drop the constraint with the most negative multiplier.
- If : move as far as possible toward without violating a constraint outside . If a constraint blocks, add it to .
import numpy as np
def active_set_qp(P, q, G, h, x, W):
n = len(x)
for it in range(50):
A = G[W]
K = np.block([[P, A.T], [A, np.zeros((len(W), len(W)))]]) if W else P
rhs = np.r_[-(P @ x + q), np.zeros(len(W))]
sol = np.linalg.solve(K, rhs)
p, lam = sol[:n], sol[n:]
if np.linalg.norm(p) < 1e-10:
if len(W) == 0 or lam.min() >= -1e-10:
return x, W, it
W = [w for k, w in enumerate(W) if k != int(np.argmin(lam))]
print(f" iter {it}: drop constraint, working set {W}")
continue
alpha, block = 1.0, None
for i in range(len(h)):
if i not in W and G[i] @ p > 1e-12:
a = (h[i] - G[i] @ x) / (G[i] @ p)
if a < alpha:
alpha, block = a, i
x = x + alpha * p
if block is not None:
W = W + [block]
print(f" iter {it}: x = {np.round(x, 4) + 0}, working set {W}")
return x, W, it
# minimize (x1 - 1)^2 + (x2 - 2.5)^2 s.t. five linear inequalities (a classic textbook polygon)
P = 2 * np.eye(2); q = np.array([-2.0, -5.0])
G = np.array([[-1.0, 2.0], [1.0, 2.0], [1.0, -2.0], [-1.0, 0.0], [0.0, -1.0]])
h = np.array([2.0, 6.0, 2.0, 0.0, 0.0])
x, W, it = active_set_qp(P, q, G, h, x=np.array([2.0, 0.0]), W=[2, 4])
print("solution:", np.round(x, 4), " active constraints:", W) iter 0: drop constraint, working set [4]
iter 1: x = [1. 0.], working set [4]
iter 2: drop constraint, working set []
iter 3: x = [1. 1.5], working set [0]
iter 4: x = [1.4 1.7], working set [0]
solution: [1.4 1.7] active constraints: [0]
The method started at a vertex with two constraints in the working set, dropped one whose multiplier was negative, moved along an edge, and so on until all multipliers in the working set were non-negative.
Why it terminates
Each step either decreases the objective strictly or changes the working set at the same point. Since the objective of the equality-constrained subproblem only depends on , a working set never repeats after a strict decrease, and there are finitely many working sets. Like the simplex method, the worst case is exponential, and practice is far better.
Warm starts: the killer feature
In model predictive control, a controller solves a similar QP every few milliseconds. The active set at time is an excellent guess for time , so the active-set method often needs zero or one change:
import numpy as np
from scipy.optimize import minimize
# a family of QPs that changes slowly: minimize |x - target(t)|^2 over the box [0, 1]^3 with sum x <= 1.5
cons = [{"type": "ineq", "fun": lambda x: 1.5 - x.sum()}]
prev_active = None
for t in np.linspace(0, 1, 6):
target = np.array([0.2 + 2 * t, 0.9 - 0.5 * t, 0.6])
r = minimize(lambda x: np.sum((x - target)**2), np.full(3, 0.3), method="SLSQP",
bounds=[(0, 1)] * 3, constraints=cons)
active = tuple(i for i in range(3) if r.x[i] > 1 - 1e-6 or r.x[i] < 1e-6) + (("sum",) if abs(r.x.sum() - 1.5) < 1e-6 else ())
print(f"t = {t:.1f}: x = {np.round(r.x, 3) + 0}, active: {active}, changed: {active != prev_active}")
prev_active = activet = 0.0: x = [0.134 0.833 0.533], active: ('sum',), changed: True
t = 0.2: x = [0.433 0.633 0.433], active: ('sum',), changed: False
t = 0.4: x = [0.733 0.433 0.333], active: ('sum',), changed: False
t = 0.6: x = [1. 0.25 0.25], active: (0, 'sum'), changed: True
t = 0.8: x = [1. 0.2 0.3], active: (0, 'sum'), changed: False
t = 1.0: x = [1. 0.15 0.35], active: (0, 'sum'), changed: False
After the first solve, the active set changes only once, at when reaches its upper bound. A warm-started active-set solver would need just one working-set change over the next five solves.
In software
- qpOASES (an online active-set solver built for MPC), the active-set QP inside SQP solvers (SNOPT, SLSQP), Gurobi's and CPLEX's simplex-based QP.
- For very large sparse QPs, interior-point (Clarabel, MOSEK) or ADMM (OSQP) usually wins.
Exercises
Exercise 1: Read a multiplier
An active-set iteration with has working-set multipliers . What happens next?
Answer
Drop the second constraint and continue.
Solution
A negative multiplier means relaxing that constraint (moving into its interior) decreases the objective. Dropping the one with the most negative multiplier is the usual rule.
Exercise 2: Blocking constraint
From along , with constraint not in the working set, how far can you move?
Answer
, to , and the constraint joins the working set.
Solution
, so the step is cut and the constraint becomes active.
Exercise 3: Check KKT (code)
For the polygon QP, check that the final point satisfies the KKT conditions with non-negative multipliers.
Answer
Stationarity holds with a non-negative multiplier on the single active constraint.
Solution
import numpy as np
P = 2 * np.eye(2); q = np.array([-2.0, -5.0])
G = np.array([[-1.0, 2.0], [1.0, 2.0], [1.0, -2.0], [-1.0, 0.0], [0.0, -1.0]]); h = np.array([2.0, 6.0, 2.0, 0.0, 0.0])
x = np.array([1.4, 1.7])
active = np.where(np.isclose(G @ x, h))[0]
lam = np.linalg.lstsq(G[active].T, -(P @ x + q), rcond=None)[0]
print("active:", active, " multipliers:", np.round(lam, 4), " feasible:", bool(np.all(G @ x <= h + 1e-12)))active: [0] multipliers: [0.8] feasible: True
Test yourself
In a primal active-set method, a constraint is removed from the working set when…
- its multiplier is negative
- its multiplier is positive
- it is violated
- the step is blocked
Active-set methods are especially good at…
- warm starts on sequences of similar QPs
- problems with billions of variables
- non-convex integer problems
- derivative-free problems
With the correct active set known, a convex QP reduces to…
- an LP
- a single linear solve of an equality-constrained KKT system
- a non-convex problem
- an integer program