diff --git a/src/storage/SparseMatrix.cpp b/src/storage/SparseMatrix.cpp index 907f97081..1dac98d2c 100644 --- a/src/storage/SparseMatrix.cpp +++ b/src/storage/SparseMatrix.cpp @@ -65,6 +65,17 @@ namespace storm { return MatrixEntry(this->getColumn(), this->getValue() * factor); } + + template + bool MatrixEntry::operator==(MatrixEntry const& other) const { + return this->entry.first == other.entry.first && this->entry.second == other.entry.second; + } + + template + bool MatrixEntry::operator!=(MatrixEntry const& other) const { + return !(*this == other); + } + template std::ostream& operator<<(std::ostream& out, MatrixEntry const& entry) { out << "(" << entry.getColumn() << ", " << entry.getValue() << ")"; @@ -568,6 +579,38 @@ namespace storm { } } + template + bool SparseMatrix::compareRows(index_type i1, index_type i2) const { + const_iterator end1 = this->end(i1); + const_iterator end2 = this->end(i2); + const_iterator it1 = this->begin(i1); + const_iterator it2 = this->begin(i2); + for(;it1 != end1 && it2 != end2; ++it1, ++it2 ) { + if(*it1 != *it2) { + return false; + } + } + if(it1 == end1 && it2 == end2) { + return true; + } + return false; + } + + template + BitVector SparseMatrix::duplicateRowsInRowgroups() const { + BitVector bv(this->getRowCount()); + for(size_t rowgroup = 0; rowgroup < this->getRowGroupCount(); ++rowgroup) { + for(size_t row1 = this->getRowGroupIndices().at(rowgroup); row1 < this->getRowGroupIndices().at(rowgroup+1); ++row1) { + for(size_t row2 = row1; row2 < this->getRowGroupIndices().at(rowgroup+1); ++row2) { + if(compareRows(row1, row2)) { + bv.set(row2); + } + } + } + } + return bv; + } + template ValueType SparseMatrix::getConstrainedRowSum(index_type row, storm::storage::BitVector const& constraint) const { ValueType result = storm::utility::zero(); diff --git a/src/storage/SparseMatrix.h b/src/storage/SparseMatrix.h index f1debced1..f0c03496d 100644 --- a/src/storage/SparseMatrix.h +++ b/src/storage/SparseMatrix.h @@ -109,6 +109,9 @@ namespace storm { */ MatrixEntry operator*(value_type factor) const; + bool operator==(MatrixEntry const& other) const; + bool operator!=(MatrixEntry const& other) const; + template friend std::ostream& operator<<(std::ostream& out, MatrixEntry const& entry); private: @@ -640,6 +643,18 @@ namespace storm { */ SparseMatrix restrictRows(storm::storage::BitVector const& rowsToKeep) const; + /** + * Compares two rows. + * @param i1 Index of first row + * @param i2 Index of second row + * @return True if the rows have identical entries. + */ + bool compareRows(index_type i1, index_type i2) const; + /*! + * Finds duplicate rows in a rowgroup. + */ + BitVector duplicateRowsInRowgroups() const; + /*! * Selects exactly one row from each row group of this matrix and returns the resulting matrix. *