Browse Source

using new iterator for checking matrix

SquareSparseMatrix now has a new iterator over elements in a row.
Dtmc uses this iterator to check the probability matrix.
tempestpy_adaptions
gereon 12 years ago
parent
commit
37f6337fa5
  1. 4
      src/models/Dtmc.h
  2. 25
      src/storage/SquareSparseMatrix.h

4
src/models/Dtmc.h

@ -155,8 +155,8 @@ private:
bool checkValidityProbabilityMatrix() {
for (uint_fast64_t row = 0; row < this->probabilityMatrix->getRowCount(); row++) {
T sum = this->probabilityMatrix->getDiagonalStoragePointer()[row];
for (uint_fast64_t id = this->probabilityMatrix->getRowIndicationsPointer()[row]; id < this->probabilityMatrix->getRowIndicationsPointer()[row+1]; id++) {
sum += this->probabilityMatrix->getStoragePointer()[id];
for (auto it = this->probabilityMatrix->beginConstNoDiagIterator(row); it != this->probabilityMatrix->endConstNoDiagIterator(row); it++) {
sum += *it;
}
if (sum == 0) continue;
if (std::abs(sum - 1) > 1e-10) return false;

25
src/storage/SquareSparseMatrix.h

@ -42,6 +42,11 @@ public:
* a row, we can simply iterate over the array (part) itself.
*/
typedef const uint_fast64_t * const constIndexIterator;
/*!
* Iterator type if we want to iterate over elements.
*/
typedef const T* const constIterator;
/*!
* An enum representing the internal state of the Matrix.
@ -930,6 +935,26 @@ public:
constIndexIterator endConstColumnNoDiagIterator(uint_fast64_t row) const {
return this->columnIndications + this->rowIndications[row + 1];
}
/*!
* Returns an iterator over the elements of the given row. The iterator
* will include neither the diagonal element nor zero entries.
* @param row The row whose elements the iterator will return.
* @return An iterator over the elements of the given row.
*/
constIterator beginConstNoDiagIterator(uint_fast64_t row) const {
return this->valueStorage + this->rowIndications[row];
}
/*!
* Returns an iterator pointing to the first element after the given
* row.
* @param row The row for which the iterator should point to the
* past-the-end element.
* @return An iterator to the element after the given row.
*/
constIterator endConstNoDiagIterator(uint_fast64_t row) const {
return this->valueStorage + this->rowIndications[row + 1];
}
void print() const {
std::cout << "diag: --------------------------------" << std::endl;

Loading…
Cancel
Save