Eigen::OSQP Class Reference

Eigen wrapper class of osqp. The class wraps the c-library osqp for Eigen matrix. It accepts both dense and sparse matrix. To compute a QP, just set the number of variables and solve. More...

#include <eigen-osqp/OSQP.h>

Public Member Functions

 OSQP ()
 Default constructor. More...
 
 ~OSQP () noexcept=default
 Default destructor. More...
 
void admmStepRho (c_float rho) noexcept
 ADMM step rho. Default is 0.1. More...
 
c_float admmStepRho () const noexcept
 
void admmStepSigma (c_float sigma) noexcept
 ADMM step sigma. Default is 1e-6. More...
 
c_float admmStepSigma () const noexcept
 
void scalingIter (c_int scaling) noexcept
 Heuristic data scaling iterations. If 0, scaling disabled. Default is 10. More...
 
c_int scalingIter () const noexcept
 
void maxIter (c_int maxIter) noexcept
 Maximum number of iteration. Default is 4000. More...
 
c_int maxIter () const noexcept
 
void absConvergenceTol (c_float tol) noexcept
 Absolute convergence tolerance. Default is 1e-3. More...
 
c_float absConvergenceTol () const noexcept
 
void relConvergenceTol (c_float tol) noexcept
 Relative convergence tolerance. Default is 1e-3. More...
 
c_float relConvergenceTol () const noexcept
 
void primalInfeasibilityTol (c_float tol) noexcept
 Primal infeasibility tolerance. Default is 1e-4. More...
 
c_float primalInfeasibilityTol () const noexcept
 
void dualInfeasibilityTol (c_float tol) noexcept
 Dual infeasibility tolerance. Default is 1e-4. More...
 
c_float dualInfeasibilityTol () const noexcept
 
void relaxationParam (c_float alpha) noexcept
 Relaxation parameter. Default is 1.6. More...
 
c_float relaxationParam () const noexcept
 
void linearSystemSolver (linsys_solver_type solver) noexcept
 Linear solver. Default is QDLDL_SOLVER. More...
 
linsys_solver_type linearSystemSolver () const noexcept
 
void scaleTermination (bool doScaleTermination) noexcept
 Use scale termination criteria. Default is false. More...
 
bool scaleTermination () const noexcept
 
void checkTermination (c_int checkValue) noexcept
 check termination interval. If 0, termination checking is disabled. Default is 25. More...
 
c_int checkTermination () const noexcept
 
void warmStart (bool ws) noexcept
 Warm start. Default is true. More...
 
bool warmStart () const noexcept
 
void polish (bool doPolish) noexcept
 Polish ADMM solution. More...
 
bool polish () const noexcept
 
void polishDelta (c_float delta) noexcept
 Regularization parameter for polish. More...
 
c_float polishDelta () const noexcept
 
void polishRefineIter (c_int iter) noexcept
 Iterative refinement steps in polish. More...
 
c_int polishRefineIter () const noexcept
 
void verbose (bool doPrint) noexcept
 Write osqp progress. More...
 
bool verbose () const noexcept
 
void problem (int nrVar, int nrConstr)
 Set up the problem parameters. More...
 
const VectorDenseresult () const noexcept
 Return the qp result. More...
 
template<typename TQ , typename TA >
bool solve (const TQ &Q, const VectorConstRef &c, const TA &A, const VectorConstRef &AL, const VectorConstRef &AU, const VectorConstRef &XL, const VectorConstRef &XU)
 Solve the given problem. The function problem(int, int) needs to be called before calling this function. More...
 
template<typename TQ , typename TA >
bool solve (const TQ &Q, const VectorConstRef &c, const TA &A, const VectorConstRef &AL, const VectorConstRef &AU)
 Solve the given problem. The function problem(int, int) needs to be called before calling this function. More...
 
template<typename TQ >
bool solve (const TQ &Q, const VectorConstRef &c)
 Solve unconstrained problem. The function problem(int, int) needs to be called before calling this function. More...
 
c_int iter () const noexcept
 Get number of iterations taken. More...
 
void inform (std::ostream &os) const noexcept
 Print solver status. More...
 
c_int status () const noexcept
 Get solver status. More...
 
c_float costResult () const noexcept
 Get cost result. More...
 
c_float primalResidualNorm () const noexcept
 Get norm of primal residual. More...
 
c_float dualResidualNorm () const noexcept
 Get norm of dual residual. More...
 

Detailed Description

Eigen wrapper class of osqp. The class wraps the c-library osqp for Eigen matrix. It accepts both dense and sparse matrix. To compute a QP, just set the number of variables and solve.

