Visual Servoing Platform
version 3.6.1 under development (2024-11-15)
|
#include <visp3/core/vpQuadProg.h>
Public Member Functions | |
Instantiated solvers <br> | |
bool | solveQPe (const vpMatrix &Q, const vpColVector &r, vpColVector &x, const double &tol=1e-6) const |
bool | solveQPi (const vpMatrix &Q, const vpColVector &r, const vpMatrix &C, const vpColVector &d, vpColVector &x, bool use_equality=false, const double &tol=1e-6) |
bool | solveQP (const vpMatrix &Q, const vpColVector &r, vpMatrix A, vpColVector b, const vpMatrix &C, const vpColVector &d, vpColVector &x, const double &tol=1e-6) |
Managing sequential calls to solvers <br> | |
std::vector< unsigned int > | active |
std::vector< unsigned int > | inactive |
vpColVector | x1 |
vpMatrix | Z |
bool | setEqualityConstraint (const vpMatrix &A, const vpColVector &b, const double &tol=1e-6) |
void | resetActiveSet () |
static void | fromCanonicalCost (const vpMatrix &H, const vpColVector &c, vpMatrix &Q, vpColVector &r, const double &tol=1e-6) |
static bool | solveQPe (const vpMatrix &Q, const vpColVector &r, vpMatrix A, vpColVector b, vpColVector &x, const double &tol=1e-6) |
static vpColVector | solveSVDorQR (const vpMatrix &A, const vpColVector &b) |
static bool | solveByProjection (const vpMatrix &Q, const vpColVector &r, vpMatrix &A, vpColVector &b, vpColVector &x, const double &tol=1e-6) |
static unsigned int | checkDimensions (const vpMatrix &Q, const vpColVector &r, const vpMatrix *A, const vpColVector *b, const vpMatrix *C, const vpColVector *d, const std::string fct) |
This class provides a solver for Quadratic Programs.
The cost function is written under the form .
If a cost function is written under the canonical form then fromCanonicalCost() can be used to retrieve Q and r from H and c.
Equality constraints are solved through projection into the kernel.
Inequality constraints are solved with active sets.
In order to be used sequentially, the decomposition of the equality constraint may be stored. The last active set is always stored and used to warm start the next call.
Definition at line 70 of file vpQuadProg.h.
|
inlinestaticprotected |
Performs a dimension check of passed QP matrices and vectors.
If any inconsistency is detected, displays a summary and throws an exception.
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
A | : pointer to the equality matrix (if any, dimension m x n) |
b | : pointer to the equality vector (if any, dimension m) |
C | : pointer to the inequality matrix (if any, dimension p x n) |
d | : pointer to the inequality vector (if any, dimension p) |
fct | : name of the solver that called this function |
Definition at line 141 of file vpQuadProg.h.
References vpException::dimensionError, vpArray2D< Type >::getCols(), and vpArray2D< Type >::getRows().
Referenced by solveQP(), solveQPe(), and solveQPi().
|
static |
Changes a canonical quadratic cost to the formulation used by this class .
Computes such that and .
H | : canonical symmetric positive cost matrix (dimension n x n) |
c | : canonical cost vector (dimension n) |
Q | : custom cost matrix (dimension rank(H) x n) |
r | : custom cost vector (dimension rank(H)) |
tol | : tolerance to test ranks |
Here is an example:
Definition at line 95 of file vpQuadProg.cpp.
References vpException::dimensionError, vpMatrix::eigenValues(), vpException::functionNotImplementedError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpMatrixException::matrixError, vpMatrix::pseudoInverse(), vpMatrix::t(), and vpMatrix::transpose().
|
inline |
Resets the active set that was found by a previous call to solveQP() or solveQPi(), if any.
Definition at line 92 of file vpQuadProg.h.
bool vpQuadProg::setEqualityConstraint | ( | const vpMatrix & | A, |
const vpColVector & | b, | ||
const double & | tol = 1e-6 |
||
) |
Saves internally the column reduction of the passed equality constraint:
A | : equality matrix (dimension m x n) |
b | : equality vector (dimension m) |
tol | : tolerance to test the ranks |
Definition at line 147 of file vpQuadProg.cpp.
References vpLinProg::colReduction(), vpArray2D< Type >::getRows(), x1, and Z.
|
staticprotected |
Solves a Quadratic Program under equality constraints.
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
A | : equality matrix (dimension m x n) |
b | : equality vector (dimension m) |
x | : solution (dimension n) |
tol | : tolerance to test the ranks |
This function is for internal use, no dimension check is performed and A and b may be modified.
Definition at line 176 of file vpQuadProg.cpp.
References vpLinProg::colReduction(), vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and vpMatrix::solveBySVD().
Referenced by solveQPe(), and solveQPi().
bool vpQuadProg::solveQP | ( | const vpMatrix & | Q, |
const vpColVector & | r, | ||
vpMatrix | A, | ||
vpColVector | b, | ||
const vpMatrix & | C, | ||
const vpColVector & | d, | ||
vpColVector & | x, | ||
const double & | tol = 1e-6 |
||
) |
Solves a Quadratic Program under equality and inequality constraints.
If the equality constraints are the same between two calls, it is more efficient to use setEqualityConstraint() and solveQPi().
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
A | : equality matrix (dimension m x n) |
b | : equality vector (dimension m) |
C | : inequality matrix (dimension p x n) |
d | : inequality vector (dimension p) |
x | : solution (dimension n) |
tol | : tolerance to test the ranks |
Here is an example:
Definition at line 384 of file vpQuadProg.cpp.
References vpLinProg::allLesser(), checkDimensions(), vpLinProg::colReduction(), vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), and solveQPi().
bool vpQuadProg::solveQPe | ( | const vpMatrix & | Q, |
const vpColVector & | r, | ||
vpColVector & | x, | ||
const double & | tol = 1e-6 |
||
) | const |
Solves a Quadratic Program under previously stored equality constraints (setEqualityConstraint())
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
x | : solution (dimension n) |
tol | : Tolerance. |
Here is an example where the two following QPs are solved:
Definition at line 248 of file vpQuadProg.cpp.
References vpException::dimensionError, vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpMatrix::solveBySVD(), x1, and Z.
|
static |
Solves a Quadratic Program under equality constraints.
If the equality constraints are the same between two calls, it is more efficient to use setEqualityConstraint() and solveQPe().
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
A | : equality matrix (dimension m x n) |
b | : equality vector (dimension m) |
x | : solution (dimension n) |
tol | : tolerance to test the ranks |
Here is an example:
Definition at line 317 of file vpQuadProg.cpp.
References checkDimensions(), and solveByProjection().
bool vpQuadProg::solveQPi | ( | const vpMatrix & | Q, |
const vpColVector & | r, | ||
const vpMatrix & | C, | ||
const vpColVector & | d, | ||
vpColVector & | x, | ||
bool | use_equality = false , |
||
const double & | tol = 1e-6 |
||
) |
Solves a Quadratic Program under inequality constraints
Q | : cost matrix (dimension c x n) |
r | : cost vector (dimension c) |
C | : inequality matrix (dimension p x n) |
d | : inequality vector (dimension p) |
x | : solution (dimension n) |
use_equality | : if a previously saved equality constraint (setEqualityConstraint()) should be considered |
tol | : tolerance to test the ranks |
Here is an example:
Definition at line 458 of file vpQuadProg.cpp.
References active, vpLinProg::allGreater(), vpLinProg::allLesser(), vpLinProg::allZero(), checkDimensions(), vpColVector::extract(), vpArray2D< Type >::getCols(), vpMatrix::getRow(), vpArray2D< Type >::getRows(), inactive, vpMatrix::pseudoInverse(), vpColVector::resize(), vpArray2D< Type >::resize(), vpLinProg::simplex(), solveByProjection(), vpMatrix::transpose(), x1, and Z.
Referenced by solveQP().
|
staticprotected |
Pick either SVD (over-constrained) or QR (square or under-constrained)
Assumes A is full rank, hence uses SVD iif A has more row than columns.
A | : matrix (dimension m x n) |
b | : vector (dimension m) |
Definition at line 686 of file vpQuadProg.cpp.
References vpArray2D< Type >::getCols(), vpArray2D< Type >::getRows(), vpMatrix::solveByQR(), and vpMatrix::solveBySVD().
|
protected |
Active set from the last call to solveQP() or solveQPi(). Used for warm starting the next call.
Definition at line 104 of file vpQuadProg.h.
Referenced by solveQPi().
|
protected |
Inactive set from the last call to solveQP() or solveQPi(). Used for warm starting the next call.
Definition at line 109 of file vpQuadProg.h.
Referenced by solveQPi().
|
protected |
Stored particular solution from the last call to setEqualityConstraint().
Definition at line 114 of file vpQuadProg.h.
Referenced by setEqualityConstraint(), solveQPe(), and solveQPi().
|
protected |
Stored projection to the kernel from the last call to setEqualityConstraint().
Definition at line 119 of file vpQuadProg.h.
Referenced by setEqualityConstraint(), solveQPe(), and solveQPi().