Line |
Branch |
Exec |
Source |
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_CONSTRAINTS_FUNCTION_DIFFERENCE_HH |
30 |
|
|
#define HPP_CONSTRAINTS_FUNCTION_DIFFERENCE_HH |
31 |
|
|
|
32 |
|
|
#include <hpp/constraints/config.hh> |
33 |
|
|
#include <hpp/constraints/differentiable-function.hh> |
34 |
|
|
#include <hpp/constraints/fwd.hh> |
35 |
|
|
|
36 |
|
|
namespace hpp { |
37 |
|
|
namespace constraints { |
38 |
|
|
namespace function { |
39 |
|
|
class Difference; |
40 |
|
|
typedef shared_ptr<Difference> DifferencePtr_t; |
41 |
|
|
|
42 |
|
|
/// Compute the difference between the value of the function in two points. |
43 |
|
|
/// i.e.: \f$ f (q_0, ... , q_n) = f_{inner} (q_{left}) - f_{inner} (q_{right}) |
44 |
|
|
/// \f$ |
45 |
|
|
class HPP_CONSTRAINTS_LOCAL Difference |
46 |
|
|
: public constraints::DifferentiableFunction { |
47 |
|
|
public: |
48 |
|
|
typedef shared_ptr<Difference> Ptr_t; |
49 |
|
|
/// Constructor |
50 |
|
|
/// |
51 |
|
|
/// \param inner function f, |
52 |
|
|
/// \param nArgs, nDers size of the input space of this function, |
53 |
|
|
/// \param lInArgs, lInders configuration and velocity intervals defining |
54 |
|
|
/// \f$q_{left}\f$, |
55 |
|
|
/// \param rInArgs, rInders configuration and velocity intervals defining |
56 |
|
|
/// \f$q_{right}\f$, |
57 |
|
|
Difference(const DifferentiableFunctionPtr_t& inner, const size_type& nArgs, |
58 |
|
|
const size_type& nDers, const segment_t& lInArgs, |
59 |
|
|
const segment_t& lInDers, const segment_t& rInArgs, |
60 |
|
|
const segment_t& rInDers); |
61 |
|
|
|
62 |
|
|
protected: |
63 |
|
✗ |
void impl_compute(LiegroupElementRef y, vectorIn_t arg) const { |
64 |
|
✗ |
inner_->value(l_, arg.segment(lsa_.first, lsa_.second)); |
65 |
|
✗ |
inner_->value(r_, arg.segment(rsa_.first, rsa_.second)); |
66 |
|
✗ |
y.vector() = l_ - r_; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
✗ |
void impl_jacobian(matrixOut_t J, vectorIn_t arg) const { |
70 |
|
✗ |
inner_->jacobian(J.middleCols(lsd_.first, lsd_.second), |
71 |
|
✗ |
arg.segment(lsa_.first, lsa_.second)); |
72 |
|
✗ |
inner_->jacobian(J.middleCols(rsd_.first, rsd_.second), |
73 |
|
✗ |
arg.segment(rsa_.first, rsa_.second)); |
74 |
|
✗ |
J.middleCols(rsd_.first, rsd_.second) *= -1; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
✗ |
bool isEqual(const DifferentiableFunction& other) const { |
78 |
|
✗ |
const Difference& castother = dynamic_cast<const Difference&>(other); |
79 |
|
✗ |
if (!DifferentiableFunction::isEqual(other)) return false; |
80 |
|
|
|
81 |
|
✗ |
if (inner_ != castother.inner_) return false; |
82 |
|
✗ |
if (lsa_ != castother.lsa_) return false; |
83 |
|
✗ |
if (lsd_ != castother.lsd_) return false; |
84 |
|
✗ |
if (rsa_ != castother.rsa_) return false; |
85 |
|
✗ |
if (rsd_ != castother.rsd_) return false; |
86 |
|
|
|
87 |
|
✗ |
return true; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
std::ostream& print(std::ostream& os) const; |
91 |
|
|
|
92 |
|
|
DifferentiableFunctionPtr_t inner_; |
93 |
|
|
const segment_t lsa_, lsd_; |
94 |
|
|
const segment_t rsa_, rsd_; |
95 |
|
|
|
96 |
|
|
mutable LiegroupElement l_, r_; |
97 |
|
|
}; // class Difference |
98 |
|
|
} // namespace function |
99 |
|
|
} // namespace constraints |
100 |
|
|
} // namespace hpp |
101 |
|
|
|
102 |
|
|
#endif // HPP_CONSTRAINTS_FUNCTION_DIFFERENCE_HH |
103 |
|
|
|