Browse Source

added Matrix::getRowSum()

... and using it in the DTMC check
tempestpy_adaptions
gereon 12 years ago
parent
commit
364d8e4861
  1. 5
      src/models/Dtmc.h
  2. 16
      src/storage/SquareSparseMatrix.h

5
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;
}

16
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;

Loading…
Cancel
Save