quadprog is a Python wrapper for a C++ library that efficiently solves quadratic programming problems. It minimizes `0.5 * x^T G x + a^T x` subject to `C^T x >= b` and an optional number of equality constraints (`meq`). The library is currently at version 0.1.13 and receives active, though somewhat irregular, maintenance.
pip install quadprogVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up and solve a simple quadratic programming problem with inequality constraints using `quadprog.solve_qp`. The problem minimizes `x^2 + y^2 - x - y` subject to `x >= 0`, `y >= 0`, and `x + y >= 1`.
Upgrade to version 0.1.11 or later to avoid this critical bug.
Verify that your `G` matrix is symmetric and strictly positive definite. For indefinite problems, consider other QP solvers or reformulate the problem.
Always transpose your constraint matrix `A` (where `A x >= b`) when passing it as `C` to `solve_qp`, i.e., `C = A.T`.
Ensure all equality constraints are placed at the beginning of your `C` and `b` arrays, and set `meq` accordingly.
Only set `factorized=True` if you are providing the Cholesky decomposition `R` of `G`. Otherwise, keep the default `factorized=False` and provide the original `G` matrix.
Install the library using pip: `pip install quadprog`
Ensure the 'a' vector has a shape of `(n,)` by using methods like `a = a.flatten()` or `a = a.ravel()`.
Verify that 'G' is `(n, n)`, 'a' is `(n,)`, 'C' is `(n, m)`, and 'b' is `(m,)` where `n` is the number of variables and `m` is the number of constraints, reshaping them if necessary.
Check if the 'G' matrix is strictly positive definite and well-conditioned; ensure the problem is feasible by reviewing your problem formulation, constraints, and objective function coefficients, and consider adding a small regularization term (e.g., `G = G + 1e-6 * np.eye(n)`) if 'G' is only positive semi-definite or nearly singular.