codac 2.0.0
Loading...
Searching...
No Matches
codac2_Matrix_addons_IntervalMatrixBase.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
 Matrix (const Matrix< double, R, C > &lb, const Matrix< double, R, C > &ub)
 Constructs an interval matrix from lower and upper bound matrices.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
 Matrix (int r, int c, const double bounds[][2])
 Constructs an interval matrix from a 2D array of bounds.
 
auto & init ()
 Initializes all elements of the matrix with default intervals.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime, typename OtherDerived>
requires IsIntervalDomain<Scalar>
bool operator== (const MatrixBase< OtherDerived > &x) const
 Compares this interval matrix with another matrix for equality.
 
void set_empty ()
 Marks the interval matrix as empty.
 
auto & inflate (double r)
 Inflates all intervals in the matrix by a fixed radius.
 
template<typename OtherDerived>
requires IsIntervalDomain<Scalar>
auto & inflate (const MatrixBase< OtherDerived > &r)
 Inflates each interval in the matrix by corresponding values from another matrix.
 
template<typename OtherDerived>
auto & operator&= (const MatrixBase< OtherDerived > &x)
 Performs element-wise intersection assignment with another matrix.
 
template<typename OtherDerived>
auto & operator|= (const MatrixBase< OtherDerived > &x)
 Performs element-wise union assignment with another matrix.
 
template<typename OtherDerived>
auto operator& (const MatrixBase< OtherDerived > &x) const
 Returns the element-wise intersection of this matrix with another.
 
template<typename OtherDerived>
auto operator| (const MatrixBase< OtherDerived > &x) const
 Returns the element-wise union of this matrix with another.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
auto bisect (Index i, float ratio=0.49) const
 Bisects the interval at the given index into two sub-interval matrices.
 
template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
auto bisect_largest (float ratio=0.49) const
 Bisects the interval with the largest diameter in the matrix.
 

Detailed Description

This class reuses some of the functions developed for ibex::IntervalMatrixBase. The original IBEX code is revised in modern C++ and adapted to the template structure proposed in Codac, based on the Eigen library. See ibex::IntervalMatrixBase (IBEX lib, author: Gilles Chabert)

This file is included in the declaration of Eigen::MatrixBase, thanks to the preprocessor token EIGEN_MATRIX_PLUGIN. See: https://eigen.tuxfamily.org/dox/TopicCustomizing_Plugins.html and the file codac2_matrices.h


Date
2024
Author
Simon Rohou, Gilles Chabert
License: GNU Lesser General Public License (LGPL)

Function Documentation

◆ Matrix() [1/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
Matrix ( const Matrix< double, R, C > & lb,
const Matrix< double, R, C > & ub )

Constructs an interval matrix from lower and upper bound matrices.

Initializes the interval matrix with the given lower bound matrix lb and upper bound matrix ub.

Each element of the resulting interval matrix is constructed from corresponding elements in lb and ub. If any lower bound element is greater than its corresponding upper bound element, the matrix is set to empty.

Parameters
lbMatrix of lower bounds.
ubMatrix of upper bounds.
Precondition
lb and ub must have the same size.
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}
void set_empty()
Marks the interval matrix as empty.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:141
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
auto ub() const
Returns a matrix containing the upper bounds of each interval element.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:103

◆ Matrix() [2/2]

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
Matrix ( int r,
int c,
const double bounds[][2] )

Constructs an interval matrix from a 2D array of bounds.

Initializes the matrix with dimensions (r,c) where each element is set to an interval constructed from the corresponding pair of lower and upper bounds in the bounds array.

Parameters
rNumber of rows in the matrix.
cNumber of columns in the matrix.
bounds2D array of size [r*c][2], where each sub-array contains the lower and upper bound for one element.
Precondition
r and c must be positive.
The bounds array size must exactly match the total number of elements.
Postcondition
Each matrix element (i,j) is initialized to codac2::Interval(bounds[k][0], bounds[k][1]) with k mapping row-major order index.
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}
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:49

◆ init()

auto & init ( )
inline

Initializes all elements of the matrix with default intervals.

Sets every element in the matrix to a default-constructed codac2::Interval.

Returns
Reference to the current matrix object (enables method chaining).
114{
115 for(Index i = 0 ; i < this->size() ; i++)
116 (this->data()+i)->init();
117 return *this;
118}

◆ operator==()

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime, typename OtherDerived>
requires IsIntervalDomain<Scalar>
bool operator== ( const MatrixBase< OtherDerived > & x) const
inline

Compares this interval matrix with another matrix for equality.

Evaluates and casts the other matrix to an interval matrix, then performs an element-wise equality comparison.

