codac 2.0.0
Loading...
Searching...
No Matches
codac2_MatrixBase_addons_IntervalMatrixBase.h
Go to the documentation of this file.
1
20
31template<typename U=Scalar>
32 requires IsIntervalDomain<U>
33inline double volume() const
34{
35 if(this->is_empty())
36 return 0.;
37
38 double v = 0.;
39 for(Index i = 0 ; i < this->rows() ; i++)
40 for(Index j = 0 ; j < this->cols() ; j++)
41 {
42 if((*this)(i,j).is_unbounded()) return codac2::oo;
43 if((*this)(i,j).is_degenerated()) return 0.;
44 v += std::log((*this)(i,j).diam());
45 }
46 return std::exp(v);
47}
48
56inline bool is_empty() const
57{
58 for(Index i = 0 ; i < rows() ; i++)
59 for(Index j = 0 ; j < cols() ; j++)
60 if((*this)(i,j).is_empty())
61 return true;
62 return false;
63}
64
69#define degenerate_mat(op) \
70 Matrix<double,RowsAtCompileTime,ColsAtCompileTime> m(this->rows(),this->cols()); \
71 \
72 if(this->is_empty()) \
73 m.init(std::numeric_limits<double>::quiet_NaN()); \
74 \
75 else \
76 { \
77 for(Index i = 0 ; i < this->rows() ; i++) \
78 for(Index j = 0 ; j < this->cols() ; j++) \
79 m(i,j) = (*this)(i,j).op(); \
80 } \
81 \
82 return m; \
83
84
89template<typename U=Scalar>
90 requires IsIntervalDomain<U>
91inline auto lb() const
92{
94}
95
101template<typename U=Scalar>
102 requires IsIntervalDomain<U>
103inline auto ub() const
104{
106}
107
115template<typename U=Scalar>
116 requires IsIntervalDomain<U>
117inline auto mid() const
118{
120}
121
129template<typename U=Scalar>
130 requires IsIntervalDomain<U>
131inline auto mag() const
132{
134}
135
141template<typename U=Scalar>
142 requires IsIntervalDomain<U>
143inline auto mig() const
144{
146}
147
155template<typename U=Scalar>
156 requires IsIntervalDomain<U>
157inline auto rand() const
158{
160}
161
169template<typename U=Scalar>
170 requires IsIntervalDomain<U>
171inline auto rad() const
172{
174}
175
183template<typename U=Scalar>
184 requires IsIntervalDomain<U>
185inline auto diam() const
186{
188}
189
199{
200 return _contains(x);
201}
202
209template<typename OtherDerived>
210inline bool contains(const MatrixBase<OtherDerived>& x) const
211{
212 return _contains(x);
213}
214
218template<typename T>
219inline bool _contains(const T& x) const
220{
221 assert_release(x.size() == this->size());
222
223 if(this->is_empty())
224 return false;
225
226 for(Index i = 0 ; i < this->rows() ; i++)
227 for(Index j = 0 ; j < this->cols() ; j++)
228 if(!(*this)(i,j).contains(x(i,j)))
229 return false;
230
231 return true;
232}
233
246
253template<typename OtherDerived>
254inline bool interior_contains(const MatrixBase<OtherDerived>& x) const
255{
256 return _interior_contains(x);
257}
258
262template<typename T>
263inline bool _interior_contains(const T& x) const
264{
265 assert_release(x.size() == this->size());
266
267 if(this->is_empty())
268 return false;
269
270 for(Index i = 0 ; i < this->rows() ; i++)
271 for(Index j = 0 ; j < this->cols() ; j++)
272 if(!(*this)(i,j).interior_contains(x(i,j)))
273 return false;
274
275 return true;
276}
277
283inline bool is_unbounded() const
284{
285 if(this->is_empty()) return false;
286 for(Index i = 0 ; i < this->rows() ; i++)
287 for(Index j = 0 ; j < this->cols() ; j++)
288 if((*this)(i,j).is_unbounded())
289 return true;
290 return false;
291}
292
300inline bool is_degenerated() const
301{
302 for(Index i = 0 ; i < this->rows() ; i++)
303 for(Index j = 0 ; j < this->cols() ; j++)
304 if(!(*this)(i,j).is_degenerated())
305 return false;
306 return true;
307}
308
317inline bool is_flat() const
318{
319 if(this->is_empty()) return true;
320 for(Index i = 0 ; i < this->rows() ; i++)
321 for(Index j = 0 ; j < this->cols() ; j++)
322 if((*this)(i,j).is_degenerated()) // don't use diam() because of roundoff
323 return true;
324 return false;
325}
326
339
346template<typename OtherDerived>
347inline bool intersects(const MatrixBase<OtherDerived>& x) const
348{
349 return _intersects(x);
350}
351
355template<typename OtherDerived>
356inline bool _intersects(const MatrixBase<OtherDerived>& x) const
357{
358 assert_release(this->size() == x.size());
359
360 if(this->is_empty())
361 return false;
362
363 for(Index i = 0 ; i < this->rows() ; i++)
364 for(Index j = 0 ; j < this->cols() ; j++)
365 if(!(*this)(i,j).intersects(x(i,j)))
366 return false;
367
368 return true;
369}
370
383
390template<typename OtherDerived>
391inline bool is_disjoint(const MatrixBase<OtherDerived>& x) const
392{
393 return _is_disjoint(x);
394}
395
399template<typename OtherDerived>
400inline bool _is_disjoint(const MatrixBase<OtherDerived>& x) const
401{
402 assert_release(this->size() == x.size());
403
404 if(this->is_empty())
405 return true;
406
407 for(Index i = 0 ; i < this->rows() ; i++)
408 for(Index j = 0 ; j < this->cols() ; j++)
409 if((*this)(i,j).is_disjoint(x(i,j)))
410 return true;
411
412 return false;
413}
414
424{
425 return _overlaps(x);
426}
427
434template<typename OtherDerived>
435inline bool overlaps(const MatrixBase<OtherDerived>& x) const
436{
437 return _overlaps(x);
438}
439
443template<typename OtherDerived>
444inline bool _overlaps(const MatrixBase<OtherDerived>& x) const
445{
446 assert_release(this->size() == x.size());
447
448 if(this->is_empty())
449 return false;
450
451 for(Index i = 0 ; i < this->rows() ; i++)
452 for(Index j = 0 ; j < this->cols() ; j++)
453 if(!(*this)(i,j).overlaps(x(i,j)))
454 return false;
455
456 return true;
457}
458
469{
470 return _is_subset(x);
471}
472
479template<typename OtherDerived>
480inline bool is_subset(const MatrixBase<OtherDerived>& x) const
481{
482 return _is_subset(x);
483}
484
488template<typename T>
489inline bool _is_subset(const T& x) const
490{
491 assert_release(this->size() == x.size());
492
493 if(this->is_empty())
494 return true;
495
496 for(Index i = 0 ; i < this->rows() ; i++)
497 for(Index j = 0 ; j < this->cols() ; j++)
498 if(!(*this)(i,j).is_subset(x(i,j)))
499 return false;
500
501 return true;
502}
503
516
523template<typename OtherDerived>
524inline bool is_strict_subset(const MatrixBase<OtherDerived>& x) const
525{
526 return _is_strict_subset(x);
527}
528
532template<typename T>
533inline bool _is_strict_subset(const T& x) const
534{
535 assert_release(this->size() == x.size());
536
537 if(this->is_empty())
538 return true;
539
540 if(!is_subset(x))
541 return false;
542
543 for(Index i = 0 ; i < this->rows() ; i++)
544 for(Index j = 0 ; j < this->cols() ; j++)
545 if((*this)(i,j).is_strict_subset(x(i,j)))
546 return true;
547
548 return false;
549}
550
563
570template<typename OtherDerived>
571inline bool is_interior_subset(const MatrixBase<OtherDerived>& x) const
572{
573 return _is_interior_subset(x);
574}
575
579template<typename OtherDerived>
580inline bool _is_interior_subset(const MatrixBase<OtherDerived>& x) const
581{
582 assert_release(this->size() == x.size());
583
584 if(this->is_empty())
585 return true;
586
587 for(Index i = 0 ; i < this->rows() ; i++)
588 for(Index j = 0 ; j < this->cols() ; j++)
589 if(!(*this)(i,j).is_interior_subset(x(i,j)))
590 return false;
591
592 return true;
593}
594
608
615template<typename OtherDerived>
616inline bool is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
617{
619}
620
624template<typename OtherDerived>
625inline bool _is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
626{
627 assert_release(this->size() == x.size());
628
629 if(this->is_empty())
630 return true;
631
632 for(Index i = 0 ; i < this->rows() ; i++)
633 for(Index j = 0 ; j < this->cols() ; j++)
634 if(!(*this)(i,j).is_strict_interior_subset(x(i,j)))
635 return false;
636
637 return true;
638}
639
652
659template<typename OtherDerived>
660inline bool is_superset(const MatrixBase<OtherDerived>& x) const
661{
662 return _is_superset(x);
663}
664
668template<typename OtherDerived>
669inline bool _is_superset(const MatrixBase<OtherDerived>& x) const
670{
671 assert_release(this->size() == x.size());
672
673 if(this->is_empty())
674 return false;
675
676 for(Index i = 0 ; i < this->rows() ; i++)
677 for(Index j = 0 ; j < this->cols() ; j++)
678 if(!x(i,j).is_subset((*this)(i,j)))
679 return false;
680
681 return true;
682}
683
697
704template<typename OtherDerived>
705inline bool is_strict_superset(const MatrixBase<OtherDerived>& x) const
706{
707 return _is_strict_superset(x);
708}
709
713template<typename OtherDerived>
714inline bool _is_strict_superset(const MatrixBase<OtherDerived>& x) const
715{
716 assert_release(this->size() == x.size());
717
718 if(this->is_empty())
719 return false;
720
721 if(!is_superset(x))
722 return false;
723
724 for(Index i = 0 ; i < this->rows() ; i++)
725 for(Index j = 0 ; j < this->cols() ; j++)
726 if(x(i,j).is_strict_subset((*this)(i,j)))
727 return true;
728
729 return false;
730}
731
739inline bool is_bisectable() const
740{
741 for(Index i = 0 ; i < this->rows() ; i++)
742 for(Index j = 0 ; j < this->cols() ; j++)
743 if((*this)(i,j).is_bisectable())
744 return true;
745 return false;
746}
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
bool overlaps(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix overlaps with another.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:423
auto lb() const
Returns a matrix containing the lower bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:91
bool is_strict_superset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a strict superset of another matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:693
auto mid() const
Returns a matrix containing the midpoints of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:117
bool is_degenerated() const
Checks if the interval matrix is degenerated.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:300
bool is_superset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a superset of another interval matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:648
bool is_unbounded() const
Checks if the interval matrix contains any unbounded intervals.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:283
auto mag() const
Returns a matrix containing the magnitudes of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:131
bool _is_subset(const T &x) const
Internal helper for subset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:489
bool is_interior_subset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is an interior subset of another.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:559
bool is_strict_subset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a strict subset of another matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:512
auto diam() const
Returns a matrix containing the diameters of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:185
bool is_empty() const
Checks whether the interval matrix is empty.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:56
bool _is_strict_subset(const T &x) const
Internal helper for strict subset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:533
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:242
bool is_subset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a subset of another interval matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:468
bool _overlaps(const MatrixBase< OtherDerived > &x) const
Internal helper to check overlap.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:444
bool is_disjoint(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks if this matrix is disjoint with another matrix of intervals.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:379
auto mig() const
Returns a matrix containing the mignitudes of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:143
bool _is_interior_subset(const MatrixBase< OtherDerived > &x) const
Internal helper for interior subset checking.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:580
#define degenerate_mat(op)
Helper macro to create a matrix from a specific operation applied to each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:69
bool _interior_contains(const T &x) const
Internal helper function to check interior containment.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:263
bool is_strict_interior_subset(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix is a strict interior subset of another matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:604
bool _is_strict_interior_subset(const MatrixBase< OtherDerived > &x) const
Internal helper for strict interior subset relation.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:625
bool is_flat() const
Checks if the interval matrix is flat.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:317
bool is_bisectable() const
Checks whether at least one interval in the matrix is bisectable.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:739
bool _is_superset(const MatrixBase< OtherDerived > &x) const
Internal helper for superset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:669
auto ub() const
Returns a matrix containing the upper bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:103
auto rand() const
Returns a matrix with random values chosen inside each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:157
bool _contains(const T &x) const
Internal helper function to check containment.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:219
bool contains(const Matrix< double, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks if this interval matrix contains the specified matrix x.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:198
auto rad() const
Returns a matrix containing the radii of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:171
bool _intersects(const MatrixBase< OtherDerived > &x) const
Internal helper that performs intersection checking.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:356
double volume() const
Computes the volume of the interval matrix.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:33
bool _is_disjoint(const MatrixBase< OtherDerived > &x) const
Internal helper for disjointness checking.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:400
bool intersects(const Matrix< codac2::Interval, RowsAtCompileTime, ColsAtCompileTime > &x) const
Checks whether this matrix intersects with another matrix of intervals.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:335
bool _is_strict_superset(const MatrixBase< OtherDerived > &x) const
Internal helper for strict superset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:714