codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_IntervalMatrixBase.h
Go to the documentation of this file.
1
20
21// does not work.. template<typename OtherDerived1,typename OtherDerived2,typename U=Scalar,int R=RowsAtCompileTime,int C=ColsAtCompileTime>
22// does not work.. requires (
23// does not work.. IsIntervalDomain<U>
24// does not work.. && (!IsIntervalDomain<typename OtherDerived1::Scalar>)
25// does not work.. && (!IsIntervalDomain<typename OtherDerived2::Scalar>)
26// does not work.. && OtherDerived1::RowsAtCompileTime == R
27// does not work.. && OtherDerived2::RowsAtCompileTime == R
28// does not work.. && OtherDerived1::ColsAtCompileTime == C
29// does not work.. && OtherDerived2::ColsAtCompileTime == C)
30// does not work.. Matrix(MatrixBase<OtherDerived1> lb, MatrixBase<OtherDerived2> ub)
31// does not work.. : Matrix<U,R,C>(lb)
32
48template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
49 requires IsIntervalDomain<Scalar>
51 : Matrix<Scalar,R,C>(lb)
52{
53 assert_release(lb.size() == ub.size());
54
55 for(Index i = 0 ; i < this->size() ; i++)
56 {
57 auto& lbi = *(this->data()+i);
58 const auto& ubi = *(ub.data()+i);
59
60 if(lbi.lb() > ubi)
61 {
62 set_empty();
63 break;
64 }
65
66 else
67 lbi |= ubi;
68 }
69}
70
89template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
90 requires IsIntervalDomain<Scalar>
91Matrix(int r, int c, const double bounds[][2])
92 : Matrix<Scalar,R,C>(r,c)
93{
94 assert_release(r > 0 && c > 0);
95
96 Index k = 0;
97 for(Index i = 0 ; i < this->rows() ; i++)
98 for(Index j = 0 ; j < this->cols() ; j++)
99 {
100 (*this)(i,j) = codac2::Interval(bounds[k][0],bounds[k][1]);
101 k++;
102 }
103 assert_release(k == this->size() && "incorrect array size");
104}
105
113inline auto& init()
114{
115 for(Index i = 0 ; i < this->size() ; i++)
116 (this->data()+i)->init();
117 return *this;
118}
119
129template<int R=RowsAtCompileTime,int C=ColsAtCompileTime,typename OtherDerived>
130 requires IsIntervalDomain<Scalar>
131inline bool operator==(const MatrixBase<OtherDerived>& x) const
132{
133 return operator==(x.eval().template cast<codac2::Interval>());
134}
135
141inline void set_empty()
142 requires IsIntervalDomain<Scalar>
143{
145}
146
157inline auto& inflate(double r)
158 requires IsIntervalDomain<Scalar>
159{
160 assert_release(r >= 0.);
161
162 for(Index i = 0 ; i < this->size() ; i++)
163 (this->data()+i)->inflate(r);
164 return *this;
165}
166
178template<typename OtherDerived>
179 requires IsIntervalDomain<Scalar>
180inline auto& inflate(const MatrixBase<OtherDerived>& r)
181{
182 assert_release(this->size() == r.size());
183 assert_release(r.min_coeff() >= 0.);
184
185 for(Index i = 0 ; i < this->rows() ; i++)
186 for(Index j = 0 ; j < this->cols() ; j++)
187 (*this)(i,j).inflate(r(i,j));
188 return *this;
189}
190
204template<typename OtherDerived>
205inline auto& operator&=(const MatrixBase<OtherDerived>& x)
206{
207 assert_release(this->size() == x.size());
208
209 if constexpr(std::is_same_v<typename MatrixBase<OtherDerived>::Scalar,codac2::Interval>)
210 {
211 if(x.is_empty())
212 {
213 set_empty();
214 return *this;
215 }
216 }
217
218 for(Index i = 0 ; i < this->rows() ; i++)
219 for(Index j = 0 ; j < this->cols() ; j++)
220 (*this)(i,j) &= x(i,j);
221 return *this;
222}
223
237template<typename OtherDerived>
238inline auto& operator|=(const MatrixBase<OtherDerived>& x)
239{
240 assert_release(this->size() == x.size());
241
242 if constexpr(std::is_same_v<typename MatrixBase<OtherDerived>::Scalar,codac2::Interval>)
243 {
244 if(x.is_empty())
245 return *this;
246 }
247
248 for(Index i = 0 ; i < this->rows() ; i++)
249 for(Index j = 0 ; j < this->cols() ; j++)
250 (*this)(i,j) |= x(i,j);
251 return *this;
252}
253
263template<typename OtherDerived>
264inline auto operator&(const MatrixBase<OtherDerived>& x) const
265{
266 auto y = *this;
267 return y &= x;
268}
269
279template<typename OtherDerived>
280inline auto operator|(const MatrixBase<OtherDerived>& x) const
281{
282 auto y = *this;
283 return y |= x.template cast<codac2::Interval>();
284}
285
293template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
294 requires IsIntervalDomain<Scalar>
295inline static auto empty(Index r, Index c)
296{
297 assert_release(r >= 0 && c >= 0);
299}
300
313template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
314 requires IsIntervalDomain<Scalar>
315inline auto bisect(Index i, float ratio = 0.49) const
316{
317 assert_release(i >= 0 && i < this->size());
318 assert_release((this->data()+i)->is_bisectable());
319 assert_release(codac2::Interval(0,1).interior_contains(ratio));
320
321 auto p = std::make_pair(*this,*this);
322 auto pi = (this->data()+i)->bisect(ratio);
323 *(p.first.data()+i) = pi.first;
324 *(p.second.data()+i) = pi.second;
325 return p;
326}
327
337template<int R=RowsAtCompileTime,int C=ColsAtCompileTime>
338 requires IsIntervalDomain<Scalar>
339inline auto bisect_largest(float ratio = 0.49) const
340{
341 return bisect(this->max_diam_index(), ratio);
342}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:568
auto & operator&=(const MatrixBase< OtherDerived > &x)
Performs element-wise intersection assignment with another matrix.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:205
auto & inflate(double r)
Inflates all intervals in the matrix by a fixed radius.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:157
bool operator==(const MatrixBase< OtherDerived > &x) const
Compares this interval matrix with another matrix for equality.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:131
auto bisect(Index i, float ratio=0.49) const
Bisects the interval at the given index into two sub-interval matrices.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:315
void set_empty()
Marks the interval matrix as empty.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:141
auto bisect_largest(float ratio=0.49) const
Bisects the interval with the largest diameter in the matrix.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:339
Matrix(const Matrix< double, R, C > &lb, const Matrix< double, R, C > &ub)
Constructs an interval matrix from lower and upper bound matrices.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:50
auto & init()
Initializes all elements of the matrix with default intervals.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:113
auto & operator|=(const MatrixBase< OtherDerived > &x)
Performs element-wise union assignment with another matrix.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:238
auto operator&(const MatrixBase< OtherDerived > &x) const
Returns the element-wise intersection of this matrix with another.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:264
auto operator|(const MatrixBase< OtherDerived > &x) const
Returns the element-wise union of this matrix with another.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:280
Matrix()=delete
Deleted default constructor to prevent default instantiation when either the number of rows or column...
auto lb() const
Returns a matrix containing the lower bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:91
Index max_diam_index() const
Returns the index of the element with the maximum diameter.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:276
bool interior_contains(const Matrix< double, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks if the interior of this interval matrix contains the specified matrix x.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:426
bool is_bisectable() const
Checks whether at least one interval in the matrix is bisectable.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:923
auto ub() const
Returns a matrix containing the upper bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:103