Parameters
xThe other matrix (of arbitrary derived type) to compare.
Returns
true if the matrices are equal after casting; false otherwise.
132{
133 return operator==(x.eval().template cast<codac2::Interval>());
134}
bool operator==(const MatrixBase< OtherDerived > &x) const
Compares this interval matrix with another matrix for equality.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:131

◆ set_empty()

void set_empty ( )
inline

Marks the interval matrix as empty.

Sets all elements to an empty interval.

143{
145}
static Interval empty()
Provides an empty interval.
Definition codac2_Interval_impl.h:568
auto & init()
Initializes all elements of the matrix with default intervals.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:113

◆ inflate() [1/2]

auto & inflate ( double r)
inline

Inflates all intervals in the matrix by a fixed radius.

Adds radius r to each interval element, expanding their bounds.

Parameters
rThe non-negative radius by which to inflate each interval.
Returns
Reference to the current matrix object (for chaining).
Precondition
r must be greater than or equal to zero.
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}

◆ inflate() [2/2]

template<typename OtherDerived>
requires IsIntervalDomain<Scalar>
auto & inflate ( const MatrixBase< OtherDerived > & r)
inline

Inflates each interval in the matrix by corresponding values from another matrix.

Inflates each element by the radius specified at the same position in matrix r.

Parameters
rMatrix containing non-negative inflation radii.
Returns
Reference to the current matrix object (for chaining).
Precondition
The size of this matrix and r must be the same.
All elements in r must be greater than or equal to zero.
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}
auto & inflate(double r)
Inflates all intervals in the matrix by a fixed radius.
Definition codac2_Matrix_addons_IntervalMatrixBase.h:157

◆ operator&=()

template<typename OtherDerived>
auto & operator&= ( const MatrixBase< OtherDerived > & x)
inline

Performs element-wise intersection assignment with another matrix.

Updates each element of this matrix by intersecting it with the corresponding element of matrix x.

If x is empty, this matrix is set empty.

Parameters
xThe matrix to intersect with.
Returns
Reference to this matrix after intersection.
Precondition
The size of this matrix and x must be the same.
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}

◆ operator|=()

template<typename OtherDerived>
auto & operator|= ( const MatrixBase< OtherDerived > & x)
inline

Performs element-wise union assignment with another matrix.

Updates each element of this matrix by taking the union with the corresponding element of matrix x.

If x is empty, this matrix remains unchanged.

Parameters
xThe matrix to union with.
Returns
Reference to this matrix after union.
Precondition
The size of this matrix and x must be the same.
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}

◆ operator&()

template<typename OtherDerived>
auto operator& ( const MatrixBase< OtherDerived > & x) const
inline

Returns the element-wise intersection of this matrix with another.

Creates a copy of this matrix and performs element-wise intersection assignment with matrix x, then returns the result.

Parameters
xThe matrix to intersect with.
Returns
A new matrix representing the intersection.
265{
266 auto y = *this;
267 return y &= x;
268}

◆ operator|()

template<typename OtherDerived>
auto operator| ( const MatrixBase< OtherDerived > & x) const
inline

Returns the element-wise union of this matrix with another.

Creates a copy of this matrix and performs element-wise union assignment with the interval-casted matrix x, then returns the result.

Parameters
xThe matrix to union with.
Returns
A new matrix representing the union.
281{
282 auto y = *this;
283 return y |= x.template cast<codac2::Interval>();
284}

◆ bisect()

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
auto bisect ( Index i,
float ratio = 0.49 ) const
inline

Bisects the interval at the given index into two sub-interval matrices.

Splits the interval at element index i into two parts according to the ratio and returns a pair of matrices having the two resulting sub-intervals.

Parameters
iIndex of the element to bisect (must be within valid range).
ratioRatio to determine the split point within the interval (default 0.49, must lie in [0,1]).
Returns
A pair of matrices resulting from the bisection.
Precondition
The element at index i must be bisectable.
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}
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
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

◆ bisect_largest()

template<int R = RowsAtCompileTime, int C = ColsAtCompileTime>
requires IsIntervalDomain<Scalar>
auto bisect_largest ( float ratio = 0.49) const
inline

Bisects the interval with the largest diameter in the matrix.

Uses max_diam_index() to find the element with the largest diameter and bisects it using the given ratio.

Parameters
ratioRatio to determine the split point within the interval (default 0.49).
Returns
A pair of matrices resulting from the bisection of the largest diameter interval.
340{
341 return bisect(this->max_diam_index(), ratio);
342}
Index max_diam_index() const
Returns the index of the element with the maximum diameter.
Definition codac2_MatrixBase_addons_IntervalMatrixBase.h:276