hpp-constraints  4.9.1
Definition of basic geometric constraints for motion planning
by-substitution.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, 2018 CNRS
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 //
4 // This file is part of hpp-constraints.
5 // hpp-constraints 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-constraints 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-constraints. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HPP_CONSTRAINTS_SOLVER_BY_SUBSTITUTION_HH
18 #define HPP_CONSTRAINTS_SOLVER_BY_SUBSTITUTION_HH
19 
20 #include <vector>
21 
22 #include <hpp/constraints/fwd.hh>
23 #include <hpp/constraints/config.hh>
24 
28 
29 namespace hpp {
30  namespace constraints {
31  namespace solver {
34 
62  class HPP_CONSTRAINTS_DLLAPI BySubstitution
64  {
65  public:
66  BySubstitution (const LiegroupSpacePtr_t& configSpace);
67  BySubstitution (const BySubstitution& other);
68 
69  virtual ~BySubstitution () {}
70 
73 
76  {
77  return explicit_;
78  }
79 
82  {
83  return explicit_;
84  }
85 
88  {
89  return explicitConstraintSetHasChanged ();
90  }
92 
110  bool add (const ImplicitPtr_t& numericalConstraint,
111  const segments_t& passiveDofs = segments_t (0),
112  const std::size_t priority = 0);
113 
126  void add (const DifferentiableFunctionPtr_t& f,
127  const std::size_t& priority,
129 
132  {
133  return constraints_;
134  }
135 
138  {
139  return explicit_;
140  }
141 
144  {
145  return explicit_;
146  }
147 
155  virtual bool contains (const ImplicitPtr_t& numericalConstraint) const;
156 
159  {
160  return explicitConstraintSet().notOutDers().nbIndices();
161  }
162 
164  void explicitConstraintSetHasChanged();
165 
166  template <typename LineSearchType>
167  Status solve (vectorOut_t arg, LineSearchType ls = LineSearchType()) const
168  {
169  return solve <LineSearchType> (arg, false, ls);
170  }
171 
172  template <typename LineSearchType>
173  Status solve (vectorOut_t arg, bool optimize, LineSearchType ls = LineSearchType()) const
174  {
175  // TODO when there are only locked joint explicit constraints,
176  // there is no need for this intricated loop.
177  // if (explicit_.isConstant()) {
178  // explicit_.solve(arg);
179  // iterative_.solve(arg, ls);
180  // } else {
181  return impl_solve (arg, optimize, ls);
182  // }
183  }
184 
194  void projectVectorOnKernel (ConfigurationIn_t from, vectorIn_t velocity,
195  ConfigurationOut_t result) const;
196 
207  virtual void projectOnKernel (ConfigurationIn_t from,
209  ConfigurationOut_t result);
210 
211  inline Status solve (vectorOut_t arg) const
212  {
213  return solve(arg, DefaultLineSearch());
214  }
215 
218 
220  vector_t rightHandSideFromConfig (ConfigurationIn_t config);
221 
223  bool rightHandSideFromConfig (const ImplicitPtr_t& constraint,
224  ConfigurationIn_t config);
225 
227  bool rightHandSide (const ImplicitPtr_t& constraint,
228  vectorIn_t rhs);
229 
231  bool getRightHandSide (const ImplicitPtr_t& constraint,vectorOut_t rhs) const;
232 
234  void rightHandSide (vectorIn_t rhs);
235 
240  vector_t rightHandSide () const;
241 
243  size_type rightHandSideSize () const;
244 
246 
253  {
254  return dimension() + explicit_.outDers().nbIndices();
255  }
256 
259  bool isSatisfied (vectorIn_t arg) const
260  {
261  return
263  && explicit_.isSatisfied (arg);
264  }
265 
271  bool isSatisfied (vectorIn_t arg, vectorOut_t error) const
272  {
273  assert (error.size() == dimension() + explicit_.outDers().nbIndices());
274  bool iterative =
276  residualError(error.head(dimension()));
277  bool _explicit =
278  explicit_.isSatisfied (arg, error.tail(explicit_.outDers().nbIndices()));
279  return iterative && _explicit;
280  }
281 
291  bool isConstraintSatisfied (const ImplicitPtr_t& constraint,
292  vectorIn_t arg, vectorOut_t error,
293  bool& constraintFound) const;
294 
295  template <typename LineSearchType>
296  bool oneStep (vectorOut_t arg, LineSearchType& lineSearch) const
297  {
298  computeValue<true> (arg);
299  updateJacobian (arg);
300  computeDescentDirection ();
301  lineSearch (*this, arg, dq_);
302  explicit_.solve (arg);
304  }
305 
308  void updateJacobian (vectorIn_t arg) const;
309 
311  void errorThreshold (const value_type& threshold)
312  {
314  explicit_.errorThreshold(threshold);
315  }
318  {
320  }
321 
325  segments_t implicitDof () const;
326 
327  virtual std::ostream& print (std::ostream& os) const;
328 
329  bool integrate(vectorIn_t from, vectorIn_t velocity, vectorOut_t result)
330  const
331  {
332  bool res = solver::HierarchicalIterative::integrate(from, velocity, result);
333  explicit_.solve (result);
334  return res;
335  }
336 
337  protected:
338  void computeActiveRowsOfJ (std::size_t iStack);
339 
340  private:
342 
343  template <typename LineSearchType>
344  Status impl_solve (vectorOut_t arg, bool optimize, LineSearchType ls) const;
345 
346  ExplicitConstraintSet explicit_;
347  mutable matrix_t Je_, JeExpanded_;
348  }; // class BySubstitution
350 
351  inline std::ostream& operator<< (std::ostream& os, const BySubstitution& hs)
352  {
353  return hs.print(os);
354  }
355  } // namespace solver
356  } // namespace constraints
357 } // namespace hpp
358 
359 #endif // HPP_CONSTRAINTS_SOLVER_BY_SUBSTITUTION_HH
Status solve(vectorOut_t arg, LineSearchType ls=LineSearchType()) const
Definition: by-substitution.hh:167
pinocchio::vector_t vector_t
Definition: fwd.hh:45
bool integrate(vectorIn_t from, vectorIn_t velocity, vectorOut_t result) const
Definition: by-substitution.hh:329
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:46
pinocchio::ConfigurationOut_t ConfigurationOut_t
Definition: fwd.hh:89
void explicitSolverHasChanged() HPP_CONSTRAINTS_DEPRECATED
Definition: by-substitution.hh:87
value_type errorThreshold() const
Get error threshold.
Definition: by-substitution.hh:317
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition: fwd.hh:54
std::vector< segment_t > segments_t
Definition: fwd.hh:69
pinocchio::matrix_t matrix_t
Definition: fwd.hh:42
virtual ~BySubstitution()
Definition: by-substitution.hh:69
Status
Definition: hierarchical-iterative.hh:171
Definition: hierarchical-iterative.hh:63
pinocchio::ConfigurationIn_t ConfigurationIn_t
Definition: fwd.hh:88
std::vector< ComparisonType > ComparisonTypes_t
Definition: fwd.hh:170
const NumericalConstraints_t & numericalConstraints() const
Get the numerical constraints implicit and explicit.
Definition: by-substitution.hh:131
assert(d.lhs()._blocks()==d.rhs()._blocks())
std::ostream & operator<<(std::ostream &os, const BySubstitution &hs)
Definition: by-substitution.hh:351
ExplicitConstraintSet & explicitSolver() HPP_CONSTRAINTS_DEPRECATED
Definition: by-substitution.hh:75
bool isSatisfied(vectorIn_t arg) const
Definition: by-substitution.hh:259
bool isSatisfied(vectorIn_t arg, vectorOut_t error) const
Definition: by-substitution.hh:271
ExplicitConstraintSet & explicitConstraintSet()
Get explicit constraint set.
Definition: by-substitution.hh:137
bool isSatisfied(vectorIn_t arg) const
Definition: hierarchical-iterative.hh:302
boost::shared_ptr< DifferentiableFunction > DifferentiableFunctionPtr_t
Definition: fwd.hh:95
virtual std::ostream & print(std::ostream &os) const
value_type errorThreshold() const
Get error threshold.
Definition: hierarchical-iterative.hh:384
size_type errorSize() const
Definition: by-substitution.hh:252
Definition: by-substitution.hh:62
bool oneStep(vectorOut_t arg, LineSearchType &lineSearch) const
Definition: by-substitution.hh:296
pinocchio::vectorOut_t vectorOut_t
Definition: fwd.hh:47
Status solve(vectorOut_t arg, bool optimize, LineSearchType ls=LineSearchType()) const
Definition: by-substitution.hh:173
pinocchio::size_type size_type
Definition: fwd.hh:35
pinocchio::value_type value_type
Definition: fwd.hh:36
size_type numberFreeVariables() const
Return the number of free variables.
Definition: by-substitution.hh:158
void errorThreshold(const value_type &threshold)
Set error threshold.
Definition: by-substitution.hh:311
virtual bool integrate(vectorIn_t from, vectorIn_t velocity, vectorOut_t result) const
const ExplicitConstraintSet & explicitSolver() const HPP_CONSTRAINTS_DEPRECATED
Definition: by-substitution.hh:81
boost::shared_ptr< Implicit > ImplicitPtr_t
Definition: fwd.hh:157
Definition: hierarchical-iterative.hh:165
DifferentiableFunctionSet DifferentiableFunctionStack HPP_CONSTRAINTS_DEPRECATED
Definition: fwd.hh:99
const ExplicitConstraintSet & explicitConstraintSet() const
Set explicit constraint set.
Definition: by-substitution.hh:143
std::vector< constraints::ImplicitPtr_t > NumericalConstraints_t
Definition: fwd.hh:159
Definition: explicit-constraint-set.hh:93
Status solve(vectorOut_t arg) const
Definition: by-substitution.hh:211