ocra-recipes
Doxygen documentation for the ocra-recipes repository
Functions
QuadProgPP Namespace Reference

Functions

double solve_quadprog (const Eigen::MatrixXd &_G, const Eigen::VectorXd &g0, const Eigen::MatrixXd &_CE, const Eigen::VectorXd &ce0, const Eigen::MatrixXd &_CI, const Eigen::VectorXd &ci0, Eigen::VectorXd &x)
 
void compute_d (Eigen::VectorXd &d, const Eigen::MatrixXd &J, const Eigen::VectorXd &np)
 
void update_z (Eigen::VectorXd &z, const Eigen::MatrixXd &J, const Eigen::VectorXd &d, int iq)
 
void update_r (const Eigen::MatrixXd &R, Eigen::VectorXd &r, const Eigen::VectorXd &d, int iq)
 
bool add_constraint (Eigen::MatrixXd &R, Eigen::MatrixXd &J, Eigen::VectorXd &d, int &iq, double &rnorm)
 
void delete_constraint (Eigen::MatrixXd &R, Eigen::MatrixXd &J, Eigen::VectorXi &A, Eigen::VectorXd &u, int n, int p, int &iq, int l)
 
void cholesky_decomposition (Eigen::MatrixXd &A)
 
void cholesky_solve (const Eigen::MatrixXd &L, Eigen::VectorXd &x, const Eigen::VectorXd &b)
 
void forward_elimination (const Eigen::MatrixXd &L, Eigen::VectorXd &y, const Eigen::VectorXd &b)
 
void backward_elimination (const Eigen::MatrixXd &U, Eigen::VectorXd &x, const Eigen::VectorXd &y)
 
double scalar_product (const Eigen::VectorXd &x, const Eigen::VectorXd &y)
 
double distance (double a, double b)
 
void print_matrix (const char *name, const Eigen::MatrixXd &A, int n=-1, int m=-1)
 
template<typename T >
void print_vector (const char *name, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, int n=-1)
 

Function Documentation

bool QuadProgPP::add_constraint ( Eigen::MatrixXd &  R,
Eigen::MatrixXd &  J,
Eigen::VectorXd &  d,
int &  iq,
double &  rnorm 
)

Definition at line 566 of file QuadProg++.cpp.

void QuadProgPP::backward_elimination ( const Eigen::MatrixXd &  U,
Eigen::VectorXd &  x,
const Eigen::VectorXd &  y 
)
inline

Definition at line 804 of file QuadProg++.cpp.

void QuadProgPP::cholesky_decomposition ( Eigen::MatrixXd &  A)

Definition at line 745 of file QuadProg++.cpp.

void QuadProgPP::cholesky_solve ( const Eigen::MatrixXd &  L,
Eigen::VectorXd &  x,
const Eigen::VectorXd &  b 
)

Definition at line 778 of file QuadProg++.cpp.

void QuadProgPP::compute_d ( Eigen::VectorXd &  d,
const Eigen::MatrixXd &  J,
const Eigen::VectorXd &  np 
)
inline

Definition at line 523 of file QuadProg++.cpp.

void QuadProgPP::delete_constraint ( Eigen::MatrixXd &  R,
Eigen::MatrixXd &  J,
Eigen::VectorXi &  A,
Eigen::VectorXd &  u,
int  n,
int  p,
int &  iq,
int  l 
)

Definition at line 637 of file QuadProg++.cpp.

double QuadProgPP::distance ( double  a,
double  b 
)
inline

Definition at line 714 of file QuadProg++.cpp.

void QuadProgPP::forward_elimination ( const Eigen::MatrixXd &  L,
Eigen::VectorXd &  y,
const Eigen::VectorXd &  b 
)
inline

Definition at line 790 of file QuadProg++.cpp.

void QuadProgPP::print_matrix ( const char *  name,
const Eigen::MatrixXd &  A,
int  n = -1,
int  m = -1 
)

Definition at line 818 of file QuadProg++.cpp.

template<typename T >
void QuadProgPP::print_vector ( const char *  name,
const Eigen::Matrix< T, Eigen::Dynamic, 1 > &  v,
int  n = -1 
)

Definition at line 842 of file QuadProg++.cpp.

double QuadProgPP::scalar_product ( const Eigen::VectorXd &  x,
const Eigen::VectorXd &  y 
)
inline

Definition at line 734 of file QuadProg++.cpp.

double QuadProgPP::solve_quadprog ( const Eigen::MatrixXd &  _G,
const Eigen::VectorXd &  g0,
const Eigen::MatrixXd &  _CE,
const Eigen::VectorXd &  ce0,
const Eigen::MatrixXd &  _CI,
const Eigen::VectorXd &  ci0,
Eigen::VectorXd &  x 
)

The quadprog_solve() function implements the algorithm of Goldfarb and Idnani for the solution of a (convex) Quadratic Programming problem by means of an active-set dual method.

The quadratic problem with $n$ variables and $m$ constraints is:

\begin{align*} \argmin{\x} &: \; \frac{1}{2} \x\tp G \x + \vec{g}_0\tp \x \\ & CE\tp \x + \vec{ce}_0 = \vec{0} \\ & CI\tp \x + \vec{ci}_0 \geq \vec{0} \end{align*}

The matrix and vectors dimensions are as follows:

$G$: $n \times n$

$\vec{g}_0$: $n$

$CE$: $n \times p$

$\vec{ce}_0$: $p$

$CI$: $n \times m$

$\vec{ci}_0$: $m$

$x$: $n$

The function will return the cost of the solution written in the $x$ vector or std::numeric_limits::infinity() if the problem is infeasible. In the latter case the value of the $x$ vector is not correct.

Parameters
_Gn x n Symmetric positive definite matrix.
g0Vector of size n, where n is the number of variables.
_CEMatrix of size n x p, where p is the number of equalities.
ce0Vector of size p.
_CIMatrix of size n x m, where m is the number of inequalities.
ci0Vector of size m.
xProblem variables of size n.
Note
Pay attention in setting up the vectors $\vec{ce}_0$ and $\vec{ci}_0$. If the constraints of your problem are specified in the form $A^T x = b$ and $C^T x \geq d$, then you should set $\vec{ce}_0 = -b$ and $\vec{ci}_0 = -d$. Also the matrix $G$ is modified within the function since it is used to compute the $G = L^T L$ cholesky factorization for further computations inside the function. If you need the original matrix $G$ you should make a copy of it and pass the copy to the function. [goldfarb1983numerically]
Returns
cost of the solution written in the x vector or std::numeric_limits::infinity() if the problem is infeasible. In the latter case the value of the $ x $ vector is not correct.
Author
Luca Di Gaspero, DIEGM - University of Udine, Italy.

Definition at line 75 of file QuadProg++.cpp.

void QuadProgPP::update_r ( const Eigen::MatrixXd &  R,
Eigen::VectorXd &  r,
const Eigen::VectorXd &  d,
int  iq 
)
inline

Definition at line 551 of file QuadProg++.cpp.

void QuadProgPP::update_z ( Eigen::VectorXd &  z,
const Eigen::MatrixXd &  J,
const Eigen::VectorXd &  d,
int  iq 
)
inline

Definition at line 538 of file QuadProg++.cpp.