# Convex Quadratic Programming

- enum FadasCQPSolverStatus\_e

    - Convex QP Solver status.

- Param FADAS\_CQP\_SUCCESS:

    - Optimal solution found.

- Param FADAS\_CQP\_SOLUTION\_INFEASIBLE:

    - Infeasible solution.

- Param FADAS\_CQP\_HESSIANNOTPD:

    - Input Hessian is not PD.

- Param FADAS\_CQP\_MAX\_ITERATIONS\_REACHED:

    - Solver reaches max iterations.

*Values:*

- enumerator FADAS\_CQP\_SUCCESS

    - Optimal solution found.

- enumerator FADAS\_CQP\_SOLUTION\_INFEASIBLE

    - Infeasible solution.

- enumerator FADAS\_CQP\_HESSIAN\_NOT\_PD

    - Input Hessian is not PD.

- enumerator FADAS\_CQP\_MAX\_ITERATIONS\_REACHED

    - Solver reaches max iterations.

- enumerator FADAS\_CQP\_INVALID\_INPUT

    - Invalid input to the solver.

- enumerator FADAS\_CQP\_RESULT\_INVALID

    - 

- enumerator FADAS\_CQP\_IEEE\_EXCEPTION

    - 

- enumerator FADAS\_CQP\_INTERNAL\_SOLVER\_ERROR

    - 

- enumerator FADAS\_CQP\_INIT

    - Initialization.

- enum FadasCQPSolverMode\_e

    - Convex QP Solver run mode.

- Param FADAS\_CQP\_MODE\_NORMAL:

    - Balance speed and precision.

- Param FADAS\_CQP\_MODE\_PRECISION:

    - Favor precision over speed.

*Values:*

- enumerator FADAS\_CQP\_MODE\_NORMAL

    - Balance speed and precision.

