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 smag() const
158{
160}
161
167template<typename U=Scalar>
168 requires IsIntervalDomain<U>
169inline auto smig() const
170{
172}
173
181template<typename U=Scalar>
182 requires IsIntervalDomain<U>
183inline auto rand() const
184{
186}
187
195template<typename U=Scalar>
196 requires IsIntervalDomain<U>
197inline auto rad() const
198{
200}
201
209template<typename U=Scalar>
210 requires IsIntervalDomain<U>
211inline auto diam() const
212{
214}
215
225{
226 return _contains(x);
227}
228
235template<typename OtherDerived>
236inline bool contains(const MatrixBase<OtherDerived>& x) const
237{
238 return _contains(x);
239}
240
244template<typename T>
245inline bool _contains(const T& x) const
246{
247 assert_release(x.size() == this->size());
248
249 if(this->is_empty())
250 return false;
251
252 for(Index i = 0 ; i < this->rows() ; i++)
253 for(Index j = 0 ; j < this->cols() ; j++)
254 if(!(*this)(i,j).contains(x(i,j)))
255 return false;
256
257 return true;
258}
259
272
279template<typename OtherDerived>
280inline bool interior_contains(const MatrixBase<OtherDerived>& x) const
281{
282 return _interior_contains(x);
283}
284
288template<typename T>
289inline bool _interior_contains(const T& x) const
290{
291 assert_release(x.size() == this->size());
292
293 if(this->is_empty())
294 return false;
295
296 for(Index i = 0 ; i < this->rows() ; i++)
297 for(Index j = 0 ; j < this->cols() ; j++)
298 if(!(*this)(i,j).interior_contains(x(i,j)))
299 return false;
300
301 return true;
302}
303
309inline bool is_unbounded() const
310{
311 if(this->is_empty()) return false;
312 for(Index i = 0 ; i < this->rows() ; i++)
313 for(Index j = 0 ; j < this->cols() ; j++)
314 if((*this)(i,j).is_unbounded())
315 return true;
316 return false;
317}
318
326inline bool is_degenerated() const
327{
328 for(Index i = 0 ; i < this->rows() ; i++)
329 for(Index j = 0 ; j < this->cols() ; j++)
330 if(!(*this)(i,j).is_degenerated())
331 return false;
332 return true;
333}
334
343inline bool is_flat() const
344{
345 if(this->is_empty()) return true;
346 for(Index i = 0 ; i < this->rows() ; i++)
347 for(Index j = 0 ; j < this->cols() ; j++)
348 if((*this)(i,j).is_degenerated()) // don't use diam() because of roundoff
349 return true;
350 return false;
351}
352
365
372template<typename OtherDerived>
373inline bool intersects(const MatrixBase<OtherDerived>& x) const
374{
375 return _intersects(x);
376}
377
381template<typename OtherDerived>
382inline bool _intersects(const MatrixBase<OtherDerived>& x) const
383{
384 assert_release(this->size() == x.size());
385
386 if(this->is_empty())
387 return false;
388
389 for(Index i = 0 ; i < this->rows() ; i++)
390 for(Index j = 0 ; j < this->cols() ; j++)
391 if(!(*this)(i,j).intersects(x(i,j)))
392 return false;
393
394 return true;
395}
396
409
416template<typename OtherDerived>
417inline bool is_disjoint(const MatrixBase<OtherDerived>& x) const
418{
419 return _is_disjoint(x);
420}
421
425template<typename OtherDerived>
426inline bool _is_disjoint(const MatrixBase<OtherDerived>& x) const
427{
428 assert_release(this->size() == x.size());
429
430 if(this->is_empty())
431 return true;
432
433 for(Index i = 0 ; i < this->rows() ; i++)
434 for(Index j = 0 ; j < this->cols() ; j++)
435 if((*this)(i,j).is_disjoint(x(i,j)))
436 return true;
437
438 return false;
439}
440
450{
451 return _overlaps(x);
452}
453
460template<typename OtherDerived>
461inline bool overlaps(const MatrixBase<OtherDerived>& x) const
462{
463 return _overlaps(x);
464}
465
469template<typename OtherDerived>
470inline bool _overlaps(const MatrixBase<OtherDerived>& x) const
471{
472 assert_release(this->size() == x.size());
473
474 if(this->is_empty())
475 return false;
476
477 for(Index i = 0 ; i < this->rows() ; i++)
478 for(Index j = 0 ; j < this->cols() ; j++)
479 if(!(*this)(i,j).overlaps(x(i,j)))
480 return false;
481
482 return true;
483}
484
495{
496 return _is_subset(x);
497}
498
505template<typename OtherDerived>
506inline bool is_subset(const MatrixBase<OtherDerived>& x) const
507{
508 return _is_subset(x);
509}
510
514template<typename T>
515inline bool _is_subset(const T& x) const
516{
517 assert_release(this->size() == x.size());
518
519 if(this->is_empty())
520 return true;
521
522 for(Index i = 0 ; i < this->rows() ; i++)
523 for(Index j = 0 ; j < this->cols() ; j++)
524 if(!(*this)(i,j).is_subset(x(i,j)))
525 return false;
526
527 return true;
528}
529
542
549template<typename OtherDerived>
550inline bool is_strict_subset(const MatrixBase<OtherDerived>& x) const
551{
552 return _is_strict_subset(x);
553}
554
558template<typename T>
559inline bool _is_strict_subset(const T& x) const
560{
561 assert_release(this->size() == x.size());
562
563 if(this->is_empty())
564 return true;
565
566 if(!is_subset(x))
567 return false;
568
569 for(Index i = 0 ; i < this->rows() ; i++)
570 for(Index j = 0 ; j < this->cols() ; j++)
571 if((*this)(i,j).is_strict_subset(x(i,j)))
572 return true;
573
574 return false;
575}
576
589
596template<typename OtherDerived>
597inline bool is_interior_subset(const MatrixBase<OtherDerived>& x) const
598{
599 return _is_interior_subset(x);
600}
601
605template<typename OtherDerived>
606inline bool _is_interior_subset(const MatrixBase<OtherDerived>& x) const
607{
608 assert_release(this->size() == x.size());
609
610 if(this->is_empty())
611 return true;
612
613 for(Index i = 0 ; i < this->rows() ; i++)
614 for(Index j = 0 ; j < this->cols() ; j++)
615 if(!(*this)(i,j).is_interior_subset(x(i,j)))
616 return false;
617
618 return true;
619}
620
634
641template<typename OtherDerived>
642inline bool is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
643{
645}
646
650template<typename OtherDerived>
651inline bool _is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
652{
653 assert_release(this->size() == x.size());
654
655 if(this->is_empty())
656 return true;
657
658 for(Index i = 0 ; i < this->rows() ; i++)
659 for(Index j = 0 ; j < this->cols() ; j++)
660 if(!(*this)(i,j).is_strict_interior_subset(x(i,j)))
661 return false;
662
663 return true;
664}
665
678
685template<typename OtherDerived>
686inline bool is_superset(const MatrixBase<OtherDerived>& x) const
687{
688 return _is_superset(x);
689}
690
694template<typename OtherDerived>
695inline bool _is_superset(const MatrixBase<OtherDerived>& x) const
696{
697 assert_release(this->size() == x.size());
698
699 if(this->is_empty())
700 return false;
701
702 for(Index i = 0 ; i < this->rows() ; i++)
703 for(Index j = 0 ; j < this->cols() ; j++)
704 if(!x(i,j).is_subset((*this)(i,j)))
705 return false;
706
707 return true;
708}
709
723
730template<typename OtherDerived>
731inline bool is_strict_superset(const MatrixBase<OtherDerived>& x) const
732{
733 return _is_strict_superset(x);
734}
735
739template<typename OtherDerived>
740inline bool _is_strict_superset(const MatrixBase<OtherDerived>& x) const
741{
742 assert_release(this->size() == x.size());
743
744 if(this->is_empty())
745 return false;
746
747 if(!is_superset(x))
748 return false;
749
750 for(Index i = 0 ; i < this->rows() ; i++)
751 for(Index j = 0 ; j < this->cols() ; j++)
752 if(x(i,j).is_strict_subset((*this)(i,j)))
753 return true;
754
755 return false;
756}
757
765inline bool is_bisectable() const
766{
767 for(Index i = 0 ; i < this->rows() ; i++)
768 for(Index j = 0 ; j < this->cols() ; j++)
769 if((*this)(i,j).is_bisectable())
770 return true;
771 return false;
772}
773
779inline bool has_integer_bounds() const
780{
781 for(Index i = 0 ; i < this->rows() ; i++)
782 for(Index j = 0 ; j < this->cols() ; j++)
783 if(!(*this)(i,j).has_integer_bounds())
784 return false;
785 return true;
786}
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:449
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:719
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:326
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:674
auto smig() const
Returns a matrix containing the signed mignitudes of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:169
bool is_unbounded() const
Checks if the interval matrix contains any unbounded intervals.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:309
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:515
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:585
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:538
auto diam() const
Returns a matrix containing the diameters of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:211
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:559
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:268
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:494
bool _overlaps(const MatrixBase< OtherDerived > &x) const
Internal helper to check overlap.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:470
auto smag() const
Returns a matrix containing the signed magnitudes of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:157
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:405
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:606
#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:289
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:630
bool _is_strict_interior_subset(const MatrixBase< OtherDerived > &x) const
Internal helper for strict interior subset relation.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:651
bool is_flat() const
Checks if the interval matrix is flat.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:343
bool is_bisectable() const
Checks whether at least one interval in the matrix is bisectable.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:765
bool _is_superset(const MatrixBase< OtherDerived > &x) const
Internal helper for superset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:695
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:183
bool _contains(const T &x) const
Internal helper function to check containment.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:245
bool has_integer_bounds() const
Checks whether all intervals in the matrix have integer lower and upper bounds.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:779
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:224
auto rad() const
Returns a matrix containing the radii of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:197
bool _intersects(const MatrixBase< OtherDerived > &x) const
Internal helper that performs intersection checking.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:382
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:426
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:361
bool _is_strict_superset(const MatrixBase< OtherDerived > &x) const
Internal helper for strict superset check.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:740