hpp-core  6.0.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 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // 1. Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 
29 #ifndef HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
30 #define HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
31 
32 #include <hpp/core/fwd.hh>
34 
35 namespace hpp {
36 namespace core {
39 namespace pathOptimization {
62  typedef Eigen::JacobiSVD<matrix_t> Decomposition_t;
63  typedef Eigen::LLT<matrix_t, Eigen::Lower> LLT_t;
64 
71  QuadraticProgram(size_type inputSize, bool useProxqp = true)
72  : H(inputSize, inputSize),
73  b(inputSize),
74  dec(inputSize, inputSize, Eigen::ComputeThinU | Eigen::ComputeThinV),
75  xStar(inputSize),
76  accuracy_(1e-4),
77  useProxqp_(useProxqp) {
78  H.setZero();
79  b.setZero();
80  bIsZero = true;
81  }
82 
91  bool useProxqp = true)
92  : H(lc.PK.cols(), lc.PK.cols()),
93  b(lc.PK.cols()),
94  bIsZero(false),
95  dec(lc.PK.cols(), lc.PK.cols(),
96  Eigen::ComputeThinU | Eigen::ComputeThinV),
97  xStar(lc.PK.cols()),
98  accuracy_(1e-4),
99  useProxqp_(useProxqp) {
100  QP.reduced(lc, *this);
101  }
102 
104  : H(QP.H),
105  b(QP.b),
106  bIsZero(QP.bIsZero),
107  dec(QP.dec),
108  xStar(QP.xStar),
109  accuracy_(QP.accuracy_),
110  useProxqp_(QP.useProxqp_) {}
111 
113 
120  void accuracy(value_type acc) { accuracy_ = acc; }
126  value_type accuracy() const { return accuracy_; }
127  void addRows(const std::size_t& nbRows) {
128  H.conservativeResize(H.rows() + nbRows, H.cols());
129  b.conservativeResize(b.rows() + nbRows, b.cols());
130 
131  H.bottomRows(nbRows).setZero();
132  }
133 
136 
137  /*/ Compute the problem
138  * \f{eqnarray*}{
139  * \min & \frac{1}{2} * x^T H x + b^T x \\
140  * lc.J * x = lc.b
141  * \f}
142  **/
143  void reduced(const LinearConstraint& lc, QuadraticProgram& QPr) const {
144  matrix_t H_PK(H * lc.PK);
145  QPr.H.noalias() = lc.PK.transpose() * H_PK;
146  QPr.b.noalias() = H_PK.transpose() * lc.xStar;
147  if (!bIsZero) {
148  QPr.b.noalias() += lc.PK.transpose() * b;
149  }
150  QPr.bIsZero = false;
151  }
152 
153  void decompose();
154 
155  void solve() { xStar.noalias() = -dec.solve(b); }
156 
158 
161 
162  void computeLLT();
163 
171  double solve(const LinearConstraint& ce, const LinearConstraint& ci);
172 
174 
179  bool bIsZero;
181 
186  Eigen::VectorXi activeConstraint;
189 
197 };
198 } // namespace pathOptimization
199 } // namespace core
200 } // namespace hpp
201 
202 #endif // HPP_CORE_PATH_OPTIMIZATION_QUADRATIC_PROGRAM_HH
void solve()
Definition: quadratic-program.hh:155
vector_t xStar
Definition: quadratic-program.hh:193
void reduced(const LinearConstraint &lc, QuadraticProgram &QPr) const
Definition: quadratic-program.hh:143
QuadraticProgram(size_type inputSize, bool useProxqp=true)
Definition: quadratic-program.hh:71
Eigen::LLT< matrix_t, Eigen::Lower > LLT_t
Definition: quadratic-program.hh:63
bool useProxqp_
Definition: quadratic-program.hh:196
double solve(const LinearConstraint &ce, const LinearConstraint &ci)
bool bIsZero
Definition: quadratic-program.hh:179
value_type trace
Definition: quadratic-program.hh:185
void accuracy(value_type acc)
Definition: quadratic-program.hh:120
Eigen::VectorXi activeConstraint
Definition: quadratic-program.hh:186
Eigen::JacobiSVD< matrix_t > Decomposition_t
Definition: quadratic-program.hh:62
QuadraticProgram(const QuadraticProgram &QP)
Definition: quadratic-program.hh:103
Decomposition_t dec
Definition: quadratic-program.hh:192
QuadraticProgram(const QuadraticProgram &QP, const LinearConstraint &lc, bool useProxqp=true)
Definition: quadratic-program.hh:90
value_type accuracy() const
Definition: quadratic-program.hh:126
vector_t b
Definition: quadratic-program.hh:178
value_type accuracy_
Definition: quadratic-program.hh:195
void addRows(const std::size_t &nbRows)
Definition: quadratic-program.hh:127
matrix_t H
Definition: quadratic-program.hh:177
int activeSetSize
Definition: quadratic-program.hh:187
LLT_t llt
Definition: quadratic-program.hh:184
Definition: relative-motion.hh:115
pinocchio::value_type value_type
Definition: fwd.hh:174
pinocchio::vector_t vector_t
Definition: fwd.hh:220
pinocchio::size_type size_type
Definition: fwd.hh:173
pinocchio::matrix_t matrix_t
Definition: fwd.hh:162
Definition: bi-rrt-planner.hh:35
A linear constraint .
Definition: linear-constraint.hh:39
matrix_t PK
Projector onto .
Definition: linear-constraint.hh:139
vector_t xStar
is a particular solution.
Definition: linear-constraint.hh:141
Definition: quadratic-program.hh:61