codac 2.0.0
Loading...
Searching...
No Matches
codac2_CtcInter.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <type_traits>
13#include "codac2_CtcWrapper.h"
14#include "codac2_Collection.h"
16
17namespace codac2
18{
53 template<typename... X>
54 class CtcInter : public Ctc<CtcInter<X...>,X...>
55 {
56 public:
57
68 explicit CtcInter(Index n)
69 : Ctc<CtcInter<X...>,X...>(n)
70 {
71 if constexpr(std::is_same_v<X...,Interval>)
72 {
73 assert(n == 1);
74 }
75 }
76
85 template<typename C>
86 requires (IsCtcBaseOrPtr<C,X...> && !std::is_same_v<CtcInter<X...>,C>)
87 CtcInter(const C& c)
88 : Ctc<CtcInter<X...>,X...>(size_of(c)), _ctcs(c)
89 { }
90
99 template<typename... C>
100 requires (IsCtcBaseOrPtr<C,X...> && ...)
101 CtcInter(const C&... c)
102 : Ctc<CtcInter<X...>,X...>(size_first_item(c...)), _ctcs(c...)
103 {
104 assert_release(all_same_size(c...));
105 }
106
114 CtcInter(const Collection<CtcBase<X...>>& ctcs)
115 : Ctc<CtcInter<X...>,X...>(ctcs.front()->size()), _ctcs(ctcs)
116 {
117 for(const auto& ci : _ctcs)
118 {
119 (void)ci;
120 assert_release(ci->size() == this->size());
121 }
122 }
123
131 template<typename C>
132 requires IsCtcBaseOrPtr<C,X...>
133 CtcInter(std::initializer_list<C> ctcs)
134 : CtcInter(Collection<CtcBase<X...>>(ctcs))
135 { }
136
142 size_t nb() const
143 {
144 return _ctcs.size();
145 }
146
155 void contract(X&... x) const
156 {
157 for(const auto& ci : _ctcs)
158 {
159 ci->contract(x...);
160 if((x.is_empty() | ...))
161 return;
162 }
163 }
164
175 template<typename C>
176 requires IsCtcBaseOrPtr<C,X...>
177 CtcInter<X...>& operator&=(const C& c)
178 {
179 assert_release(size_of(c) == this->size());
180 _ctcs.push_back(c);
181 return *this;
182 }
183
184 protected:
185
187 Collection<CtcBase<X...>> _ctcs;
188 };
189
196 template <>
197 class CtcInter<> : public CtcInter<IntervalVector>
198 { };
199
205 template<typename Tuple>
207
213 template<typename... T>
214 struct CtcInterType<std::tuple<T...>> {
215 using Ctc = CtcInter<T...>;
216 };
217
229 template<typename C1,typename C2>
231 {
232 return { c1, c2 };
233 }
234
244 template<typename C1,typename C2>
245 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const std::shared_ptr<C2>& c2)
246 {
247 return { c1, c2 };
248 }
249
259 template<typename C1,typename C2>
260 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const C2& c2)
261 {
262 return { c1, c2 };
263 }
264
274 template<typename C1,typename C2>
275 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const std::shared_ptr<C2>& c2)
276 {
277 return { c1, c2 };
278 }
279
290 template<typename C2>
291 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
292 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
293 {
294 assert_release(c1.size() == c2.size());
295 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
296 }
297
308 template<typename C1>
309 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
310 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
311 {
312 assert_release(c1.size() == c2.size());
313 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
314 }
315
316 // Template deduction guides
317
318 CtcInter(Index) -> CtcInter<IntervalVector>;
319
320 template<typename... C>
321 requires (IsCtcBaseOrPtr<C,IntervalVector> && ...)
322 CtcInter(const C&...) -> CtcInter<IntervalVector>;
323
324 template<typename C>
325 CtcInter(std::initializer_list<C>) -> CtcInter<IntervalVector>;
326}
Sequential intersection of several contractors:
Definition codac2_CtcInter.h:55
size_t nb() const
Returns the number of stored contractors.
Definition codac2_CtcInter.h:142
CtcInter(const C &c)
Builds an intersection contractor from a single contractor.
Definition codac2_CtcInter.h:87
Collection< CtcBase< X... > > _ctcs
Definition codac2_CtcInter.h:187
CtcInter< X... > & operator&=(const C &c)
Appends a contractor to the current intersection.
Definition codac2_CtcInter.h:177
CtcInter(std::initializer_list< C > ctcs)
Builds an intersection contractor from a std::initializer_list of contractors.
Definition codac2_CtcInter.h:133
CtcInter(const C &... c)
Builds an intersection contractor from several contractors.
Definition codac2_CtcInter.h:101
void contract(X &... x) const
Contracts the given domain(s) by applying all stored contractors in sequence.
Definition codac2_CtcInter.h:155
CtcInter(Index n)
Builds a neutral intersection contractor with a prescribed domain size.
Definition codac2_CtcInter.h:68
CtcInter(const Collection< CtcBase< X... > > &ctcs)
Builds an intersection contractor from a collection of contractors.
Definition codac2_CtcInter.h:114
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:50
Definition codac2_OctaSym.h:21
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
CtcInterType< typenameC1::ContractedTypes >::Ctc operator&(const C1 &c1, const C2 &c2)
Builds an intersection contractor from two contractors.
Definition codac2_CtcInter.h:230
Helper meta-function returning the appropriate CtcInter type from a tuple.
Definition codac2_CtcInter.h:206