Directory: | ./ |
---|---|
File: | include/hpp/constraints/implicit-constraint-set.hh |
Date: | 2025-05-05 12:19:30 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 28 | 28 | 100.0% |
Branches: | 21 | 38 | 55.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2016 - 2018 CNRS | ||
3 | // Authors: Joseph Mirabel, Florent Lamiraux | ||
4 | // | ||
5 | |||
6 | // Redistribution and use in source and binary forms, with or without | ||
7 | // modification, are permitted provided that the following conditions are | ||
8 | // met: | ||
9 | // | ||
10 | // 1. Redistributions of source code must retain the above copyright | ||
11 | // notice, this list of conditions and the following disclaimer. | ||
12 | // | ||
13 | // 2. Redistributions in binary form must reproduce the above copyright | ||
14 | // notice, this list of conditions and the following disclaimer in the | ||
15 | // documentation and/or other materials provided with the distribution. | ||
16 | // | ||
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
28 | // DAMAGE. | ||
29 | |||
30 | #ifndef HPP_CONSTRAINTS_IMPLICIT_CONSTRAINT_SET_HH | ||
31 | #define HPP_CONSTRAINTS_IMPLICIT_CONSTRAINT_SET_HH | ||
32 | |||
33 | #include <hpp/constraints/differentiable-function-set.hh> | ||
34 | #include <hpp/constraints/fwd.hh> | ||
35 | #include <hpp/constraints/implicit.hh> | ||
36 | |||
37 | namespace hpp { | ||
38 | namespace constraints { | ||
39 | /// \addtogroup constraints | ||
40 | /// \{ | ||
41 | |||
42 | /// Set of implicit constraints | ||
43 | /// | ||
44 | /// This class also handles selection of cols of the output matrix. | ||
45 | class HPP_CONSTRAINTS_DLLAPI ImplicitConstraintSet : public Implicit { | ||
46 | public: | ||
47 | typedef std::vector<ImplicitPtr_t> Implicits_t; | ||
48 | |||
49 | /// Return a shared pointer to a new instance | ||
50 | /// | ||
51 | /// \param name the name of the constraints, | ||
52 | static ImplicitConstraintSetPtr_t create(const std::string& name) { | ||
53 | return ImplicitConstraintSetPtr_t(new ImplicitConstraintSet(name)); | ||
54 | } | ||
55 | |||
56 | 4142 | virtual ~ImplicitConstraintSet() {} | |
57 | |||
58 | /// \name Function stack management | ||
59 | /// \{ | ||
60 | |||
61 | 1051 | void add(const ImplicitPtr_t& constraint) { | |
62 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1051 times.
|
1051 | assert(HPP_DYNAMIC_PTR_CAST(DifferentiableFunctionSet, function_)); |
63 | DifferentiableFunctionSetPtr_t functions( | ||
64 | 1051 | HPP_STATIC_PTR_CAST(DifferentiableFunctionSet, function_)); | |
65 |
1/2✓ Branch 4 taken 1051 times.
✗ Branch 5 not taken.
|
1051 | functions->add(constraint->functionPtr()); |
66 |
1/2✓ Branch 1 taken 1051 times.
✗ Branch 2 not taken.
|
1051 | constraints_.push_back(constraint); |
67 | // Handle comparison types | ||
68 |
1/2✓ Branch 2 taken 1051 times.
✗ Branch 3 not taken.
|
1051 | const ComparisonTypes_t& comp(constraint->comparisonType()); |
69 |
2/2✓ Branch 1 taken 10122 times.
✓ Branch 2 taken 1051 times.
|
11173 | for (std::size_t i = 0; i < comp.size(); ++i) { |
70 |
1/2✓ Branch 2 taken 10122 times.
✗ Branch 3 not taken.
|
10122 | comparison_.push_back(comp[i]); |
71 | } | ||
72 | // Handle mask | ||
73 |
1/2✓ Branch 6 taken 1051 times.
✗ Branch 7 not taken.
|
1051 | mask_.insert(mask_.end(), constraint->mask_.begin(), |
74 | 1051 | constraint->mask_.end()); | |
75 | // Recompute active rows | ||
76 |
1/2✓ Branch 1 taken 1051 times.
✗ Branch 2 not taken.
|
1051 | computeActiveRows(); |
77 |
1/2✓ Branch 1 taken 1051 times.
✗ Branch 2 not taken.
|
1051 | computeIndices(); |
78 | // Resize temporary variables | ||
79 |
1/2✓ Branch 3 taken 1051 times.
✗ Branch 4 not taken.
|
1051 | output_ = LiegroupElement(functions->outputSpace()); |
80 |
1/2✓ Branch 5 taken 1051 times.
✗ Branch 6 not taken.
|
1051 | logOutput_.resize(functions->outputSpace()->nv()); |
81 | 1051 | } | |
82 | |||
83 | /// Get constraints | ||
84 | 28029 | const Implicits_t& constraints() const { return constraints_; } | |
85 | |||
86 | /// The output columns selection of other is not taken into account. | ||
87 | void merge(const ImplicitConstraintSetPtr_t& other) { | ||
88 | const Implicits_t& constraints = other->constraints(); | ||
89 | for (Implicits_t::const_iterator constraint = constraints.begin(); | ||
90 | constraint != constraints.end(); ++constraint) | ||
91 | add(*constraint); | ||
92 | } | ||
93 | |||
94 | /// \} | ||
95 | |||
96 | std::ostream& print(std::ostream& os) const { | ||
97 | function_->print(os); | ||
98 | return os; | ||
99 | } | ||
100 | |||
101 | /// Constructor | ||
102 | /// | ||
103 | /// \param name the name of the constraints, | ||
104 | ImplicitConstraintSet(const std::string& name) | ||
105 | : Implicit(DifferentiableFunctionSet::create(name), ComparisonTypes_t(), | ||
106 | std::vector<bool>()) {} | ||
107 | |||
108 | 1032 | ImplicitConstraintSet() | |
109 |
2/4✓ Branch 2 taken 1032 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1032 times.
✗ Branch 6 not taken.
|
2064 | : Implicit(DifferentiableFunctionSet::create("Stack"), |
110 |
1/2✓ Branch 4 taken 1032 times.
✗ Branch 5 not taken.
|
3096 | ComparisonTypes_t(), std::vector<bool>()) {} |
111 | |||
112 | 1039 | ImplicitConstraintSet(const ImplicitConstraintSet& o) | |
113 |
2/4✓ Branch 2 taken 1039 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1039 times.
✗ Branch 6 not taken.
|
2078 | : Implicit(DifferentiableFunctionSet::create("Stack"), |
114 |
1/2✓ Branch 4 taken 1039 times.
✗ Branch 5 not taken.
|
3117 | ComparisonTypes_t(), std::vector<bool>()) { |
115 | 1039 | const Implicits_t& constraints = o.constraints(); | |
116 | 1039 | for (Implicits_t::const_iterator constraint = constraints.begin(); | |
117 |
2/2✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1039 times.
|
1048 | constraint != constraints.end(); ++constraint) |
118 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | add(*constraint); |
119 | 1039 | } | |
120 | |||
121 | private: | ||
122 | Implicits_t constraints_; | ||
123 | |||
124 | HPP_SERIALIZABLE(); | ||
125 | }; // class ImplicitConstraintSet | ||
126 | /// \} | ||
127 | } // namespace constraints | ||
128 | } // namespace hpp | ||
129 | |||
130 | #endif // HPP_CONSTRAINTS_IMPLICIT_CONSTRAINT_SET_HH | ||
131 |