|
Robotat Linalg
|
Convex quadratic problem solver, with direct methods for inequality constrained problems and an active-set method for inequality constrained problems. More...
Data Structures | |
| struct | quadprog_t |
| Quadratic Program (QP or quadprogram) problem structure. More... | |
Enumerations | |
| enum | quadprog_status_t { QP_SUCCESS , QP_SIZE_MISMATCH , QP_NOT_RESTRICTED , QP_NOT_CONVEX , QP_BAD_DEFINED } |
| Operation status from quadprog. More... | |
| enum | quadprog_method_t { QP_KKT_NULLSPACE , QP_KKT_LDLT , QP_LU , QP_SVD , QP_QR , SQP_ACTIVE_SET } |
| Quadprog-specific methods for solving QPs. More... | |
Functions | |
| void | quadprog_status_print (quadprog_status_t status) |
| Print quadprog status. | |
| void | quadprog_init (quadprog_t *const p_qp, const matf32_t *const p_Q, const matf32_t *const p_c, const matf32_t *const p_Aeq, const matf32_t *const p_beq, const matf32_t *const p_Ain, const matf32_t *const p_bin, const matf32_t *const p_x0) |
| Constructor for the quadratic problem data structure. Set as null any argment that isn't needed. | |
| quadprog_status_t | quadprog (quadprog_t *p_qp, matf32_t *const p_x, bool set_linsolve_method, quadprog_method_t method) |
| Quadratic convex problem solver, choosing automatically the method to be used. | |
| quadprog_status_t | quadprog_qp_linsolve (quadprog_t *p_qp, matf32_t *const p_x, linsolve_method_t method) |
| Equality restricted quadratic convex problem solver by constructing a KKT system and then solving it through one of the following linsolve methods: LU, SVD or QR (the method must be specificed in the arguments of the function). The KKT system is constructed as follows: | |
| quadprog_status_t | quadprog_qp_nullspace (quadprog_t *p_qp, matf32_t *const p_x) |
| Solves a convex quadratic problem with equality restrictions using the null-space method for KKT systems. This method does NOT construct and solve the KKT system directly, instead, it does the following procedure as described in Nocedal, Numerical Optimization: | |
| quadprog_status_t | quadprog_qp_ldlt (quadprog_t *p_qp, matf32_t *const p_x) |
| Solves a convex quadratic problem with equality restrictions using the LDL' factorization, as explained in Nocedal, Numerical Optimization. | |
| quadprog_status_t | quadprog_sqp (quadprog_t *p_qp, matf32_t *const p_x) |
| Solves a convex quadratic problem with an active-set binding direction method, based on Martins, Engineering Design Optimization, algorithm 5.4, but divided in four cases depending on the combination of restrictions that can be found in each iteration, so that the KKT system that's built and solved in each iteration is as small as possible (increasing solving speed and stability). As such, the procedure implemented in this routine is as follows: | |
Convex quadratic problem solver, with direct methods for inequality constrained problems and an active-set method for inequality constrained problems.
Last modified: 16 Nov. 2026 By: Andrea Pineda
| struct quadprog_t |
Quadratic Program (QP or quadprogram) problem structure.
| Data Fields | ||
|---|---|---|
| const matf32_t * | p_Aeq |
Equality conditions matrix |
| const matf32_t * | p_Ain |
Inequality conditions matrix |
| const matf32_t * | p_beq |
Equality conditions vector |
| const matf32_t * | p_bin |
Inequality conditions vector |
| const matf32_t * | p_c |
Cost function vector |
| const matf32_t * | p_Q |
Cost function matrix |
| const matf32_t * | p_x0 |
Starting point |
| enum quadprog_method_t |
Quadprog-specific methods for solving QPs.
| enum quadprog_status_t |
| quadprog_status_t quadprog | ( | quadprog_t * | p_qp, |
| matf32_t *const | p_x, | ||
| bool | set_linsolve_method, | ||
| quadprog_method_t | method ) |
Quadratic convex problem solver, choosing automatically the method to be used.
| [in] | p_qp | Points to the structure representing the problem to solve. |
| [in,out] | p_x | Points to the vector to store the result. |
| void quadprog_init | ( | quadprog_t *const | p_qp, |
| const matf32_t *const | p_Q, | ||
| const matf32_t *const | p_c, | ||
| const matf32_t *const | p_Aeq, | ||
| const matf32_t *const | p_beq, | ||
| const matf32_t *const | p_Ain, | ||
| const matf32_t *const | p_bin, | ||
| const matf32_t *const | p_x0 ) |
Constructor for the quadratic problem data structure. Set as null any argment that isn't needed.
| [in,out] | p_qp | Points to structure representing the problem. |
| [in] | p_Q | Cost function matrix. |
| [in] | p_c | Cost function vector. |
| [in] | p_Ain | Inequality conditions matrix. |
| [in] | p_vin | Inequality conditions vector. |
| [in] | p_Aeq | Equality conditions matrix. |
| [in] | p_veq | Equality conditions vector. |
| [in] | p_x0 | Starting point. |
| quadprog_status_t quadprog_qp_ldlt | ( | quadprog_t * | p_qp, |
| matf32_t *const | p_x ) |
Solves a convex quadratic problem with equality restrictions using the LDL' factorization, as explained in Nocedal, Numerical Optimization.
Starting with the KKT system for the problem with equality restrictions:
\[\begin{bmatrix} \textbf{Q} & \textbf{A}^\top \\ \textbf{A} & \textbf{0} \end{bmatrix} \begin{bmatrix} \textbf{-p} \\ \boldsymbol{\lambda} \end{bmatrix} = \begin{bmatrix} \textbf{c} \\ \textbf{b} \\ \end{bmatrix} \]
The \( \textbf{LDL}^\top \) factorization is applied to the matrix of the system, to get the resulting structure:
\[ \textbf{P}^\top \textbf{MP} = \textbf{LDL}^\top \]
where \( \textbf{P} \) is a permutation matrix, while \( \textbf{L} \) and \( \textbf{D} \) are, respectively, a lower triangular and diagonal matrix, all generated during the procedure of the factorization.
Afterwards, the KKT system is solved as follows:
\[ \textbf{Lz}_1 = \textbf{P}^\top \textbf{b} \]
\[ \textbf{Bz}_2 = \textbf{z}_1 \]
\[ \textbf{L}^\top \textbf{z}_3 = \textbf{z}_2 \]
\[ \textbf{y} = \textbf{Pz}_3 \]
where:
\[ \textbf{b} = \begin{bmatrix} \textbf{g} \\ \textbf{h} \end{bmatrix} \]
\[ \textbf{y} = \begin{bmatrix} - \textbf{p} \\ \boldsymbol{\lambda} \end{bmatrix} \]
The specific algorithm in this routine for the factorization corresponds to the symmetric indefinite factorization with Bunch and Parlett Pivoting as presented in section 4.4.3 of Golub, Matrix Computations. The different linear systems in the procedure are solved using linsolve.
| [in] | p_qp | Points to the structure representing the problem to solve. |
| [in,out] | p_x | Points to the vector to store the solution for the QP. |
| quadprog_status_t quadprog_qp_linsolve | ( | quadprog_t * | p_qp, |
| matf32_t *const | p_x, | ||
| linsolve_method_t | method ) |
Equality restricted quadratic convex problem solver by constructing a KKT system and then solving it through one of the following linsolve methods: LU, SVD or QR (the method must be specificed in the arguments of the function). The KKT system is constructed as follows:
\[\begin{bmatrix} \textbf{Q} & \textbf{A}^\top \\ \textbf{A} & \textbf{0} \end{bmatrix} \begin{bmatrix} \textbf{-p} \\ \boldsymbol{\lambda} \end{bmatrix} = \begin{bmatrix} \textbf{c} \\ \textbf{b} \\ \end{bmatrix} \]
according to the matrices of the cost function and restrictions of the QP, and the definition of the KKT system (Nocedal, Numerical Optimization).
| [in] | p_qp | Points to the structure representing the problem to solve. |
| [out] | p_x | Points to the vector to store the solution to the QP. |
| [in] | method | Linsolve method to use for solving the system: LU, SVD or QR. |
| quadprog_status_t quadprog_qp_nullspace | ( | quadprog_t * | p_qp, |
| matf32_t *const | p_x ) |
Solves a convex quadratic problem with equality restrictions using the null-space method for KKT systems. This method does NOT construct and solve the KKT system directly, instead, it does the following procedure as described in Nocedal, Numerical Optimization:
Starting from the definition of a KKT system for the problem with equality restrictions:
\[\begin{bmatrix} \textbf{Q} & \textbf{A}^\top \\ \textbf{A} & \textbf{0} \end{bmatrix} \begin{bmatrix} \textbf{-p} \\ \boldsymbol{\lambda} \end{bmatrix} = \begin{bmatrix} \textbf{c} \\ \textbf{b} \\ \end{bmatrix} \]
The solution vector \( \textbf{p} \) is calculated through partial solutions, which are as follows:
\[ \textbf{p} = \textbf{Yp}_y + \textbf{Zp}_z \]
where \( \textbf{Y} \) is (n x m) and \( \textbf{Z} \) is (n x (n-m)), and are generated from the \( \textbf{Q} \) matrix of the QR factorization.
Then, the vectors \( \textbf{p}_y \) and \( \textbf{p}_z \) of the partial solutions are calculated, by solving the following linear systems:
\[ \textbf{AYp}_y = - \textbf{h} \]
\[ \textbf{Z}^\top \textbf{QZp}_z = -\textbf{Z}^\top \textbf{Q} \textbf{Yp}_y - \textbf{Z}^\top \textbf{g} \]
After which, \( \textbf{p} \) can be calculated.
Currently, this routine does NOT calculate the Lagrange multipliers associated to the solution of the QP, but if you need them, the following operation should be added:
\[ \textbf{AY}^\top \boldsymbol{\lambda} = \textbf{Y}^\top (\textbf{g} + \textbf{Gp}) \]
| [in] | p_qp | Points to the structure representing the problem to solve. |
| [in,out] | p_x | Points to the vector to store the solution for the QP. |
| quadprog_status_t quadprog_sqp | ( | quadprog_t * | p_qp, |
| matf32_t *const | p_x ) |
Solves a convex quadratic problem with an active-set binding direction method, based on Martins, Engineering Design Optimization, algorithm 5.4, but divided in four cases depending on the combination of restrictions that can be found in each iteration, so that the KKT system that's built and solved in each iteration is as small as possible (increasing solving speed and stability). As such, the procedure implemented in this routine is as follows:
Case 1: There are both equality and inequality restrictions
\[\begin{bmatrix} \textbf{Q} & \textbf{A}_{eq}^\top & \textbf{A}_w^\top\\ \textbf{A}_{eq} & 0 & 0 \\ \textbf{A}_w & 0 & 0 \end{bmatrix} \begin{bmatrix} \textbf{p}_k \\ \boldsymbol{\lambda}_{eq} \\ \boldsymbol{\lambda}_w \end{bmatrix} = - \begin{bmatrix} \textbf{Qx}_k + \textbf{c} \\ \textbf{A}_{eq}\textbf{x}_k - \textbf{b}_{eq} \\ \textbf{A}_w \textbf{x}_k - \textbf{b}_w \end{bmatrix} \]
Case 2: There are only equality restrictions
\[\begin{bmatrix} \textbf{Q} & \textbf{A}_{eq}^\top \\ \textbf{A}_{eq} & 0 \end{bmatrix} \begin{bmatrix} \textbf{p}_k \\ \boldsymbol{\lambda}_eq \end{bmatrix} = - \begin{bmatrix} \textbf{Qx}_k + \textbf{c} \\ \textbf{A}_{eq} - \textbf{b}_{eq} \end{bmatrix} \]
Case 3: There are only inequality restrictions (and at least one is active)
\[\begin{bmatrix} \textbf{Q} & \textbf{A}_w^\top \\ \textbf{A}_w & 0 \end{bmatrix} \begin{bmatrix} \textbf{p}_k \\ \boldsymbol{\lambda}_w \end{bmatrix} = - \begin{bmatrix} \textbf{Qx}_k + \textbf{c} \\ \textbf{A}_w - \textbf{b}_w \end{bmatrix} \]
Case 4: There are no restrictions (either the problem was unconstrained or had only inequality restrictions such as, currently, all are inactive)
\[ \textbf{Qp}_k = -(\textbf{Qx}_k + \textbf{c}) \]
| [in] | p_qp | Points to the structure representing the problem to solve. |
| [in,out] | p_x | Points to the vector to store the result. |
| void quadprog_status_print | ( | quadprog_status_t | status | ) |
Print quadprog status.
| [in] | p_qp | quadprog execution status. |