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
112 size_t nb() const
113 {
114 return _ctcs.size();
115 }
116
125 void contract(X&... x) const
126 {
127 for(const auto& ci : _ctcs)
128 {
129 ci->contract(x...);
130 if((x.is_empty() | ...))
131 return;
132 }
133 }
134
145 template<typename C>
146 requires IsCtcBaseOrPtr<C,X...>
147 CtcInter<X...>& operator&=(const C& c)
148 {
149 assert_release(size_of(c) == this->size());
150 _ctcs.push_back(c);
151 return *this;
152 }
153
154 protected:
155
157 Collection<CtcBase<X...>> _ctcs;
158 };
159
166 template <>
167 class CtcInter<> : public CtcInter<IntervalVector>
168 { };
169
175 template<typename Tuple>
177
183 template<typename... T>
184 struct CtcInterType<std::tuple<T...>> {
185 using Ctc = CtcInter<T...>;
186 };
187
199 template<typename C1,typename C2>
201 {
202 return { c1, c2 };
203 }
204
214 template<typename C1,typename C2>
215 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const std::shared_ptr<C2>& c2)
216 {
217 return { c1, c2 };
218 }
219
229 template<typename C1,typename C2>
230 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const std::shared_ptr<C1>& c1, const C2& c2)
231 {
232 return { c1, c2 };
233 }
234
244 template<typename C1,typename C2>
245 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const std::shared_ptr<C2>& c2)
246 {
247 return { c1, c2 };
248 }
249
260 template<typename C2>
261 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
262 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
263 {
264 assert_release(c1.size() == c2.size());
265 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
266 }
267
278 template<typename C1>
279 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
280 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
281 {
282 assert_release(c1.size() == c2.size());
283 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
284 }
285
286 // Template deduction guides
287
288 CtcInter(Index) -> CtcInter<IntervalVector>;
289}
Sequential intersection of several contractors:
Definition codac2_CtcInter.h:55
size_t nb() const
Returns the number of stored contractors.
Definition codac2_CtcInter.h:112
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:157
CtcInter< X... > & operator&=(const C &c)
Appends a contractor to the current intersection.
Definition codac2_CtcInter.h:147
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:125
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:200
Helper meta-function returning the appropriate CtcInter type from a tuple.
Definition codac2_CtcInter.h:176