- enumerator FADAS\_CQP\_MODE\_PRECISION

    - Favor precision over speed.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_Init(const char \*licenseKey)

    - Initialize the Quadratic Programming Solver module. **WARNING:** Must be called once before other FastADAS functions except [FadasVersion()](https://docs.qualcomm.com/doc/80-63309-1/topic/misc.html#group__misc_1ga55cbdff48d751f2a0227ae4ac106d746).

- Parameters:

    - **licenseKey** – License key string.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_DeInit(void)

    - Deinitialize the Quadratic Programming Solver module. **WARNING:** Must be called once after all other FastADAS functions.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_IsHessianSymPosDef(uint32\_t n, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*hessianMatrix, bool \*bPostiveDef)

    - Validate symmetry and positive definiteness of Hessian matrix.

- Parameters:

    - - **n** – Number of variables in QP problem.
- **hessianMatrix** – Input Hessian matrix \((G)\) of n x n dimensions.
- **bPostiveDef** – Return bool value.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- void FadasCQP\_GetMemReq(uint32\_t n, uint32\_t m, uint32\_t m\_e, size\_t \*memSize, bool boundPresent = true)

    - Compute total memory required for internal buffers allocation.

- Parameters:

    - - **n** – Number of variables in QP problem.
- **m** – Number of constraints (equality + inequality) in QP problem.
- **m\_e** – Number of equality constraints in QP problem.
- **memSize** – Return value of required memory for allocation.
- **boundPresent** – Flag for presence of upper and lower bound constraints.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_Create(uint32\_t n, uint32\_t m, uint32\_t m\_e, size\_t memSize, void \*pScratchMem, [FadasHandle\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ae31515ec9878f0df582da37e4b413592.html#_CPPv413FadasHandle_t) \*phCQP, bool boundPresent = true)

    - Create and allocate internal buffers for CQP solver.

- Parameters:

    - - **n** – Number of variables in QP problem.
- **m** – Number of constraints (equality + inequality) in QP problem.
- **m\_e** – Number of equality constraints in QP problem.
- **memSize** – Size of externally allocated memory.
- **pScratchMem** – Pointer to externally allocated memory if any.
- **phCQP** – Handle to CQP solver.
- **boundPresent** – Flag for presence of upper and lower bound constraints.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_Destroy([FadasHandle\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ae31515ec9878f0df582da37e4b413592.html#_CPPv413FadasHandle_t) hCQP)

    - Function to release CQP solver resources.

- Parameters:

    - **hCQP** – Handle to CQP solver.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_SetMode([FadasHandle\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ae31515ec9878f0df582da37e4b413592.html#_CPPv413FadasHandle_t) hCQP, [FadasCQPSolverMode\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_group___c_q_p_s_1gad94c29e8a50fa7f6db2002e83dc0a013.html#_CPPv420FadasCQPSolverMode_e) runMode = [FADAS\_CQP\_MODE\_NORMAL](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_group___c_q_p_s_1gad94c29e8a50fa7f6db2002e83dc0a013.html#_CPPv4N20FadasCQPSolverMode_e21FADAS_CQP_MODE_NORMALE))

    - Set the run mode for a CQP solver.

- Parameters:

    - - **hCQP** – Handle to CQP solver.
- **runMode** – [FADAS\_CQP\_MODE\_NORMAL](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1ggad94c29e8a50fa7f6db2002e83dc0a013a1613e1d188d13f47bbd25423ed3c7dd9) — Default.

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- [FadasError\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#_CPPv412FadasError_e) FadasCQP\_Run([FadasHandle\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ae31515ec9878f0df582da37e4b413592.html#_CPPv413FadasHandle_t) hCQP, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*hessianMatrix, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*objectiveVector, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*constraintMatrix, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*constraintVector, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*lowerBoundVector, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*upperBoundVector, const size\_t maxIterations, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) violationTol, const [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) tolerance, [FadasCQPSolverResult\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/struct_fadas_c_q_p_solver_result__t.html#_CPPv422FadasCQPSolverResult_t) \*qpResults)

    - Solve a strictly convex quadratic program.

\[\begin{split}\begin{eqnarray\*} min.\, && \frac{1}{2} x^T G x - a^T x \\ \\ s.t.\, && C^T x - b \geq 0 \\ && x\_l \leq x \leq x\_u \\ \end{eqnarray\*}\end{split}\]

This routine uses the Goldfarb/Idnani dual algorithm [1].

[1] D. Goldfarb and A. Idnani (1983). A numerically stable dual method for solving strictly convex quadratic programs. Mathematical Programming, 27, 1-33.

- Parameters:

    - - **hessianMatrix** – Hessian matrix \((G)\) of n x n dimensions. Must be symmetric and positive definite.
- **objectiveVector** – Objective vector \((a)\) of n x 1 dimensions.
- **constraintMatrix** – Constraint matrix \((C)\) of n x m dimensions.
- **constraintVector** – Constraint vector \((b)\) of m x 1 dimensions.
- **lowerBoundVector** – Lower bound vector \((x\_l)\) of n x 1 dimensions.
- **upperBoundVector** – Upper bound vector \((x\_u)\) of n x 1 dimensions.
- **maxIterations** – Maximum number of iterations to terminate.
- **violationTol** – tolerance for non-negligible constraints violation, if \delta\_i is defined as the violation of the i-th constraint, then if \delta\_i &gt; violationTol, the corresponding constraint is violated.
- **tolerance** – Tolerance used to compute the maximum constraint violation at optimum.
- **qpResults** –

    - (return\_status) Receives information about the CQP solver termination [FADAS\_CQP\_SUCCESS](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1gga6ba628a400371267931f2443e97d08edacd8974ee11f84d8ddb00b9385c65e2d9), solution was found [FADAS\_CQP\_SOLUTION\_INFEASIBLE](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1gga6ba628a400371267931f2443e97d08eda1bc8f4eec7c994b8c7a809a5e678c559), the problem has no solution [FADAS\_CQP\_HESSIAN\_NOT\_PD](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1gga6ba628a400371267931f2443e97d08edaa2be884c51f4b2d48d3a772964a3a6fa), Hessian matrix is non-positive definite [FADAS\_CQP\_MAX\_ITERATIONS\_REACHED](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1gga6ba628a400371267931f2443e97d08edad40fd77902b082c41edd5c7b459965c0), Solver reaches maximum admissible number of iterations [FADAS\_CQP\_INVALID\_INPUT](https://docs.qualcomm.com/doc/80-63309-1/topic/convex-quadratic-programming.html#group___c_q_p_s_1gga6ba628a400371267931f2443e97d08eda02c5902c72cb64fde3a0ac36fac97a07), Invalid input provided to the solver
    - (optimizationResult) nx1 vector, receives the solution x to the minimization problem
    - (obj\_result) Receives the objective function value at the optimum
    - (required\_iterations) Receives the number of iterations to reach optimum

- Returns:

    - [FADAS\_ERROR\_NONE](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_fadas_8h_1a280abf443019bfc722ac1158e5fe1013.html#fadas_8h_1a280abf443019bfc722ac1158e5fe1013aea09a4171f0866f38326d7e5323f2d12) — Success.

- struct FadasCQPSolverResult\_t

    - Convex QP Solver Results.

- Param return\_status:

    - Receives information about the CQP solver termination defined in FadasCQPSolverStatus\_e.

- Param optimization\_result:

    - nx1 vector, receives the solution x to the minimization problem.

- Param obj\_result:

    - Receives the objective function value at optimum.

- Param required\_iterations:

    - Receives the number of iterations to reach optimum.

- Param reached\_tolerance:

    - Receives the maximum violation error at optimum.

Public Members

- [FadasCQPSolverStatus\_e](https://docs.qualcomm.com/doc/80-63309-1/topic/enum_group___c_q_p_s_1ga6ba628a400371267931f2443e97d08ed.html#_CPPv422FadasCQPSolverStatus_e) return\_status

    - 

- [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*optimization\_result

    - 

- [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) \*obj\_result

    - 

- uint32\_t \*required\_iterations

    - 

- [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) condition\_number

    - 

- [float64\_t](https://docs.qualcomm.com/doc/80-63309-1/topic/typedef_fadas_8h_1ac55f3ae81b5bc9053760baacf57e47f4.html#_CPPv49float64_t) reached\_tolerance

    -

## Related examples

- [cqp/app.cpp](https://docs.qualcomm.com/doc/80-63309-1/topic/cqp.html)
- [cqp\_basic/app.cpp](https://docs.qualcomm.com/doc/80-63309-1/topic/cqp-basic.html)

Last Published: Sep 30, 2024

[Previous Topic
Matrix Computations](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/matrix-computations.md) [Next Topic
Image Conversion](https://docs.qualcomm.com/bundle/publicresource/80-63309-1/topics/image-conversion.md)