hpp-constraints  6.0.0
Definition of basic geometric constraints for motion planning
affine-function.hh
Go to the documentation of this file.
1 // Copyright (c) 2017, 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_CONSTRAINTS_AFFINE_FUNCTION_HH
30 #define HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
31 
34 #include <hpp/constraints/fwd.hh>
35 
36 namespace hpp {
37 namespace constraints {
38 
41 
48  public:
50  const std::string& name) {
51  IdentityPtr_t ptr(new Identity(space, name));
52  return ptr;
53  }
54 
55  Identity(const LiegroupSpacePtr_t space, const std::string& name)
56  : DifferentiableFunction(space->nq(), space->nv(), space, name) {}
57 
58  protected:
60  y.vector() = arg;
61  }
62 
63  void impl_jacobian(matrixOut_t J, vectorIn_t) const { J.setIdentity(); }
64 
65  bool isEqual(const DifferentiableFunction& other) const {
66  dynamic_cast<const Identity&>(other);
67  if (!DifferentiableFunction::isEqual(other)) return false;
68 
69  return true;
70  }
71 
72  private:
73  Identity() {}
74  HPP_SERIALIZABLE();
75 }; // class Identity
76 
82  public:
84  const std::string name = "LinearFunction") {
85  return AffineFunctionPtr_t(new AffineFunction(J, name));
86  }
87 
88  static AffineFunctionPtr_t create(const matrixIn_t& J, const vectorIn_t& b,
89  const std::string name = "LinearFunction") {
90  return AffineFunctionPtr_t(new AffineFunction(J, b, name));
91  }
92 
93  protected:
94  AffineFunction(const matrixIn_t& J, const std::string name = "LinearFunction")
95  : DifferentiableFunction(J.cols(), J.cols(), LiegroupSpace::Rn(J.rows()),
96  name),
97  J_(J),
98  b_(vector_t::Zero(J.rows())) {
99  init();
100  }
101 
103  const std::string name = "LinearFunction")
104  : DifferentiableFunction(J.cols(), J.cols(), LiegroupSpace::Rn(J.rows()),
105  name),
106  J_(J),
107  b_(b) {
108  init();
109  }
110 
111  bool isEqual(const DifferentiableFunction& other) const {
112  const AffineFunction& castother =
113  dynamic_cast<const AffineFunction&>(other);
114  if (!DifferentiableFunction::isEqual(other)) return false;
115 
116  if (J_ != castother.J_) return false;
117  if (b_ != castother.b_) return false;
118 
119  return true;
120  }
121 
122  private:
124  void impl_compute(LiegroupElementRef y, vectorIn_t x) const {
125  y.vector().noalias() = J_ * x + b_;
126  }
127 
128  void impl_jacobian(matrixOut_t jacobian, vectorIn_t) const { jacobian = J_; }
129 
130  void init() {
131  assert(J_.rows() == b_.rows());
132  activeParameters_ = (J_.array() != 0).colwise().any();
133  activeDerivativeParameters_ = activeParameters_;
134  }
135 
136  const matrix_t J_;
137  const vector_t b_;
138 
139  AffineFunction() {}
140  HPP_SERIALIZABLE();
141 }; // class AffineFunction
142 
148  public:
150  const vector_t& constant, const size_type& sizeIn,
151  const size_type& sizeInDer, const std::string name = "ConstantFunction") {
152  return ConstantFunctionPtr_t(
153  new ConstantFunction(constant, sizeIn, sizeInDer, name));
154  }
156  const LiegroupElement& element, const size_type& sizeIn,
157  const size_type& sizeInDer, const std::string name = "ConstantFunction") {
158  return ConstantFunctionPtr_t(
159  new ConstantFunction(element, sizeIn, sizeInDer, name));
160  }
161 
162  protected:
163  ConstantFunction(const vector_t& constant, const size_type& sizeIn,
164  const size_type& sizeInDer,
165  const std::string name = "ConstantFunction")
166  : DifferentiableFunction(sizeIn, sizeInDer,
167  LiegroupSpace::Rn(constant.rows()), name),
168  c_(constant, outputSpace()) {}
169 
170  ConstantFunction(const LiegroupElement& element, const size_type& sizeIn,
171  const size_type& sizeInDer,
172  const std::string name = "ConstantFunction")
173  : DifferentiableFunction(sizeIn, sizeInDer, element.space(), name),
174  c_(element) {}
175 
177  void impl_compute(LiegroupElementRef r, vectorIn_t) const { r = c_; }
178 
179  void impl_jacobian(matrixOut_t J, vectorIn_t) const { J.setZero(); }
180 
181  bool isEqual(const DifferentiableFunction& other) const {
182  const ConstantFunction& castother =
183  dynamic_cast<const ConstantFunction&>(other);
184  if (!DifferentiableFunction::isEqual(other)) return false;
185 
186  if (c_.vector() == castother.c_.vector()) return false;
187 
188  return true;
189  }
190 
192 
193  private:
194  ConstantFunction() {}
195  HPP_SERIALIZABLE();
196 }; // class ConstantFunction
197 
199 } // namespace constraints
200 } // namespace hpp
201 
202 #endif // HPP_CONSTRAINTS_AFFINE_FUNCTION_HH
Definition: affine-function.hh:81
AffineFunction(const matrixIn_t &J, const vectorIn_t &b, const std::string name="LinearFunction")
Definition: affine-function.hh:102
AffineFunction(const matrixIn_t &J, const std::string name="LinearFunction")
Definition: affine-function.hh:94
static AffineFunctionPtr_t create(const matrixIn_t &J, const std::string name="LinearFunction")
Definition: affine-function.hh:83
bool isEqual(const DifferentiableFunction &other) const
Definition: affine-function.hh:111
static AffineFunctionPtr_t create(const matrixIn_t &J, const vectorIn_t &b, const std::string name="LinearFunction")
Definition: affine-function.hh:88
Definition: differentiable-function.hh:63
virtual bool isEqual(const DifferentiableFunction &other) const
Definition: differentiable-function.hh:206
Definition: affine-function.hh:47
bool isEqual(const DifferentiableFunction &other) const
Definition: affine-function.hh:65
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition: affine-function.hh:63
static IdentityPtr_t create(const LiegroupSpacePtr_t space, const std::string &name)
Definition: affine-function.hh:49
Identity(const LiegroupSpacePtr_t space, const std::string &name)
Definition: affine-function.hh:55
void impl_compute(LiegroupElementRef y, vectorIn_t arg) const
User implementation of function evaluation.
Definition: affine-function.hh:59
#define HPP_CONSTRAINTS_DLLAPI
Definition: config.hh:88
assert(d.lhs()._blocks()==d.rhs()._blocks())
pinocchio::LiegroupElement LiegroupElement
Definition: fwd.hh:65
shared_ptr< AffineFunction > AffineFunctionPtr_t
Definition: fwd.hh:135
pinocchio::LiegroupSpace LiegroupSpace
Definition: fwd.hh:68
pinocchio::LiegroupSpacePtr_t LiegroupSpacePtr_t
Definition: fwd.hh:69
shared_ptr< ConstantFunction > ConstantFunctionPtr_t
Definition: fwd.hh:136
pinocchio::size_type size_type
Definition: fwd.hh:47
pinocchio::vectorIn_t vectorIn_t
Definition: fwd.hh:60
pinocchio::matrix_t matrix_t
Definition: fwd.hh:56
Eigen::Ref< matrix_t > matrixOut_t
Definition: fwd.hh:58
Eigen::Ref< const matrix_t > matrixIn_t
Definition: fwd.hh:57
pinocchio::vector_t vector_t
Definition: fwd.hh:59
pinocchio::LiegroupElementRef LiegroupElementRef
Definition: fwd.hh:66
shared_ptr< Identity > IdentityPtr_t
Definition: fwd.hh:134
Definition: active-set-differentiable-function.hh:36
Definition: affine-function.hh:147
ConstantFunction(const vector_t &constant, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:163
const LiegroupElement c_
Definition: affine-function.hh:191
static ConstantFunctionPtr_t create(const vector_t &constant, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:149
static ConstantFunctionPtr_t create(const LiegroupElement &element, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:155
void impl_compute(LiegroupElementRef r, vectorIn_t) const
User implementation of function evaluation.
Definition: affine-function.hh:177
bool isEqual(const DifferentiableFunction &other) const
Definition: affine-function.hh:181
void impl_jacobian(matrixOut_t J, vectorIn_t) const
Definition: affine-function.hh:179
ConstantFunction(const LiegroupElement &element, const size_type &sizeIn, const size_type &sizeInDer, const std::string name="ConstantFunction")
Definition: affine-function.hh:170