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<IntervalVector>>& 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
128 size_t nb() const
129 {
130 return _ctcs.size();
131 }
132
141 void contract(X&... x) const
142 {
143 for(const auto& ci : _ctcs)
144 {
145 ci->contract(x...);
146 if((x.is_empty() | ...))
147 return;
148 }
149 }
150
161 template<typename C>
162 requires IsCtcBaseOrPtr<C,X...>
163 CtcInter<X...>& operator&=(const C& c)
164 {
165 assert_release(size_of(c) == this->size());
166 _ctcs.push_back(c);
167 return *this;
168 }
169
170 protected:
171
173 Collection<CtcBase<X...>> _ctcs;
174 };
175
182 template <>
183 class CtcInter<> : public CtcInter<IntervalVector>
184 { };
185
191 template<typename Tuple>
193
199 template<typename... T>
200 struct CtcInterType<std::tuple<T...>> {
201 using Ctc = CtcInter<T...>;
202 };
203
215 template<typename C1,typename C2>
217 {
218 return { c1, c2 };
219 }
220
230 template<typename C1,typename C2>
231 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const std::shared_ptr<C2>& c2)
232 {
233 return { c1, c2 };
234 }
235
245 template<typename C1,typename C2>
246 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const C2& c2)
247 {
248 return { c1, c2 };
249 }
250
260 template<typename C1,typename C2>
261 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const std::shared_ptr<C2>& c2)
262 {
263 return { c1, c2 };
264 }
265
276 template<typename C2>
277 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
278 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
279 {
280 assert_release(c1.size() == c2.size());
281 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
282 }
283
294 template<typename C1>
295 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
296 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
297 {
298 assert_release(c1.size() == c2.size());
299 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
300 }
301
302 // Template deduction guides
303
304 CtcInter(Index) -> CtcInter<IntervalVector>;
305}
Sequential intersection of several contractors:
Definition codac2_CtcInter.h:55
size_t nb() const
Returns the number of stored contractors.
Definition codac2_CtcInter.h:128
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:173
CtcInter< X... > & operator&=(const C &c)
Appends a contractor to the current intersection.
Definition codac2_CtcInter.h:163
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:141
CtcInter(const Collection< CtcBase< IntervalVector > > &ctcs)
Builds an intersection contractor from a collection of contractors.
Definition codac2_CtcInter.h:114
CtcInter(Index n)
Builds a neutral intersection contractor with a prescribed domain size.
Definition codac2_CtcInter.h:68
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
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:216
Helper meta-function returning the appropriate CtcInter type from a tuple.
Definition codac2_CtcInter.h:192