Note
Dense matrix are converted to an osqp sparse representation. All zeros in it won't be deleted away.

Constructor & Destructor Documentation

◆ OSQP()

Eigen::OSQP::OSQP ( )

Default constructor.

◆ ~OSQP()

Eigen::OSQP::~OSQP ( )
defaultnoexcept

Default destructor.

Member Function Documentation

◆ absConvergenceTol() [1/2]

void Eigen::OSQP::absConvergenceTol ( c_float  tol)
inlinenoexcept

Absolute convergence tolerance. Default is 1e-3.

◆ absConvergenceTol() [2/2]

c_float Eigen::OSQP::absConvergenceTol ( ) const
inlinenoexcept

◆ admmStepRho() [1/2]

void Eigen::OSQP::admmStepRho ( c_float  rho)
inlinenoexcept

ADMM step rho. Default is 0.1.

◆ admmStepRho() [2/2]

c_float Eigen::OSQP::admmStepRho ( ) const
inlinenoexcept

◆ admmStepSigma() [1/2]

void Eigen::OSQP::admmStepSigma ( c_float  sigma)
inlinenoexcept

ADMM step sigma. Default is 1e-6.

◆ admmStepSigma() [2/2]

c_float Eigen::OSQP::admmStepSigma ( ) const
inlinenoexcept

◆ checkTermination() [1/2]

void Eigen::OSQP::checkTermination ( c_int  checkValue)
inlinenoexcept

check termination interval. If 0, termination checking is disabled. Default is 25.

◆ checkTermination() [2/2]

c_int Eigen::OSQP::checkTermination ( ) const
inlinenoexcept

◆ costResult()

c_float Eigen::OSQP::costResult ( ) const
inlinenoexcept

Get cost result.

◆ dualInfeasibilityTol() [1/2]

void Eigen::OSQP::dualInfeasibilityTol ( c_float  tol)
inlinenoexcept

Dual infeasibility tolerance. Default is 1e-4.

◆ dualInfeasibilityTol() [2/2]

c_float Eigen::OSQP::dualInfeasibilityTol ( ) const
inlinenoexcept

◆ dualResidualNorm()

c_float Eigen::OSQP::dualResidualNorm ( ) const
inlinenoexcept

Get norm of dual residual.

◆ inform()

void Eigen::OSQP::inform ( std::ostream &  os) const
inlinenoexcept

Print solver status.

◆ iter()

c_int Eigen::OSQP::iter ( ) const
inlinenoexcept

Get number of iterations taken.

◆ linearSystemSolver() [1/2]

void Eigen::OSQP::linearSystemSolver ( linsys_solver_type  solver)
inlinenoexcept

Linear solver. Default is QDLDL_SOLVER.

◆ linearSystemSolver() [2/2]

linsys_solver_type Eigen::OSQP::linearSystemSolver ( ) const
inlinenoexcept

◆ maxIter() [1/2]

void Eigen::OSQP::maxIter ( c_int  maxIter)
inlinenoexcept

Maximum number of iteration. Default is 4000.

References maxIter().

Referenced by maxIter().

◆ maxIter() [2/2]

c_int Eigen::OSQP::maxIter ( ) const
inlinenoexcept

◆ polish() [1/2]

void Eigen::OSQP::polish ( bool  doPolish)
inlinenoexcept

Polish ADMM solution.

◆ polish() [2/2]

bool Eigen::OSQP::polish ( ) const
inlinenoexcept

◆ polishDelta() [1/2]

void Eigen::OSQP::polishDelta ( c_float  delta)
inlinenoexcept

Regularization parameter for polish.

◆ polishDelta() [2/2]

c_float Eigen::OSQP::polishDelta ( ) const
inlinenoexcept

◆ polishRefineIter() [1/2]

void Eigen::OSQP::polishRefineIter ( c_int  iter)
inlinenoexcept

Iterative refinement steps in polish.

◆ polishRefineIter() [2/2]

c_int Eigen::OSQP::polishRefineIter ( ) const
inlinenoexcept

◆ primalInfeasibilityTol() [1/2]

void Eigen::OSQP::primalInfeasibilityTol ( c_float  tol)
inlinenoexcept

Primal infeasibility tolerance. Default is 1e-4.

◆ primalInfeasibilityTol() [2/2]

c_float Eigen::OSQP::primalInfeasibilityTol ( ) const
inlinenoexcept

◆ primalResidualNorm()

c_float Eigen::OSQP::primalResidualNorm ( ) const
inlinenoexcept

Get norm of primal residual.

