codac 2.0.5
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 assert_release(ci->size() == this->size());
120 }
121 }
122
130 template<typename C>
131 requires IsCtcBaseOrPtr<C,X...>
132 CtcInter(std::initializer_list<C> ctcs)
133 : CtcInter(Collection<CtcBase<X...>>(ctcs))
134 { }
135
141 size_t nb() const
142 {
143 return _ctcs.size();
144 }
145
154 void contract(X&... x) const
155 {
156 for(const auto& ci : _ctcs)
157 {
158 ci->contract(x...);
159 if((x.is_empty() | ...))
160 return;
161 }
162 }
163
174 template<typename C>
175 requires IsCtcBaseOrPtr<C,X...>
176 CtcInter<X...>& operator&=(const C& c)
177 {
178 assert_release(size_of(c) == this->size());
179 _ctcs.push_back(c);
180 return *this;
181 }
182
183 protected:
184
186 Collection<CtcBase<X...>> _ctcs;
187 };
188
195 template <>
196 class CtcInter<> : public CtcInter<IntervalVector>
197 { };
198
204 template<typename Tuple>
206
212 template<typename... T>
213 struct CtcInterType<std::tuple<T...>> {
214 using Ctc = CtcInter<T...>;
215 };
216
228 template<typename C1,typename C2>
230 {
231 return { c1, c2 };
232 }
233
243 template<typename C1,typename C2>
244 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const std::shared_ptr<C2>& c2)
245 {
246 return { c1, c2 };
247 }
248
258 template<typename C1,typename C2>
259 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const C2& c2)
260 {
261 return { c1, c2 };
262 }
263
273 template<typename C1,typename C2>
274 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const std::shared_ptr<C2>& c2)
275 {
276 return { c1, c2 };
277 }
278
289 template<typename C2>
290 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
291 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
292 {
293 assert_release(c1.size() == c2.size());
294 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
295 }
296
307 template<typename C1>
308 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
309 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
310 {
311 assert_release(c1.size() == c2.size());
312 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
313 }
314
315 // Template deduction guides
316
317 CtcInter(Index) -> CtcInter<IntervalVector>;
318
319 template<typename... C>
320 requires (IsCtcBaseOrPtr<C,IntervalVector> && ...)
321 CtcInter(const C&...) -> CtcInter<IntervalVector>;
322
323 template<typename C>
324 CtcInter(std::initializer_list<C>) -> CtcInter<IntervalVector>;
325}
Sequential intersection of several contractors:
Definition codac2_CtcInter.h:55
size_t nb() const
Returns the number of stored contractors.
Definition codac2_CtcInter.h:141
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:186
CtcInter< X... > & operator&=(const C &c)
Appends a contractor to the current intersection.
Definition codac2_CtcInter.h:176
CtcInter(std::initializer_list< C > ctcs)
Builds an intersection contractor from a std::initializer_list of contractors.
Definition codac2_CtcInter.h:132
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:154
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:229
Helper meta-function returning the appropriate CtcInter type from a tuple.
Definition codac2_CtcInter.h:205