From 364d8e4861eac855d8e575650a9852528686352d Mon Sep 17 00:00:00 2001 From: gereon <gereon.kremer@rwth-aachen.de> Date: Mon, 24 Dec 2012 13:46:43 +0100 Subject: [PATCH] added Matrix::getRowSum() ... and using it in the DTMC check --- src/models/Dtmc.h | 5 +---- src/storage/SquareSparseMatrix.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/models/Dtmc.h b/src/models/Dtmc.h index 35b129991..0018d5274 100644 --- a/src/models/Dtmc.h +++ b/src/models/Dtmc.h @@ -176,10 +176,7 @@ private: */ bool checkValidityProbabilityMatrix() { for (uint_fast64_t row = 0; row < this->probabilityMatrix->getRowCount(); row++) { - T sum = this->probabilityMatrix->getDiagonalStoragePointer()[row]; - for (auto it = this->probabilityMatrix->beginConstNoDiagIterator(row); it != this->probabilityMatrix->endConstNoDiagIterator(row); it++) { - sum += *it; - } + T sum = this->probabilityMatrix->getRowSum(row); 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 bee88ba3f..d95009bf1 100644 --- a/src/storage/SquareSparseMatrix.h +++ b/src/storage/SquareSparseMatrix.h @@ -954,6 +954,22 @@ public: constIterator endConstNoDiagIterator(uint_fast64_t row) const { return this->valueStorage + this->rowIndications[row + 1]; } + + /*! + * @brief Calculate sum of all entries in given row. + * + * Adds up all values in the given row (including the diagonal value) + * and returns the sum. + * @param row The row that should be added up. + * @return Sum of the row. + */ + T getRowSum(uint_fast64_t row) const { + T sum = this->diagonalStorage[row]; + for (auto it = this->beginConstNoDiagIterator(row); it != this->endConstNoDiagIterator(row); it++) { + sum += *it; + } + return sum; + } void print() const { std::cout << "diag: --------------------------------" << std::endl;