Visual Servoing Platform  version 3.2.0 under development (2019-01-22)
vpQuadProg.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Quadratic Programming
33  *
34  * Authors:
35  * Olivier Kermorgant
36  *
37  *****************************************************************************/
38 
39 #ifndef vpQuadProgh
40 #define vpQuadProgh
41 
42 #include <vector>
43 #include <stdlib.h>
44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpMatrix.h>
46 #include <visp3/core/vpMatrixException.h>
47 #include <visp3/core/vpLinProg.h>
48 
73 class VISP_EXPORT vpQuadProg
74 {
75 public:
76 #ifdef VISP_HAVE_CPP11_COMPATIBILITY
77 
79  bool solveQPe(const vpMatrix &Q, const vpColVector &r,
80  vpColVector &x, const double &tol = 1e-6) const;
81 
82  bool solveQPi(const vpMatrix &Q, const vpColVector &r,
83  const vpMatrix &C, const vpColVector &d,
84  vpColVector &x,
85  const bool use_equality = false,
86  const double &tol = 1e-6);
87 
88  bool solveQP(const vpMatrix &Q, const vpColVector &r,
89  vpMatrix A, vpColVector b,
90  const vpMatrix &C, const vpColVector &d,
91  vpColVector &x, const double &tol = 1e-6);
93 
96  bool setEqualityConstraint(const vpMatrix &A, const vpColVector &b, const double &tol = 1e-6);
101  {
102  active.clear();
103  }
105 
106  static void fromCanonicalCost(const vpMatrix &H, const vpColVector &c, vpMatrix &Q, vpColVector &r, const double &tol = 1e-6);
107  static bool solveQPe(const vpMatrix &Q, const vpColVector &r,
108  vpMatrix A, vpColVector b,
109  vpColVector &x, const double &tol = 1e-6);
110 
111 protected:
115  std::vector<unsigned int> active;
119  std::vector<unsigned int> inactive;
128 
129  static bool solveByProjection(const vpMatrix &Q, const vpColVector &r,
130  vpMatrix &A, vpColVector &b,
131  vpColVector &x, const double &tol = 1e-6);
132 
148  static unsigned int checkDimensions(const vpMatrix &Q, const vpColVector &r,
149  const vpMatrix* A, const vpColVector* b,
150  const vpMatrix* C, const vpColVector* d,
151  const std::string fct)
152  {
153  // check data consistency
154  const unsigned int n = Q.getCols();
155  const bool Ab = (A != NULL && b != NULL && A->getRows());
156  const bool Cd = (C != NULL && d != NULL && C->getRows());
157 
158  if ( (Ab && n != A->getCols()) ||
159  (Cd && n != C->getCols()) ||
160  (Ab && A->getRows() != b->getRows()) ||
161  (Cd && C->getRows() != d->getRows()) ||
162  Q.getRows() != r.getRows())
163  {
164  std::cout << "vpQuadProg::" << fct << ": wrong dimension\n" <<
165  "Q: " << Q.getRows() << "x" << Q.getCols() << " - r: " << r.getRows() << std::endl;
166  if(Ab)
167  std::cout << "A: " << A->getRows() << "x" << A->getCols() << " - b: " << b->getRows() << std::endl;
168  if(Cd)
169  std::cout << "C: " << C->getRows() << "x" << C->getCols() << " - d: " << d->getRows() << std::endl;
171  }
172  return n;
173  }
174 #endif
175 };
176 #endif
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
vpColVector x1
Definition: vpQuadProg.h:123
unsigned int getCols() const
Definition: vpArray2D.h:146
std::vector< unsigned int > inactive
Definition: vpQuadProg.h:119
This class provides a solver for Quadratic Programs.
Definition: vpQuadProg.h:73
unsigned int getRows() const
Definition: vpArray2D.h:156
std::vector< unsigned int > active
Definition: vpQuadProg.h:115
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void resetActiveSet()
Definition: vpQuadProg.h:100
vpMatrix Z
Definition: vpQuadProg.h:127
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)
Definition: vpQuadProg.h:148