Browse Source

SparseMatrix: fixed getConstraintRowSumVector which did not allocate enough space before filling the resulting vector.

tempestpy_adaptions
Tim Quatmann 5 years ago
parent
commit
60670e1fb2
  1. 21
      src/storm/storage/SparseMatrix.cpp
  2. 5
      src/storm/storage/SparseMatrix.h

21
src/storm/storage/SparseMatrix.cpp

@ -586,6 +586,25 @@ namespace storm {
return res;
}
template<typename ValueType>
typename SparseMatrix<ValueType>::index_type SparseMatrix<ValueType>::getNumRowsInRowGroups(storm::storage::BitVector const& groupConstraint) const {
if (this->hasTrivialRowGrouping()) {
return groupConstraint.getNumberOfSetBits();
}
index_type numRows = 0;
index_type rowGroupIndex = groupConstraint.getNextSetIndex(0);
while (rowGroupIndex < this->getRowGroupCount()) {
index_type start = this->getRowGroupIndices()[rowGroupIndex];
rowGroupIndex = groupConstraint.getNextUnsetIndex(rowGroupIndex + 1);
index_type end = this->getRowGroupIndices()[rowGroupIndex];
// All rows with index in [start,end) are selected.
numRows += end - start;
rowGroupIndex = groupConstraint.getNextSetIndex(rowGroupIndex + 1);
}
return numRows;
}
template<typename ValueType>
std::vector<typename SparseMatrix<ValueType>::index_type> const& SparseMatrix<ValueType>::getRowGroupIndices() const {
// If there is no current row grouping, we need to create it.
@ -874,7 +893,7 @@ namespace storm {
template<typename ValueType>
std::vector<ValueType> SparseMatrix<ValueType>::getConstrainedRowGroupSumVector(storm::storage::BitVector const& rowGroupConstraint, storm::storage::BitVector const& columnConstraint) const {
std::vector<ValueType> result;
result.reserve(rowGroupConstraint.getNumberOfSetBits());
result.reserve(this->getNumRowsInRowGroups(rowGroupConstraint));
if (!this->hasTrivialRowGrouping()) {
for (auto rowGroup : rowGroupConstraint) {
for (index_type row = this->getRowGroupIndices()[rowGroup]; row < this->getRowGroupIndices()[rowGroup + 1]; ++row) {

5
src/storm/storage/SparseMatrix.h

@ -573,6 +573,11 @@ namespace storm {
*/
index_type getSizeOfLargestRowGroup() const;
/*!
* Returns the total number of rows that are in one of the specified row groups.
*/
index_type getNumRowsInRowGroups(storm::storage::BitVector const& groupConstraint) const;
/*!
* Returns the grouping of rows of this matrix.
*

Loading…
Cancel
Save