diff --git a/src/models/Dtmc.h b/src/models/Dtmc.h index 626091f4b..c024779ba 100644 --- a/src/models/Dtmc.h +++ b/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; diff --git a/src/storage/SquareSparseMatrix.h b/src/storage/SquareSparseMatrix.h index cbb56f196..e111115b9 100644 --- a/src/storage/SquareSparseMatrix.h +++ b/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;