ZonoOpt 2.5.0
Loading...
Searching...
No Matches
IntervalMatrix.hpp
Go to the documentation of this file.
1#pragma once
2
14#include <functional>
15#include <ostream>
16#include <string>
17#include <utility>
18#include <vector>
19
20#include "Eigen/Dense"
21#include "Eigen/Sparse"
22
23#include "Interval.hpp"
24#include "Box.hpp"
25#include "Defines.hpp"
26
27namespace ZonoOpt
28{
29 using namespace detail;
30
36 {
37 public:
41 IntervalMatrix() : rows_(0), cols_(0)
42 {
43 }
44
51 IntervalMatrix(size_t rows, size_t cols, const std::vector<Eigen::Triplet<Interval>>& triplets);
52
59 IntervalMatrix(const Eigen::Matrix<zono_float, -1, -1>& mat_lb,
60 const Eigen::Matrix<zono_float, -1, -1>& mat_ub);
61
67 explicit IntervalMatrix(const Eigen::Matrix<Interval, -1, -1>& mat);
68
74 std::vector<std::vector<Interval>> to_array() const;
75
81 std::tuple<int, int, std::vector<Eigen::Triplet<Interval>>> to_triplets() const;
82
89 Eigen::SparseMatrix<zono_float> center() const;
90
97 Eigen::SparseMatrix<zono_float> diam() const;
98
105 IntervalMatrix radius() const;
106
113 zono_float width() const;
114
119 bool is_empty() const;
120
125 bool is_single_valued() const;
126
134 IntervalMatrix intersect(const IntervalMatrix& other) const;
135
143 IntervalMatrix interval_hull(const IntervalMatrix& other) const;
144
152 bool contains(const Eigen::SparseMatrix<zono_float>& mat) const;
153
161 bool contains_set(const IntervalMatrix& other) const;
162
169 Box operator*(const Eigen::Vector<zono_float, -1>& v) const;
170
177 Box operator*(const Box& box) const;
178
185
190 void operator*=(zono_float alpha);
191
198 friend IntervalMatrix operator*(zono_float alpha, const IntervalMatrix& A);
199
205 IntervalMatrix operator*(const Interval& interval) const;
206
213 friend IntervalMatrix operator*(const Interval& interval, const IntervalMatrix& A);
214
219 void operator*=(const Interval& interval);
220
227
234 friend IntervalMatrix operator/(zono_float alpha, const IntervalMatrix& A);
235
240 void operator/=(zono_float alpha);
241
247 IntervalMatrix operator/(const Interval& interval) const;
248
255 friend IntervalMatrix operator/(const Interval& interval, const IntervalMatrix& A);
256
261 void operator/=(const Interval& interval);
262
269 IntervalMatrix operator*(const Eigen::SparseMatrix<zono_float, Eigen::RowMajor>& A) const;
270
278 friend IntervalMatrix operator*(const Eigen::SparseMatrix<zono_float, Eigen::RowMajor>& A, const IntervalMatrix& B);
279
286 IntervalMatrix operator*(const Eigen::Matrix<zono_float, -1, -1>& A) const;
287
295 friend IntervalMatrix operator*(const Eigen::Matrix<zono_float, -1, -1>& A, const IntervalMatrix& B);
296
303 IntervalMatrix operator*(const IntervalMatrix& other) const;
304
310 void operator*=(const IntervalMatrix& other);
311
318 IntervalMatrix operator+(const IntervalMatrix& other) const;
319
325 void operator+=(const IntervalMatrix& other);
326
332 IntervalMatrix operator+(const Interval& interval) const;
333
340 friend IntervalMatrix operator+(const Interval& interval, const IntervalMatrix& mat);
341
346 void operator+=(const Interval& interval);
347
354
361 friend IntervalMatrix operator+(zono_float alpha, const IntervalMatrix& A);
362
367 void operator+=(zono_float alpha);
368
369
376 IntervalMatrix operator-(const IntervalMatrix& other) const;
377
383 void operator-=(const IntervalMatrix& other);
384
385
391 IntervalMatrix operator-(const Interval& interval) const;
392
399 friend IntervalMatrix operator-(const Interval& interval, const IntervalMatrix& mat);
400
405 void operator-=(const Interval& interval);
406
413
420 friend IntervalMatrix operator-(zono_float alpha, const IntervalMatrix& A);
421
426 void operator-=(zono_float alpha);
427
433
441 IntervalMatrix operator&(const IntervalMatrix& other) const;
442
450 IntervalMatrix operator|(const IntervalMatrix& other) const;
451
458 bool operator<=(const IntervalMatrix& other) const;
459
466 bool operator>=(const IntervalMatrix& other) const;
467
474 bool operator==(const IntervalMatrix& other) const;
475
480 size_t rows() const { return rows_; }
481
486 size_t cols() const { return cols_; }
487
492 std::string print() const;
493
500 friend std::ostream& operator<<(std::ostream& os, const IntervalMatrix& interval_matrix);
501
502 private:
503 size_t rows_, cols_;
504 std::vector<std::vector<std::pair<size_t, Interval>>> mat_; // rows->cols->vals
505
506 // apply f elementwise, including to implicit zero elements; these are only stored if f([0, 0]) != [0, 0]
507 IntervalMatrix apply_elementwise(const std::function<Interval(const Interval&)>& f) const;
508 };
509
510}
Box classe.
Defines for ZonoOpt library.
Interval class.
Box (i.e., interval vector) class.
Definition Box.hpp:46
Class for interval matrices (i.e., every element of the matrix is an interval)
Definition IntervalMatrix.hpp:36
IntervalMatrix interval_hull(const IntervalMatrix &other) const
Interval matrix interval hull.
Definition IntervalMatrix.cpp:684
size_t rows() const
Get number of rows.
Definition IntervalMatrix.hpp:480
Eigen::SparseMatrix< zono_float > diam() const
Get diameter matrix.
Definition IntervalMatrix.cpp:580
IntervalMatrix operator&(const IntervalMatrix &other) const
Interval matrix intersection oeprator.
Definition IntervalMatrix.cpp:539
bool operator>=(const IntervalMatrix &other) const
Set containment operator.
Definition IntervalMatrix.cpp:554
std::string print() const
Print method.
Definition IntervalMatrix.cpp:761
zono_float width() const
Get width of interval matrix.
Definition IntervalMatrix.cpp:609
friend IntervalMatrix operator+(const Interval &interval, const IntervalMatrix &mat)
IntervalMatrix element-wise addition with interval.
Definition IntervalMatrix.cpp:195
bool contains(const Eigen::SparseMatrix< zono_float > &mat) const
Check whether the interval matrix contains a given sparse matrix.
Definition IntervalMatrix.cpp:717
void operator/=(zono_float alpha)
IntervalMatrix elementwise division by scalar.
Definition IntervalMatrix.cpp:296
IntervalMatrix intersect(const IntervalMatrix &other) const
Interval matrix intersection.
Definition IntervalMatrix.cpp:651
bool operator<=(const IntervalMatrix &other) const
Set containment operator.
Definition IntervalMatrix.cpp:549
Eigen::SparseMatrix< zono_float > center() const
Get center matrix.
Definition IntervalMatrix.cpp:564
friend std::ostream & operator<<(std::ostream &os, const IntervalMatrix &interval_matrix)
print to ostream
Definition IntervalMatrix.cpp:778
std::vector< std::vector< Interval > > to_array() const
Convert to a vector of vectors of Intervals (row-major)
Definition IntervalMatrix.cpp:113
friend IntervalMatrix operator-(const Interval &interval, const IntervalMatrix &mat)
IntervalMatrix elementwise interval subtraction.
Definition IntervalMatrix.cpp:481
bool operator==(const IntervalMatrix &other) const
Set equality operator.
Definition IntervalMatrix.cpp:559
friend IntervalMatrix operator*(zono_float alpha, const IntervalMatrix &A)
IntervalMatrix scalar multiplication.
Definition IntervalMatrix.cpp:278
bool is_empty() const
Determine whether interval matrix is empty (any contained interval is empty)
Definition IntervalMatrix.cpp:625
void operator-=(const IntervalMatrix &other)
IntervalMatrix subtraction in-place.
Definition IntervalMatrix.cpp:486
void operator*=(zono_float alpha)
IntervalMatrix scalar multiplication in-place.
Definition IntervalMatrix.cpp:250
bool is_single_valued() const
Determine whether interval matrix is single-valued (i.e., all intervals have width 0 within numerical...
Definition IntervalMatrix.cpp:638
friend IntervalMatrix operator/(zono_float alpha, const IntervalMatrix &A)
IntervalMatrix elementwise scalar division.
Definition IntervalMatrix.cpp:516
bool contains_set(const IntervalMatrix &other) const
Check whether the interval matrix contains another interval matrix.
Definition IntervalMatrix.cpp:739
IntervalMatrix operator|(const IntervalMatrix &other) const
Interval matrix interval hull operator.
Definition IntervalMatrix.cpp:544
std::tuple< int, int, std::vector< Eigen::Triplet< Interval > > > to_triplets() const
Convert to triplets.
Definition IntervalMatrix.cpp:139
size_t cols() const
Get number of columns.
Definition IntervalMatrix.hpp:486
IntervalMatrix radius() const
Get radius matrix.
Definition IntervalMatrix.cpp:596
void operator+=(const IntervalMatrix &other)
IntervalMatrix addition in-place.
Definition IntervalMatrix.cpp:430
IntervalMatrix()
IntervalMatrix default constructor.
Definition IntervalMatrix.hpp:41
Interval class.
Definition Interval.hpp:50
#define zono_float
Defines the floating-point type used in ZonoOpt.
Definition Defines.hpp:22
Definition ZonoOpt.hpp:51