Browse Source

Added row groups to flexible matrix

Former-commit-id: 85c7dc944b
tempestpy_adaptions
Mavo 9 years ago
parent
commit
acab78ba0e
  1. 80
      src/storage/FlexibleSparseMatrix.cpp
  2. 35
      src/storage/FlexibleSparseMatrix.h
  3. 5
      src/storage/SparseMatrix.cpp
  4. 7
      src/storage/SparseMatrix.h

80
src/storage/FlexibleSparseMatrix.cpp

@ -16,9 +16,6 @@ namespace storm {
FlexibleSparseMatrix<ValueType>::FlexibleSparseMatrix(storm::storage::SparseMatrix<ValueType> const& matrix, bool setAllValuesToOne) : data(matrix.getRowCount()), columnCount(matrix.getColumnCount()), nonzeroEntryCount(matrix.getNonzeroEntryCount()), nontrivialRowGrouping(matrix.hasNontrivialRowGrouping()) {
if (nontrivialRowGrouping) {
rowGroupIndices = matrix.getRowGroupIndices();
rowIndications = matrix.getRowIndications();
// Not fully implemented yet
assert(false);
}
for (index_type rowIndex = 0; rowIndex < matrix.getRowCount(); ++rowIndex) {
typename storm::storage::SparseMatrix<ValueType>::const_rows row = matrix.getRow(rowIndex);
@ -52,6 +49,20 @@ namespace storm {
return this->data[index];
}
template<typename ValueType>
typename FlexibleSparseMatrix<ValueType>::row_type& FlexibleSparseMatrix<ValueType>::getRow(index_type rowGroup, index_type offset) {
assert(rowGroup < this->getRowGroupCount());
assert(offset < this->getRowGroupSize(rowGroup));
return getRow(rowGroupIndices[rowGroup] + offset);
}
template<typename ValueType>
typename FlexibleSparseMatrix<ValueType>::row_type const& FlexibleSparseMatrix<ValueType>::getRow(index_type rowGroup, index_type offset) const {
assert(rowGroup < this->getRowGroupCount());
assert(offset < this->getRowGroupSize(rowGroup));
return getRow(rowGroupIndices[rowGroup] + offset);
}
template<typename ValueType>
typename FlexibleSparseMatrix<ValueType>::index_type FlexibleSparseMatrix<ValueType>::getRowCount() const {
return this->data.size();
@ -67,6 +78,20 @@ namespace storm {
return nonzeroEntryCount;
}
template<typename ValueType>
typename FlexibleSparseMatrix<ValueType>::index_type FlexibleSparseMatrix<ValueType>::getRowGroupCount() const {
return rowGroupIndices.size();
}
template<typename ValueType>
typename FlexibleSparseMatrix<ValueType>::index_type FlexibleSparseMatrix<ValueType>::getRowGroupSize(index_type group) const {
if (group == getRowGroupCount() - 1) {
return getRowCount() - rowGroupIndices[group];
} else {
return rowGroupIndices[group + 1] - rowGroupIndices[group];
}
}
template<typename ValueType>
void FlexibleSparseMatrix<ValueType>::updateDimensions() {
this->nonzeroEntryCount = 0;
@ -91,7 +116,7 @@ namespace storm {
}
template<typename ValueType>
bool SparseMatrix<ValueType>::hasNontrivialRowGrouping() const {
bool FlexibleSparseMatrix<ValueType>::hasNontrivialRowGrouping() const {
return nontrivialRowGrouping;
}
@ -142,13 +167,50 @@ namespace storm {
template<typename ValueType>
std::ostream& operator<<(std::ostream& out, FlexibleSparseMatrix<ValueType> const& matrix) {
for (uint_fast64_t index = 0; index < matrix->data.size(); ++index) {
out << index << " - ";
for (auto const& element : matrix->getRow(index)) {
out << "(" << element.getColumn() << ", " << element.getValue() << ") ";
// Print column numbers in header.
out << "\t\t";
for (typename FlexibleSparseMatrix<ValueType>::index_type i = 0; i < matrix.getColumnCount(); ++i) {
out << i << "\t";
}
out << std::endl;
typename FlexibleSparseMatrix<ValueType>::index_type endIndex = matrix.hasNontrivialRowGrouping() ? matrix.getRowGroupCount() : matrix.getRowCount();
// Iterate over all rows.
for (typename SparseMatrix<ValueType>::index_type i = 0; i < endIndex; ++i) {
if (matrix.hasNontrivialRowGrouping()) {
out << "\t---- group " << i << "/" << (matrix.getRowGroupCount() - 1) << " ---- " << std::endl;
}
return out;
typename FlexibleSparseMatrix<ValueType>::index_type startRow = matrix.hasNontrivialRowGrouping() ? matrix.rowGroupIndices[i] : i;
typename FlexibleSparseMatrix<ValueType>::index_type endRow = matrix.hasNontrivialRowGrouping() ? matrix.rowGroupIndices[i + 1] : i+1;
for (typename FlexibleSparseMatrix<ValueType>::index_type rowIndex = startRow; rowIndex < endRow; ++rowIndex) {
// Print the actual row.
out << i << "\t(\t";
typename FlexibleSparseMatrix<ValueType>::row_type row = matrix.getRow(rowIndex);
typename FlexibleSparseMatrix<ValueType>::index_type columnIndex = 0;
for (auto const& entry : row) {
//Insert zero between entries.
while (columnIndex < entry.getColumn()) {
out << "0\t";
++columnIndex;
}
++columnIndex;
out << entry.getValue() << "\t";
}
//Insert remaining zeros.
while (columnIndex++ <= matrix.getColumnCount()) {
out << "0\t";
}
out << "\t)\t" << i << std::endl;
}
}
// Print column numbers in footer.
out << "\t\t";
for (typename FlexibleSparseMatrix<ValueType>::index_type i = 0; i < matrix.getColumnCount(); ++i) {
out << i << "\t";
}
out << std::endl;
return out;
}
// Explicitly instantiate the matrix.

35
src/storage/FlexibleSparseMatrix.h

@ -72,6 +72,22 @@ namespace storm {
*/
row_type const& getRow(index_type) const;
/*!
* Returns an object representing the offset'th row in the rowgroup
* @param rowGroup the row group
* @param offset which row in the group
* @return An object representing the given row.
*/
row_type& getRow(index_type rowGroup, index_type offset);
/*!
* Returns an object representing the offset'th row in the rowgroup
* @param rowGroup the row group
* @param offset which row in the group
* @return An object representing the given row.
*/
row_type const& getRow(index_type rowGroup, index_type entryInGroup) const;
/*!
* Returns the number of rows of the matrix.
*
@ -93,6 +109,21 @@ namespace storm {
*/
index_type getNonzeroEntryCount() const;
/*!
* Returns the number of row groups in the matrix.
*
* @return The number of row groups in the matrix.
*/
index_type getRowGroupCount() const;
/*!
* Returns the size of the given row group.
*
* @param group The group whose size to retrieve.
* @return The number of rows that belong to the given row group.
*/
index_type getRowGroupSize(index_type group) const;
/*!
* Recomputes the number of columns and the number of non-zero entries.
*/
@ -146,10 +177,6 @@ namespace storm {
// The number of entries in the matrix.
index_type nonzeroEntryCount;
// A vector containing the indices at which each given row begins. The values of the entries in row i are
// data[rowIndications[i]] to data[rowIndications[i + 1]] where the last entry is not included anymore.
std::vector<index_type> rowIndications;
// A flag that indicates whether the matrix has a non-trivial row-grouping, i.e. (possibly) more than one
// row per row group.
bool nontrivialRowGrouping;

5
src/storage/SparseMatrix.cpp

@ -452,11 +452,6 @@ namespace storm {
return rowGroupIndices;
}
template<typename ValueType>
std::vector<typename SparseMatrix<ValueType>::index_type> const& SparseMatrix<ValueType>::getRowIndications() const {
return rowIndications;
}
template<typename ValueType>
void SparseMatrix<ValueType>::makeRowsAbsorbing(storm::storage::BitVector const& rows) {
for (auto row : rows) {

7
src/storage/SparseMatrix.h

@ -549,13 +549,6 @@ namespace storm {
*/
std::vector<index_type> const& getRowGroupIndices() const;
/*!
* Returns the indices where new row groups start.
*
* @return The indices where new row groups start.
*/
std::vector<index_type> const& getRowIndications() const;
/*!
* This function makes the given rows absorbing.
*

Loading…
Cancel
Save