math::QPSolver#

rb::math::QPSolver is the quadratic-programming helper used by advanced control and optimization code. The related QPSolverException is documented on this page because it is tightly coupled to solver setup and failure modes.

Header

Header

#include <rby1-sdk/math/qp_solver.h>

Declaration

Namespace

rb::math

Kind

class family

Primary role

Configure and solve constrained quadratic programs.

Public Member Functions

Method group

Purpose

Notes

Setup(...) and InitFunction()

Allocate the solver and initialize its problem dimensions.

Call before setting cost or constraints.

SetCostFunction(...) and AddCostFunction(...)

Define one or more least-squares cost terms.

AddCostFunction(...) augments an existing cost.

SetConstraintsFunction(...) and SetPrimalVariable(...)

Define bound and constraint data plus the initial guess.

Needed before solving most nontrivial problems.

Solve()

Execute the QP solve.

May throw or return failure information via the paired exception type.

Get*() accessors

Inspect the assembled matrices and bounds.

Useful for debugging a solver configuration.

Detailed Reference

class QPSolver#

Public Functions

QPSolver()#
~QPSolver()#
void AddCostFunction(const Eigen::MatrixXd &A, const Eigen::VectorXd &b)#
Eigen::MatrixXd GetAConst() const#
Eigen::MatrixXd GetACost() const#
Eigen::VectorXd GetBCost() const#
Eigen::VectorXd GetLowerBound() const#
Eigen::VectorXd GetUpperBound() const#
void InitFunction()#
void ResetIsFirst()#
void SetConstraintsFunction(const Eigen::MatrixXd &A, const Eigen::VectorXd &lb, const Eigen::VectorXd &ub)#
void SetCostFunction(const Eigen::MatrixXd &A, const Eigen::VectorXd &b)#
void SetPrimalVariable(const Eigen::VectorXd &pv)#
void Setup(int n_var, int n_const, double time_limit = 2e-3)#
Eigen::VectorXd Solve()#

Solve the QP problem

Throws:

QPSolverException

Returns:

Solution

class QPSolverException : public std::exception#

Public Functions

explicit QPSolverException(int error_code)#
int code() const noexcept#
const char *what() const noexcept override#

Public Static Functions

static std::string GenerateMessage(int code)#

Public Static Attributes

static unsigned int kStatusOffset = 100#

Related Types

Examples

  • optimal_control.cpp is the main end-to-end example for this solver path.