hpp-core  4.9.0
Implement basic classes for canonical path planning for kinematic chains.
linear-constraint.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, 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_SPLINE_GRADIENT_BASED_LINEAR_CONSTRAINT_HH
18 #define HPP_CORE_PATH_OPTIMIZATION_SPLINE_GRADIENT_BASED_LINEAR_CONSTRAINT_HH
19 
20 #include <hpp/core/fwd.hh>
21 
22 #include <hpp/util/debug.hh>
23 
24 namespace hpp {
25  namespace core {
26  namespace pathOptimization {
29  {
30  LinearConstraint (size_type inputSize, size_type outputSize) :
31  J (outputSize, inputSize), b (outputSize),
32  xSol (inputSize)
33  {
34  J.setZero();
35  b.setZero();
36  }
37 
39 
40  void concatenate (const LinearConstraint& oc)
41  {
42  assert(oc.J.cols() == J.cols());
43  J.conservativeResize (J.rows() + oc.J.rows(), J.cols());
44  J.bottomRows(oc.J.rows()) = oc.J;
45  b.conservativeResize (b.rows() + oc.b.rows());
46  b.tail(oc.b.rows()) = oc.b;
47  }
48 
54  bool decompose (bool check = false, bool throwIfNotValid = false);
55 
57  void computeRank ()
58  {
59  if (J.size() == 0) rank = 0;
60  else {
61  Eigen::FullPivLU <matrix_t> lu (J);
62  rank = lu.rank();
63  }
64  }
65 
72  bool reduceConstraint (const LinearConstraint& lc, LinearConstraint& lcr, bool computeRank = true) const
73  {
74  lcr.J.noalias() = lc.J * PK;
75  lcr.b.noalias() = lc.b - lc.J * xStar;
76 
77  // Decompose
78  if (computeRank) {
79  lcr.computeRank();
80  return lcr.rank == std::min(lcr.J.rows(), lcr.J.cols());
81  } else return true;
82  }
83 
88  void computeSolution (const vector_t& v)
89  {
90  xSol.noalias() = xStar + PK * v;
91 #ifdef HPP_DEBUG
93 #endif // HPP_DEBUG
94  }
95 
97  bool isSatisfied (const vector_t& x, const value_type& threshold = Eigen::NumTraits<value_type>::dummy_precision())
98  {
99  vector_t err (J * x - b);
100  if (err.isZero(threshold)) return true;
101  hppDout (error, "constraints could not be satisfied: " << err.norm() << '\n' << err);
102  return false;
103  }
104 
105  void addRows (const std::size_t& nbRows)
106  {
107  if (nbRows > 0) {
108  J.conservativeResize(J.rows() + nbRows, J.cols());
109  b.conservativeResize(b.rows() + nbRows);
110 
111  J.bottomRows(nbRows).setZero();
112  }
113  }
114 
120 
124 
127 
132 
134  };
135  } // namespace pathOptimization
136  } // namespace core
137 } // namespace hpp
138 
139 #endif // HPP_CORE_PATH_OPTIMIZATION_SPLINE_GRADIENT_BASED_LINEAR_CONSTRAINT_HH
void concatenate(const LinearConstraint &oc)
Definition: linear-constraint.hh:40
#define hppDout(channel, data)
bool decompose(bool check=false, bool throwIfNotValid=false)
pinocchio::size_type size_type
Definition: fwd.hh:156
matrix_t J
Definition: linear-constraint.hh:117
vector_t xSol
Definition: linear-constraint.hh:131
LinearConstraint(size_type inputSize, size_type outputSize)
Definition: linear-constraint.hh:30
void addRows(const std::size_t &nbRows)
Definition: linear-constraint.hh:105
assert(d.lhs()._blocks()==d.rhs()._blocks())
bool isSatisfied(const vector_t &x, const value_type &threshold=Eigen::NumTraits< value_type >::dummy_precision())
Returns .
Definition: linear-constraint.hh:97
vector_t b
Definition: linear-constraint.hh:118
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
bool reduceConstraint(const LinearConstraint &lc, LinearConstraint &lcr, bool computeRank=true) const
Definition: linear-constraint.hh:72
void computeRank()
Compute rank of the constraint using a LU decomposition.
Definition: linear-constraint.hh:57
size_type rank
Rank of J.
Definition: linear-constraint.hh:126
void computeSolution(const vector_t &v)
Definition: linear-constraint.hh:88
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