hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
quadratic-program.hh
Go to the documentation of this file.
1 // Copyright (c) 2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-core.
5 // hpp-core is free software: you can redistribute it
6 // and/or modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation, either version
8 // 3 of the License, or (at your option) any later version.
9 //
10 // hpp-core is distributed in the hope that it will be
11 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Lesser Public License for more details. You should have
14 // received a copy of the GNU Lesser General Public License along with
15 // hpp-core. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
18 # define HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
19 
20 #include <hpp/core/fwd.hh>
21 
23 
24 namespace hpp {
25  namespace core {
28  namespace pathOptimization {
29  /*/ Quadratic program
30  *
31  * This class stores a quadratic cost defined by
32  * \f$ 0.5 * x^T H x + b^T x \f$ where \f$ (H, b) \f$ are the parameters.
33  *
34  * It can then solve the two following program:
35  * \li Program subject to linear equality constraints
36  * \f{eqnarray*}{
37  * min & 0.5 * x^T H x + b^T x \\
38  * & A_0 * x = b_0
39  * \f}
40  * This is done via \ref reduced, \ref decompose and \ref solve methods
41  * \li Program subject to linear equality and inequality constraints:
42  * \f{eqnarray*}{
43  * min & 0.5 * x^T H x + b^T x \\
44  * & A_0 * x = b_0 \\
45  * & A_1 * x \ge b_1
46  * \f}
47  * This is done via \ref computeLLT and \ref solve methods
48  * and uses quadprog
49  **/
51  {
52  typedef Eigen::JacobiSVD < matrix_t > Decomposition_t;
53  typedef Eigen::LLT <matrix_t, Eigen::Lower> LLT_t;
54 
56  H (inputSize, inputSize), b (inputSize),
57  dec (inputSize, inputSize, Eigen::ComputeThinU | Eigen::ComputeThinV),
58  xStar (inputSize)
59  {
60  H.setZero();
61  b.setZero();
62  bIsZero = true;
63  }
64 
66  H (lc.PK.cols(), lc.PK.cols()), b (lc.PK.cols()), bIsZero (false),
67  dec (lc.PK.cols(), lc.PK.cols(), Eigen::ComputeThinU | Eigen::ComputeThinV),
68  xStar (lc.PK.cols())
69  {
70  QP.reduced (lc, *this);
71  }
72 
74  H (QP.H), b (QP.b), bIsZero (QP.bIsZero),
75  dec (QP.dec), xStar (QP.xStar)
76  {}
77 
79 
80  void addRows (const std::size_t& nbRows)
81  {
82  H.conservativeResize(H.rows() + nbRows, H.cols());
83  b.conservativeResize(b.rows() + nbRows, b.cols());
84 
85  H.bottomRows(nbRows).setZero();
86  }
87 
90 
91  /*/ Compute the problem
92  * \f{eqnarray*}{
93  * min & 0.5 * x^T H x + b^T x \\
94  * & lc.J * x = lc.b
95  * \f}
96  **/
97  void reduced (const LinearConstraint& lc, QuadraticProgram& QPr) const
98  {
99  matrix_t H_PK (H * lc.PK);
100  QPr.H.noalias() = lc.PK.transpose() * H_PK;
101  QPr.b.noalias() = H_PK.transpose() * lc.xStar;
102  if (!bIsZero) {
103  QPr.b.noalias() += lc.PK.transpose() * b;
104  }
105  QPr.bIsZero = false;
106  }
107 
108  void decompose ();
109 
110  void solve ()
111  {
112  xStar.noalias() = - dec.solve(b);
113  }
114 
116 
119 
120  void computeLLT();
121 
126  double solve(const LinearConstraint& ce, const LinearConstraint& ci);
127 
129 
134  bool bIsZero;
136 
139  LLT_t llt;
141  Eigen::VectorXi activeConstraint;
144 
147  Decomposition_t dec;
150  };
151  } // namespace pathOptimization
152  } // namespace core
153 } // namespace hpp
154 
155 #endif // HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
void solve()
Definition: quadratic-program.hh:110
QuadraticProgram(const QuadraticProgram &QP, const LinearConstraint &lc)
Definition: quadratic-program.hh:65
pinocchio::size_type size_type
Definition: fwd.hh:156
Eigen::JacobiSVD< matrix_t > Decomposition_t
Definition: quadratic-program.hh:52
void addRows(const std::size_t &nbRows)
Definition: quadratic-program.hh:80
matrix_t H
Definition: quadratic-program.hh:132
LLT_t llt
Definition: quadratic-program.hh:139
QuadraticProgram(const QuadraticProgram &QP)
Definition: quadratic-program.hh:73
vector_t b
Definition: quadratic-program.hh:133
vector_t xStar
Definition: quadratic-program.hh:148
pinocchio::matrix_t matrix_t
Definition: fwd.hh:145
pinocchio::vector_t vector_t
Definition: fwd.hh:201
pinocchio::value_type value_type
Definition: fwd.hh:157
Definition: quadratic-program.hh:50
Decomposition_t dec
Definition: quadratic-program.hh:147
int activeSetSize
Definition: quadratic-program.hh:142
QuadraticProgram(size_type inputSize)
Definition: quadratic-program.hh:55
Eigen::LLT< matrix_t, Eigen::Lower > LLT_t
Definition: quadratic-program.hh:53
bool bIsZero
Definition: quadratic-program.hh:134
A linear constraint .
Definition: linear-constraint.hh:28
vector_t xStar
is a particular solution.
Definition: linear-constraint.hh:131
matrix_t PK
Projector onto .
Definition: linear-constraint.hh:129
Eigen::VectorXi activeConstraint
Definition: quadratic-program.hh:141
value_type trace
Definition: quadratic-program.hh:140
void reduced(const LinearConstraint &lc, QuadraticProgram &QPr) const
Definition: quadratic-program.hh:97