13template<
typename ValueType>
18template<
typename ValueType>
20 : data(matrix.getRowCount()),
21 columnCount(matrix.getColumnCount()),
22 nonzeroEntryCount(matrix.getNonzeroEntryCount()),
23 trivialRowGrouping(matrix.hasTrivialRowGrouping()) {
24 STORM_LOG_THROW(!revertEquationSystem || trivialRowGrouping, storm::exceptions::InvalidArgumentException,
"Illegal option for creating flexible matrix.");
26 if (!trivialRowGrouping) {
32 for (
auto const& element : row) {
35 if (revertEquationSystem && rowIndex == element.getColumn()) {
36 getRow(rowIndex).emplace_back(element.getColumn(), storm::utility::one<ValueType>());
41 if (setAllValuesToOne) {
42 if (revertEquationSystem && element.getColumn() == rowIndex &&
storm::utility::isOne(element.getValue())) {
45 getRow(rowIndex).emplace_back(element.getColumn(), storm::utility::one<ValueType>());
48 if (revertEquationSystem) {
49 if (element.getColumn() == rowIndex) {
53 getRow(rowIndex).emplace_back(element.getColumn(), storm::utility::one<ValueType>() - element.getValue());
55 getRow(rowIndex).emplace_back(element.getColumn(), -element.getValue());
58 getRow(rowIndex).emplace_back(element);
65template<
typename ValueType>
67 this->data[row].reserve(numberOfElements);
70template<
typename ValueType>
72 return this->data[index];
75template<
typename ValueType>
77 return this->data[index];
80template<
typename ValueType>
83 STORM_LOG_ASSERT(offset < this->getRowGroupSize(rowGroup),
"Invalid offset.");
84 return getRow(rowGroupIndices[rowGroup] + offset);
87template<
typename ValueType>
90 STORM_LOG_ASSERT(offset < this->getRowGroupSize(rowGroup),
"Invalid offset.");
91 return getRow(rowGroupIndices[rowGroup] + offset);
94template<
typename ValueType>
96 return rowGroupIndices;
99template<
typename ValueType>
101 return this->data.size();
104template<
typename ValueType>
109template<
typename ValueType>
111 return nonzeroEntryCount;
114template<
typename ValueType>
116 return rowGroupIndices.size() - 1;
119template<
typename ValueType>
121 return rowGroupIndices[group + 1] - rowGroupIndices[group];
124template<
typename ValueType>
126 ValueType sum = storm::utility::zero<ValueType>();
127 for (
auto const& element : getRow(row)) {
128 sum += element.getValue();
133template<
typename ValueType>
135 this->nonzeroEntryCount = 0;
136 this->columnCount = 0;
137 for (
auto const& row : this->data) {
138 for (
auto const& element : row) {
140 ++this->nonzeroEntryCount;
141 this->columnCount = std::max(element.getColumn() + 1, this->columnCount);
146template<
typename ValueType>
148 for (
auto const& row : this->data) {
156template<
typename ValueType>
158 return trivialRowGrouping;
161template<
typename ValueType>
163 for (uint_fast64_t rowIndex = 0; rowIndex < this->data.size(); ++rowIndex) {
164 auto& row = this->data[rowIndex];
165 if (!rowConstraint.
get(rowIndex)) {
171 for (
auto const& element : row) {
172 if (columnConstraint.
get(element.getColumn())) {
173 newRow.push_back(element);
176 row = std::move(newRow);
180template<
typename ValueType>
182 uint_fast64_t numEntries = 0;
183 for (
auto const& row : this->data) {
184 numEntries += row.size();
188 hasTrivialRowGrouping() ? 0 : getRowGroupCount());
189 uint_fast64_t currRowIndex = 0;
190 auto rowGroupIndexIt = getRowGroupIndices().begin();
191 for (
auto const& row : this->data) {
192 if (!hasTrivialRowGrouping()) {
193 while (currRowIndex >= *rowGroupIndexIt) {
198 for (
auto const& entry : row) {
199 matrixBuilder.
addNextValue(currRowIndex, entry.getColumn(), entry.getValue());
204 if (!hasTrivialRowGrouping()) {
205 while (currRowIndex >= *rowGroupIndexIt) {
210 return matrixBuilder.
build();
213template<
typename ValueType>
216 uint_fast64_t numEntries = 0;
217 for (
auto rowIndex : rowConstraint) {
218 auto const& row = data[rowIndex];
219 for (
auto const& entry : row) {
220 if (columnConstraint.
get(entry.getColumn())) {
225 uint_fast64_t numRowGroups = 0;
226 if (!hasTrivialRowGrouping()) {
227 auto lastRowGroupIndexIt = getRowGroupIndices().
end() - 1;
228 auto rowGroupIndexIt = getRowGroupIndices().begin();
229 while (rowGroupIndexIt != lastRowGroupIndexIt) {
231 if (rowConstraint.
getNextSetIndex(*rowGroupIndexIt) < *(++rowGroupIndexIt)) {
237 std::vector<uint_fast64_t> oldToNewColumnIndexMapping(getColumnCount(), getColumnCount());
238 uint_fast64_t newColumnIndex = 0;
239 for (
auto oldColumnIndex : columnConstraint) {
240 oldToNewColumnIndexMapping[oldColumnIndex] = newColumnIndex++;
245 uint_fast64_t currRowIndex = 0;
246 auto rowGroupIndexIt = getRowGroupIndices().begin();
247 for (
auto oldRowIndex : rowConstraint) {
248 if (!hasTrivialRowGrouping() && oldRowIndex >= *rowGroupIndexIt) {
253 }
while (oldRowIndex >= *rowGroupIndexIt);
255 auto const& row = data[oldRowIndex];
256 for (
auto const& entry : row) {
257 if (columnConstraint.
get(entry.getColumn())) {
258 matrixBuilder.
addNextValue(currRowIndex, oldToNewColumnIndexMapping[entry.getColumn()], entry.getValue());
263 return matrixBuilder.
build();
266template<
typename ValueType>
268 for (
auto const& entry : this->getRow(state)) {
269 if (entry.getColumn() < state) {
271 }
else if (entry.getColumn() > state) {
273 }
else if (entry.getColumn() == state) {
280template<
typename ValueType>
283 row_type row = this->getRow(rowIndex);
284 for (
index_type column = 0; column < this->getColumnCount(); ++column) {
285 if (columnIndex < row.size() && row[columnIndex].getColumn() == column) {
287 out << row[columnIndex].getValue() <<
"\t";
297template<
typename ValueType>
311 for (FlexibleIndex rowGroup = 0; rowGroup < rowGroupCount; ++rowGroup) {
312 out <<
"\t---- group " << rowGroup <<
"/" << (rowGroupCount - 1) <<
" ---- \n";
313 FlexibleIndex endRow = matrix.rowGroupIndices[rowGroup + 1];
315 for (FlexibleIndex row = matrix.rowGroupIndices[rowGroup]; row < endRow; ++row) {
317 out << rowGroup <<
"\t(\t";
319 out <<
"\t)\t" << rowGroup <<
'\n';
325 for (FlexibleIndex row = 0; row < matrix.
getRowCount(); ++row) {
327 out << row <<
"\t(\t";
329 out <<
"\t)\t" << row <<
'\n';
343template class FlexibleSparseMatrix<double>;
346#ifdef STORM_HAVE_CARL
A bit vector that is internally represented as a vector of 64-bit values.
uint_fast64_t getNextSetIndex(uint_fast64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
The flexible sparse matrix is used during state elimination.
void reserveInRow(index_type row, index_type numberOfElements)
Reserves space for elements in row.
index_type getRowGroupSize(index_type group) const
Returns the size of the given row group.
index_type getColumnCount() const
Returns the number of columns of the matrix.
value_type getRowSum(index_type row) const
Computes the sum of the entries in a given row.
void updateDimensions()
Recomputes the number of columns and the number of non-zero entries.
index_type getNonzeroEntryCount() const
Returns the cached number of nonzero entries in the matrix.
std::ostream & printRow(std::ostream &out, index_type const &rowIndex) const
Print row.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
storm::storage::SparseMatrix< ValueType > createSparseMatrix()
Creates a sparse matrix from the flexible sparse matrix.
row_type & getRow(index_type)
Returns an object representing the given row.
bool empty() const
Checks if the matrix has no elements.
void filterEntries(storm::storage::BitVector const &rowConstraint, storm::storage::BitVector const &columnConstraint)
Erases all entries whose row and column does not satisfy the given rowConstraint and the given column...
index_type getRowCount() const
Returns the number of rows of the matrix.
FlexibleSparseMatrix()=default
Constructs an empty flexible sparse matrix.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a (possibly) trivial row grouping.
bool rowHasDiagonalElement(storm::storage::sparse::state_type state)
Checks whether the given state has a self-loop with an arbitrary probability in the probability matri...
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
std::vector< storm::storage::MatrixEntry< index_type, value_type > > row_type
This class represents a number of consecutive rows of the matrix.
index_type getNumberOfEntries() const
Retrieves the number of entries in the rows.
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
const_iterator end(index_type row) const
Retrieves an iterator that points past the end of the given row.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const ®ion)
bool isOne(ValueType const &a)
bool isZero(ValueType const &a)