Traffic Flow Dynamics Model
|
SparseMatrix class v1.7.0 by Grufoony. More...
#include <SparseMatrix.hpp>
Public Member Functions | |
SparseMatrix (int rows, int cols) | |
SparseMatrix constructor. More... | |
SparseMatrix (int index) | |
SparseMatrix constructor - colum. More... | |
void | setSeed (int seed) noexcept |
Set random seed. More... | |
void | insert (int i, int j, T value) |
insert a value in the matrix More... | |
void | insert (int i, T value) |
insert a value in the matrix More... | |
void | insert_or_assign (int i, int j, T value) |
insert a value in the matrix. If the element already exist, it overwrites it More... | |
void | insert_or_assign (int index, T value) |
insert a value in the matrix. If the element already exist, it overwrites it More... | |
void | erase (int i, int j) |
remove a value from the matrix More... | |
void | eraseRow (int index) |
remove a row from the matrix More... | |
void | eraseColumn (int index) |
remove a column from the matrix More... | |
void | clear () noexcept |
bool | contains (int i, int j) const |
check if the element is non zero More... | |
bool | contains (int const index) const |
check if the element is non zero More... | |
SparseMatrix< int > | getDegreeVector () |
get the input degree of all nodes More... | |
SparseMatrix< double > | getStrengthVector () |
get the strength of all nodes More... | |
SparseMatrix< int > | getLaplacian () |
get the laplacian matrix More... | |
SparseMatrix | getRow (int index) const |
get a row as a row vector More... | |
SparseMatrix | getCol (int index) const |
get a column as a column vector More... | |
std::pair< int, T > | getRndRowElement (int index) |
get a random non-zero element from a row More... | |
std::pair< int, T > | getRndColElement (int index) |
get a random non-zero element from a column More... | |
std::pair< int, T > | getRndElement () |
get a random non-zero element from the matrix More... | |
SparseMatrix< double > | getNormRows () const |
get a matrix of double with every row normalized to 1 More... | |
SparseMatrix< double > | getNormCols () const |
get a matrix of double with every column normalized to 1 More... | |
int | getRowDim () const noexcept |
get the number of rows More... | |
int | getColDim () const noexcept |
get the number of columns More... | |
int | size () const noexcept |
get the number of non zero elements in the matrix More... | |
int | max_size () const noexcept |
get the maximum number of elements in the matrix More... | |
T | at (int i, int j) const |
access an element of the matrix More... | |
T | at (int index) const |
access an element of the matrix More... | |
void | symmetrize () |
symmetrize the matrix | |
void | print () const noexcept |
print the matrix in standard output | |
void | fprint (std::string const &filename) const noexcept |
print the matrix on a file More... | |
std::unordered_map< int, T >::const_iterator | begin () const noexcept |
return the begin iterator of the matrix More... | |
std::unordered_map< int, T >::const_iterator | end () const noexcept |
return the end iterator of the matrix More... | |
T const & | operator() (int i, int j) |
access an element of the matrix More... | |
T const & | operator() (int index) |
access an element of the matrix More... | |
template<typename U > | |
SparseMatrix | operator+ (const SparseMatrix< U > &other) const |
sum of two matrices More... | |
template<typename U > | |
SparseMatrix | operator- (const SparseMatrix< U > &other) const |
difference of two matrices More... | |
SparseMatrix | operator++ () |
transpose the matrix More... | |
template<typename U > | |
SparseMatrix & | operator+= (const SparseMatrix< U > &other) |
sum of two matrices More... | |
template<typename U > | |
SparseMatrix & | operator-= (const SparseMatrix< U > &other) |
difference of two matrices More... | |
Static Public Member Functions | |
static void | encode (std::string const &filename) |
Function to read a matrix from a file and rewrite it in a listed way. More... | |
static void | decode (std::string const &filename) |
Function to read a matrix from a file and rewrite it as a full matrix. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const SparseMatrix &m) |
print the matrix on a stream | |
std::istream & | operator>> (std::istream &is, SparseMatrix &m) |
read the matrix from a stream | |
SparseMatrix class v1.7.0 by Grufoony.
This class implements a sparse matrix. The matrix is stored in a compressed row format. ++ 20 requiered.
|
inline |
SparseMatrix constructor.
rows | number of rows |
cols | number of columns |
std::invalid_argument | if rows or cols are < 0 |
|
inline |
SparseMatrix constructor - colum.
index | number of rows |
std::invalid_argument | if index is < 0 |
|
inline |
access an element of the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
|
inline |
access an element of the matrix
index | index in vectorial form |
std::out_of_range | if the index is out of range |
|
inlinenoexcept |
return the begin iterator of the matrix
|
inline |
check if the element is non zero
index | index in vectorial form |
std::out_of_range | if the index is out of range |
|
inline |
check if the element is non zero
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
|
inlinestatic |
Function to read a matrix from a file and rewrite it as a full matrix.
filename | name of the file |
|
inlinestatic |
Function to read a matrix from a file and rewrite it in a listed way.
filename | name of the file |
|
inlinenoexcept |
return the end iterator of the matrix
|
inline |
remove a value from the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
std::runtime_error | if the element is not found |
|
inline |
remove a column from the matrix
index | column index |
std::out_of_range | if the index is out of range |
|
inline |
remove a row from the matrix
index | row index |
std::out_of_range | if the index is out of range |
|
inlinenoexcept |
print the matrix on a file
filename | name of the file |
|
inline |
get a column as a column vector
index | column index |
std::out_of_range | if the index is out of range |
|
inlinenoexcept |
get the number of columns
|
inline |
get the input degree of all nodes
std::runtime_error | if the matrix is not square |
|
inline |
get the laplacian matrix
std::runtime_error | if the matrix is not square |
|
inline |
get a matrix of double with every column normalized to 1
|
inline |
get a matrix of double with every row normalized to 1
|
inline |
get a random non-zero element from a column
index | column index |
std::out_of_range | if the index is out of range |
|
inline |
get a random non-zero element from the matrix
std::runtime_error | if the matrix is empty |
|
inline |
get a random non-zero element from a row
index | row index |
std::out_of_range | if the index is out of range |
|
inline |
get a row as a row vector
index | row index |
std::out_of_range | if the index is out of range |
|
inlinenoexcept |
get the number of rows
|
inline |
get the strength of all nodes
std::runtime_error | if the matrix is not square |
|
inline |
insert a value in the matrix
i | row index |
j | column index |
value | value to insert |
std::out_of_range | if the index is out of range |
|
inline |
insert a value in the matrix
i | index |
value | value to insert |
std::out_of_range | if the index is out of range |
|
inline |
insert a value in the matrix. If the element already exist, it overwrites it
i | row index |
j | column index |
value | value to insert |
std::out_of_range | if the index is out of range |
|
inline |
insert a value in the matrix. If the element already exist, it overwrites it
index | index in vectorial form |
value | value to insert |
std::out_of_range | if the index is out of range |
|
inlinenoexcept |
get the maximum number of elements in the matrix
|
inline |
access an element of the matrix
i | row index |
j | column index |
std::out_of_range | if the index is out of range |
|
inline |
access an element of the matrix
index | index in vectorial form |
std::out_of_range | if the index is out of range |
|
inline |
sum of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inline |
transpose the matrix
|
inline |
sum of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inline |
difference of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inline |
difference of two matrices
other | the other matrix |
std::runtime_error | if the dimensions do not match |
|
inlinenoexcept |
Set random seed.
seed | seed |
|
inlinenoexcept |
get the number of non zero elements in the matrix