◆ problem()

void Eigen::OSQP::problem ( int  nrVar,
int  nrConstr 
)

Set up the problem parameters.

Parameters
nrVarNumber of variable
nrConstrNumber of constraints

◆ relaxationParam() [1/2]

void Eigen::OSQP::relaxationParam ( c_float  alpha)
inlinenoexcept

Relaxation parameter. Default is 1.6.

◆ relaxationParam() [2/2]

c_float Eigen::OSQP::relaxationParam ( ) const
inlinenoexcept

◆ relConvergenceTol() [1/2]

void Eigen::OSQP::relConvergenceTol ( c_float  tol)
inlinenoexcept

Relative convergence tolerance. Default is 1e-3.

◆ relConvergenceTol() [2/2]

c_float Eigen::OSQP::relConvergenceTol ( ) const
inlinenoexcept

◆ result()

const VectorDense& Eigen::OSQP::result ( ) const
inlinenoexcept

Return the qp result.

Returns
Result (uninitialize vector if the qp fails)

◆ scaleTermination() [1/2]

void Eigen::OSQP::scaleTermination ( bool  doScaleTermination)
inlinenoexcept

Use scale termination criteria. Default is false.

◆ scaleTermination() [2/2]

bool Eigen::OSQP::scaleTermination ( ) const
inlinenoexcept

◆ scalingIter() [1/2]

void Eigen::OSQP::scalingIter ( c_int  scaling)
inlinenoexcept

Heuristic data scaling iterations. If 0, scaling disabled. Default is 10.

◆ scalingIter() [2/2]

c_int Eigen::OSQP::scalingIter ( ) const
inlinenoexcept

◆ solve() [1/3]

template<typename TQ , typename TA >
bool Eigen::OSQP::solve ( const TQ &  Q,
const VectorConstRef c,
const TA &  A,
const VectorConstRef AL,
const VectorConstRef AU,
const VectorConstRef XL,
const VectorConstRef XU 
)

Solve the given problem. The function problem(int, int) needs to be called before calling this function.

Template Parameters
TQMatrix type. Either a dense or compressed sparse matrix (or a reference to it).
TAMatrix type. Either a dense or compressed sparse matrix (or a reference to it).
Parameters
QQuadratic part of the cost.
cLinear part of the cost.
AConstraint matrix.
ALLower bound of the constraints.
AUUpper bound of the constraints.
XLLower bound of the variables.
XUUpper bound of the variables.

References Eigen::CSCMatrix::matrix(), Eigen::CSCMatrix::updateAndAddIdentity(), and Eigen::CSCMatrix::updateTriangularDefault().

◆ solve() [2/3]

template<typename TQ , typename TA >
bool Eigen::OSQP::solve ( const TQ &  Q,
const VectorConstRef c,
const TA &  A,
const VectorConstRef AL,
const VectorConstRef AU 
)

Solve the given problem. The function problem(int, int) needs to be called before calling this function.

Template Parameters
TQMatrix type. Either a dense or compressed sparse matrix (or a reference to it).
TAMatrix type. Either a dense or compressed sparse matrix (or a reference to it).
Parameters
QQuadratic part of the cost.
cLinear part of the cost.
AConstraint matrix.
ALLower bound of the constraints.
AUUpper bound of the constraints.

References Eigen::CSCMatrix::matrix(), Eigen::CSCMatrix::updateDefault(), and Eigen::CSCMatrix::updateTriangularDefault().

◆ solve() [3/3]

template<typename TQ >
bool Eigen::OSQP::solve ( const TQ &  Q,
const VectorConstRef c 
)

Solve unconstrained problem. The function problem(int, int) needs to be called before calling this function.

Template Parameters
TQMatrix type. Either a dense or compressed sparse matrix (or a reference to it).
Parameters
QQuadratic part of the cost.
cLinear part of the cost.

References Eigen::CSCMatrix::matrix(), and Eigen::CSCMatrix::updateTriangularDefault().

◆ status()

c_int Eigen::OSQP::status ( ) const
inlinenoexcept

Get solver status.

◆ verbose() [1/2]

void Eigen::OSQP::verbose ( bool  doPrint)
inlinenoexcept

Write osqp progress.

◆ verbose() [2/2]

bool Eigen::OSQP::verbose ( ) const
inlinenoexcept

◆ warmStart() [1/2]

void Eigen::OSQP::warmStart ( bool  ws)
inlinenoexcept

Warm start. Default is true.

◆ warmStart() [2/2]

bool Eigen::OSQP::warmStart ( ) const
inlinenoexcept