Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SparseMatrix.h
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <cstdint>
5#include <iosfwd>
6#include <iterator>
7#include <vector>
8
9#include <boost/functional/hash.hpp>
10#include <boost/optional.hpp>
11#include <boost/range/irange.hpp>
12
16
19
20// Forward declaration for extended numbers.
21namespace storm::utility {
22template<typename ValueType>
23class ExtendedNumber;
24} // namespace storm::utility
25
26// Forward declaration for adapter classes.
27namespace storm {
28namespace adapters {
29template<typename ValueType>
31class EigenAdapter;
32class StormAdapter;
33} // namespace adapters
34} // namespace storm
35
36namespace storm {
37namespace storage {
38
39// Forward declare matrix class.
40template<typename T>
41class SparseMatrix;
42
44
45template<typename IndexType, typename ValueType>
47 public:
48 typedef IndexType index_type;
49 typedef ValueType value_type;
50
58
64 MatrixEntry(std::pair<index_type, value_type>&& pair);
65
66 MatrixEntry() = default;
67 MatrixEntry(MatrixEntry const& other) = default;
68 MatrixEntry& operator=(MatrixEntry const& other) = default;
69 MatrixEntry(MatrixEntry&& other) = default;
70 MatrixEntry& operator=(MatrixEntry&& other) = default;
71
77 index_type const& getColumn() const;
78
84 void setColumn(index_type const& column);
85
91 value_type const& getValue() const;
92
98 void setValue(value_type const& value);
99
105 std::pair<index_type, value_type> const& getColumnValuePair() const;
106
113
114 bool operator==(MatrixEntry const& other) const;
115 bool operator!=(MatrixEntry const& other) const;
116
117 template<typename IndexTypePrime, typename ValueTypePrime>
118 friend std::ostream& operator<<(std::ostream& out, MatrixEntry<IndexTypePrime, ValueTypePrime> const& entry);
119
120 private:
121 // The actual matrix entry.
122 std::pair<index_type, value_type> entry;
123};
124
128template<typename IndexType, typename ValueType>
129std::size_t hash_value(MatrixEntry<IndexType, ValueType> const& matrixEntry) {
130 std::size_t seed = 0;
131 boost::hash_combine(seed, matrixEntry.getColumn());
132 boost::hash_combine(seed, matrixEntry.getValue());
133 return seed;
134}
135
139template<typename ValueType>
141 public:
143 typedef ValueType value_type;
144
156
172 SparseMatrixBuilder(index_type rows = 0, index_type columns = 0, index_type entries = 0, bool forceDimensions = true, bool hasCustomRowGrouping = false,
173 index_type rowGroups = 0);
174
182
198 void addNextValue(index_type row, index_type column, value_type const& value);
199
209
216
223 void newRowGroup(index_type startingRow);
224
225 /*
226 * Finalizes the sparse matrix to indicate that initialization process has been completed and the matrix
227 * may now be used. This must be called after all entries have been added to the matrix via addNextValue.
228 *
229 * @param overriddenRowCount If this is set to a nonzero value, the resulting matrix will have exactly this many rows.
230 * If there are fewer rows than that, empty rows are added at the end of the matrix. If rows beyond that
231 * count were already added, an exception is thrown. Note that this will *not* override the row count that has
232 * been given upon construction (if any).
233 * @param overriddenColumnCount If this is set to a nonzero value, the resulting matrix will have exactly this many
234 * columns. By construction, the matrix will have no entries in the columns that have been added this way.
235 * If entries beyond that column count were already added, an exception is thrown. Note that this will *not*
236 * override the column count that has been given upon construction (if any).
237 * @param overriddenRowGroupCount If this is set to a nonzero value, the resulting matrix will have exactly this
238 * many row groups. The row groups added this way are empty. If more row groups were already started, an
239 * exception is thrown. Note that this will *not* override the row group count that has been given upon
240 * construction (if any).
241 */
242 SparseMatrix<value_type> build(index_type overriddenRowCount = 0, index_type overriddenColumnCount = 0, index_type overriddenRowGroupCount = 0);
243
249 index_type getLastRow() const;
250
257
264
273 void replaceColumns(std::vector<index_type> const& replacements, index_type offset);
274
283 void addDiagonalEntry(index_type row, ValueType const& value);
284
285 private:
286 // A flag indicating whether a row count was set upon construction.
287 bool initialRowCountSet;
288
289 // The row count that was initially set (if any).
290 index_type initialRowCount;
291
292 // A flag indicating whether a column count was set upon construction.
293 bool initialColumnCountSet;
294
295 // The column count that was initially set (if any).
296 index_type initialColumnCount;
297
298 // A flag indicating whether an entry count was set upon construction.
299 bool initialEntryCountSet;
300
301 // The number of entries in the matrix.
302 index_type initialEntryCount;
303
304 // A flag indicating whether the initially given dimensions are to be enforced on the resulting matrix.
305 bool forceInitialDimensions;
306
307 // A flag indicating whether the builder is to construct a custom row grouping for the matrix.
308 bool hasCustomRowGrouping;
309
310 // A flag indicating whether the number of row groups was set upon construction.
311 bool initialRowGroupCountSet;
312
313 // The number of row groups in the matrix.
314 index_type initialRowGroupCount;
315
316 // The vector that stores the row-group indices (if they are non-trivial).
317 boost::optional<std::vector<index_type>> rowGroupIndices;
318
319 // The storage for the columns and values of all entries in the matrix.
320 std::vector<MatrixEntry<index_type, value_type>> columnsAndValues;
321
322 // A vector containing the indices at which each given row begins. This index is to be interpreted as an
323 // index in the valueStorage and the columnIndications vectors. Put differently, the values of the entries
324 // in row i are valueStorage[rowIndications[i]] to valueStorage[rowIndications[i + 1]] where the last
325 // entry is not included anymore.
326 std::vector<index_type> rowIndications;
327
328 // Stores the current number of entries in the matrix. This is used for inserting an entry into a matrix
329 // with preallocated storage.
330 index_type currentEntryCount;
331
332 // Stores the row of the last entry in the matrix. This is used for correctly inserting an entry into a
333 // matrix.
334 index_type lastRow;
335
336 // Stores the column of the currently last entry in the matrix. This is used for correctly inserting an
337 // entry into a matrix.
338 index_type lastColumn;
339
340 // Stores the highest column at which an entry was inserted into the matrix.
341 index_type highestColumn;
342
343 // Stores the currently active row group. This is used for correctly constructing the row grouping of the
344 // matrix.
345 index_type currentRowGroupCount;
346
347 boost::optional<ValueType> pendingDiagonalEntry;
348
349 // Specifies how multiple values for the same row and column are combined.
351};
352
367template<typename ValueType>
369 public:
370 // Declare adapter classes as friends to use internal data.
371 friend class storm::adapters::GmmxxAdapter<ValueType>;
373 friend class storm::adapters::StormAdapter;
374 friend class SparseMatrixBuilder<ValueType>;
375
377 typedef ValueType value_type;
378 typedef typename std::vector<MatrixEntry<index_type, value_type>>::iterator iterator;
379 typedef typename std::vector<MatrixEntry<index_type, value_type>>::const_iterator const_iterator;
380
384 class rows {
385 public:
393 rows(iterator begin, index_type entryCount);
394
400 iterator begin();
401
407 iterator end();
408
415
416 private:
417 // The pointer to the columnd and value of the first entry.
418 iterator beginIterator;
419
420 // The number of non-zero entries in the rows.
421 index_type entryCount;
422 };
423
428 public:
437
443 const_iterator begin() const;
444
450 const_iterator end() const;
451
458
459 private:
460 // The pointer to the column and value of the first entry.
461 const_iterator beginIterator;
462
463 // The number of non-zero entries in the rows.
464 index_type entryCount;
465 };
466
473
478
485
493 SparseMatrix(SparseMatrix<value_type> const& other, bool insertDiagonalElements);
494
501
510 SparseMatrix(index_type columnCount, std::vector<index_type> const& rowIndications,
511 std::vector<MatrixEntry<index_type, value_type>> const& columnsAndValues, boost::optional<std::vector<index_type>> const& rowGroupIndices);
512
521 SparseMatrix(index_type columnCount, std::vector<index_type>&& rowIndications, std::vector<MatrixEntry<index_type, value_type>>&& columnsAndValues,
522 boost::optional<std::vector<index_type>>&& rowGroupIndices);
523
530
537
544 bool operator==(SparseMatrix<value_type> const& other) const;
545
552
559
566
573
580
589
594
598 void updateDimensions() const;
599
605 void updateNonzeroEntryCount(std::make_signed<index_type>::type difference);
606
613
621
626
631
637 std::vector<index_type> const& getRowGroupIndices() const;
638
642 boost::integer_range<index_type> getRowGroupIndices(index_type group) const;
643
647 std::vector<index_type> const& getRowIndices() const;
648
654 std::vector<index_type> swapRowGroupIndices(std::vector<index_type>&& newRowGrouping);
655
662 void setRowGroupIndices(std::vector<index_type> const& newRowGroupIndices);
663
670
676
685
695 storm::storage::BitVector getRowFilter(storm::storage::BitVector const& groupConstraint, storm::storage::BitVector const& columnConstraints) const;
696
705 storm::storage::BitVector getRowGroupFilter(storm::storage::BitVector const& rowConstraint, bool setIfForAllRowsInGroup) const;
706
715
723 void makeRowGroupsAbsorbing(storm::storage::BitVector const& rowGroupConstraint, bool dropZeroEntries = false);
724
734 void makeRowDirac(index_type row, index_type column, bool dropZeroEntries = false);
735
741 std::vector<ValueType> getRowSumVector() const;
742
751
761 std::vector<value_type> getConstrainedRowSumVector(storm::storage::BitVector const& rowConstraint, storm::storage::BitVector const& columnConstraint) const;
762
772 std::vector<value_type> getConstrainedRowGroupSumVector(storm::storage::BitVector const& rowGroupConstraint,
773 storm::storage::BitVector const& columnConstraint) const;
774
790 SparseMatrix getSubmatrix(bool useGroups, storm::storage::BitVector const& rowConstraint, storm::storage::BitVector const& columnConstraint,
791 bool insertDiagonalEntries = false, storm::storage::BitVector const& makeZeroColumns = storm::storage::BitVector()) const;
792
803 SparseMatrix restrictRows(storm::storage::BitVector const& rowsToKeep, bool allowEmptyRowGroups = false) const;
804
811 SparseMatrix permuteRows(std::vector<index_type> const& inversePermutation) const;
812
820 SparseMatrix permuteRowGroupsAndColumns(std::vector<index_type> const& inverseRowGroupPermutation, std::vector<index_type> const& columnPermutation) const;
821
830
835
843
848
854 void swapRows(index_type const& row1, index_type const& row2);
855
863 SparseMatrix selectRowsFromRowGroups(std::vector<index_type> const& rowGroupToRowIndexMapping, bool insertDiagonalEntries = true) const;
864
874 SparseMatrix selectRowsFromRowIndexSequence(std::vector<index_type> const& rowIndexSequence, bool insertDiagonalEntries = true) const;
875
884 storm::storage::SparseMatrix<value_type> transpose(bool joinGroups = false, bool keepZeros = false) const;
885
894 SparseMatrix<ValueType> transposeSelectedRowsFromRowGroups(std::vector<uint64_t> const& rowGroupChoices, bool keepZeros = false) const;
895
900
906
911
918
924 std::pair<storm::storage::SparseMatrix<value_type>, std::vector<value_type>> getJacobiDecomposition() const;
925
935 template<typename OtherValueType, typename ResultValueType = OtherValueType>
936 ResultValueType getPointwiseProductRowSum(storm::storage::SparseMatrix<OtherValueType> const& otherMatrix, index_type const& row) const;
937
948 template<typename OtherValueType, typename ResultValueType = OtherValueType>
949 std::vector<ResultValueType> getPointwiseProductRowSumVector(storm::storage::SparseMatrix<OtherValueType> const& otherMatrix) const;
950
959 void multiplyWithVector(std::vector<value_type> const& vector, std::vector<value_type>& result, std::vector<value_type> const* summand = nullptr) const;
960
961 void multiplyWithVectorForward(std::vector<value_type> const& vector, std::vector<value_type>& result,
962 std::vector<value_type> const* summand = nullptr) const;
963 void multiplyWithVectorBackward(std::vector<value_type> const& vector, std::vector<value_type>& result,
964 std::vector<value_type> const* summand = nullptr) const;
965
980 void multiplyAndReduce(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType> const& vector,
981 std::vector<ValueType> const* summand, std::vector<ValueType>& result, std::vector<uint64_t>* choices) const;
982
983 void multiplyAndReduceForward(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
984 std::vector<ValueType> const& vector, std::vector<ValueType> const* b, std::vector<ValueType>& result,
985 std::vector<uint64_t>* choices) const;
986 template<typename Compare>
987 void multiplyAndReduceForward(std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType> const& vector, std::vector<ValueType> const* summand,
988 std::vector<ValueType>& result, std::vector<uint64_t>* choices) const;
989
990 void multiplyAndReduceBackward(storm::solver::OptimizationDirection const& dir, std::vector<uint64_t> const& rowGroupIndices,
991 std::vector<ValueType> const& vector, std::vector<ValueType> const* b, std::vector<ValueType>& result,
992 std::vector<uint64_t>* choices) const;
993 template<typename Compare>
994 void multiplyAndReduceBackward(std::vector<uint64_t> const& rowGroupIndices, std::vector<ValueType> const& vector, std::vector<ValueType> const* b,
995 std::vector<ValueType>& result, std::vector<uint64_t>* choices) const;
996
1006 ValueType multiplyRowWithVector(index_type row, std::vector<ValueType> const& vector, ValueType offset = storm::utility::zero<ValueType>()) const;
1007
1015
1025 void multiplyVectorWithMatrix(std::vector<value_type> const& vector, std::vector<value_type>& result) const;
1026
1032 void scaleRowsInPlace(std::vector<value_type> const& factors);
1033
1039 void divideRowsInPlace(std::vector<value_type> const& divisors);
1040
1048 void performSuccessiveOverRelaxationStep(ValueType omega, std::vector<ValueType>& x, std::vector<ValueType> const& b) const;
1049
1059 void performWalkerChaeStep(std::vector<ValueType> const& x, std::vector<ValueType> const& columnSums, std::vector<ValueType> const& b,
1060 std::vector<ValueType> const& ax, std::vector<ValueType>& result) const;
1061
1069
1074
1079
1087 bool isProbabilistic(ValueType const& tolerance, storm::OptionalRef<std::string> reason = {}) const;
1088
1093
1104
1112 template<typename OtherValueType>
1114
1115 // Returns true if the matrix is the identity matrix
1116 bool isIdentityMatrix() const;
1117
1118 template<typename TPrime>
1119 friend std::ostream& operator<<(std::ostream& out, SparseMatrix<TPrime> const& matrix);
1120
1124 std::string getDimensionsAsString() const;
1125
1132 void printAsMatlabMatrix(std::ostream& out) const;
1133
1139 std::size_t hash() const;
1140
1148 const_rows getRows(index_type startRow, index_type endRow) const;
1149
1157 rows getRows(index_type startRow, index_type endRow);
1158
1165 const_rows getRow(index_type row) const;
1166
1174
1181 const_rows getRow(index_type rowGroup, index_type offset) const;
1182
1189 rows getRow(index_type rowGroup, index_type offset);
1190
1197 const_rows getRowGroup(index_type rowGroup) const;
1198
1205 rows getRowGroup(index_type rowGroup);
1206
1214
1222
1229
1236
1244
1252
1259
1266
1270 template<typename NewValueType>
1272 std::vector<MatrixEntry<SparseMatrix::index_type, NewValueType>> newColumnsAndValues;
1273 std::vector<SparseMatrix::index_type> newRowIndications(rowIndications);
1274 boost::optional<std::vector<SparseMatrix::index_type>> newRowGroupIndices(rowGroupIndices);
1275
1276 newColumnsAndValues.resize(columnsAndValues.size());
1277 std::transform(
1278 columnsAndValues.begin(), columnsAndValues.end(), newColumnsAndValues.begin(), [](MatrixEntry<SparseMatrix::index_type, ValueType> const& a) {
1279 return MatrixEntry<SparseMatrix::index_type, NewValueType>(a.getColumn(), storm::utility::convertNumber<NewValueType, ValueType>(a.getValue()));
1280 });
1281
1282 return SparseMatrix<NewValueType>(columnCount, std::move(newRowIndications), std::move(newColumnsAndValues), std::move(newRowGroupIndices));
1283 }
1284
1285 private:
1286 // The number of rows of the matrix.
1287 index_type rowCount;
1288
1289 // The number of columns of the matrix.
1290 mutable index_type columnCount;
1291
1292 // The number of entries in the matrix.
1293 index_type entryCount;
1294
1295 // The number of nonzero entries in the matrix.
1296 mutable index_type nonzeroEntryCount;
1297
1298 // The storage for the columns and values of all entries in the matrix.
1299 std::vector<MatrixEntry<index_type, value_type>> columnsAndValues;
1300
1301 // A vector containing the indices at which each given row begins. This index is to be interpreted as an
1302 // index in the valueStorage and the columnIndications vectors. Put differently, the values of the entries
1303 // in row i are valueStorage[rowIndications[i]] to valueStorage[rowIndications[i + 1]] where the last
1304 // entry is not included anymore.
1305 std::vector<index_type> rowIndications;
1306
1307 // A flag indicating whether the matrix has a trivial row grouping. Note that this may be true and yet
1308 // there may be row group indices, because they were requested from the outside.
1309 bool trivialRowGrouping;
1310
1311 // A vector indicating the row groups of the matrix. This needs to be mutible in case we create it on-the-fly.
1312 mutable boost::optional<std::vector<index_type>> rowGroupIndices;
1313};
1314
1315} // namespace storage
1316} // namespace storm
Helper class that optionally holds a reference to an object of type T.
Definition OptionalRef.h:48
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
MatrixEntry(index_type column, value_type value)
Constructs a matrix entry with the given column and value.
MatrixEntry operator*(value_type factor) const
Multiplies the entry with the given factor and returns the result.
value_type const & getValue() const
Retrieves the value of the matrix entry.
std::pair< index_type, value_type > const & getColumnValuePair() const
Retrieves a pair of column and value that characterizes this entry.
MatrixEntry(MatrixEntry &&other)=default
void setColumn(index_type const &column)
Sets the column of the current entry.
MatrixEntry()=default
MatrixEntry(MatrixEntry const &other)=default
index_type const & getColumn() const
Retrieves the column of the matrix entry.
bool operator!=(MatrixEntry const &other) const
void setValue(value_type const &value)
Sets the value of the entry in the matrix.
MatrixEntry & operator=(MatrixEntry &&other)=default
MatrixEntry & operator=(MatrixEntry const &other)=default
ValueType value_type
IndexType index_type
friend std::ostream & operator<<(std::ostream &out, MatrixEntry< IndexTypePrime, ValueTypePrime > const &entry)
bool operator==(MatrixEntry const &other) const
MatrixEntry(std::pair< index_type, value_type > &&pair)
Move-constructs the matrix entry fro the given column-value pair.
const_rows(const_iterator begin, index_type entryCount)
Constructs an object that represents the rows defined by the value of the first entry,...
const_iterator end() const
Retrieves an iterator that points past the last entry of the rows.
index_type getNumberOfEntries() const
Retrieves the number of entries in the rows.
const_iterator begin() const
Retrieves an iterator that points to the beginning of the rows.
iterator end()
Retrieves an iterator that points past the last entry of the rows.
iterator begin()
Retrieves an iterator that points to the beginning of the rows.
index_type getNumberOfEntries() const
Retrieves the number of entries in the rows.
rows(iterator begin, index_type entryCount)
Constructs an object that represents the rows defined by the value of the first entry,...
A class that can be used to build a sparse matrix by adding value by value.
index_type getCurrentRowGroupCount() const
Retrieves the current row group count.
AccumulationMode
Specifies how values that are added for the same row and column are combined.
@ ExpectNone
There must not be multiple values for the same row and column.
@ ExpectSame
All values added for the same row and column must be equal. The (single) entry keeps this value.
index_type getLastRow() const
Retrieves the most recently used row.
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 replaceColumns(std::vector< index_type > const &replacements, index_type offset)
Replaces all columns with id > offset according to replacements.
SparseMatrixBuilder(index_type rows=0, index_type columns=0, index_type entries=0, bool forceDimensions=true, bool hasCustomRowGrouping=false, index_type rowGroups=0)
Constructs a sparse matrix builder producing a matrix with the given number of rows,...
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
index_type getLastColumn() const
Retrieves the most recently used row.
void addDiagonalEntry(index_type row, ValueType const &value)
Makes sure that a diagonal entry will be inserted at the given row.
void setAccumulationMode(AccumulationMode mode)
Sets how values that are added for the same row and column are combined.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
AccumulationMode getAccumulationMode() const
Retrieves how values that are added for the same row and column are combined.
A class that holds a possibly non-square matrix in the compressed row storage format.
void divideRowsInPlace(std::vector< value_type > const &divisors)
Divides each row of the matrix, i.e., divides each element in row i with divisors[i].
ResultValueType getPointwiseProductRowSum(storm::storage::SparseMatrix< OtherValueType > const &otherMatrix, index_type const &row) const
Performs a pointwise multiplication of the entries in the given row of this matrix and the entries of...
void convertToEquationSystem()
Transforms the matrix into an equation system.
SparseMatrix()
Constructs an empty sparse matrix.
rows getRow(index_type row)
Returns an object representing the given row.
void swapRows(index_type const &row1, index_type const &row2)
Swaps the two rows.
bool operator==(SparseMatrix< value_type > const &other) const
Determines whether the current and the given matrix are semantically equal.
const_rows getRow(index_type row) const
Returns an object representing the given row.
storm::storage::BitVector getRowFilter(storm::storage::BitVector const &groupConstraint, storm::storage::BitVector const &columnConstraints) const
Returns the indices of all rows that.
index_type getSizeOfLargestRowGroup() const
Returns the size of the largest row group of the matrix.
SparseMatrix selectRowsFromRowGroups(std::vector< index_type > const &rowGroupToRowIndexMapping, bool insertDiagonalEntries=true) const
Selects exactly one row from each row group of this matrix and returns the resulting matrix.
void multiplyWithVectorForward(std::vector< value_type > const &vector, std::vector< value_type > &result, std::vector< value_type > const *summand=nullptr) const
index_type getEntryCount() const
Returns the number of entries in the matrix.
bool isProbabilistic(ValueType const &tolerance, storm::OptionalRef< std::string > reason={}) const
Checks for each row whether (i) each entry is between zero and one and (ii) all entries sum to one.
SparseMatrix(index_type columnCount, std::vector< index_type > &&rowIndications, std::vector< MatrixEntry< index_type, value_type > > &&columnsAndValues, boost::optional< std::vector< index_type > > &&rowGroupIndices)
Constructs a sparse matrix by moving the given contents.
const_rows getRows(index_type startRow, index_type endRow) const
Returns an object representing the consecutive rows given by the parameters.
index_type getNonconstantEntryCount() const
Returns the number of non-constant entries.
void multiplyVectorWithMatrix(std::vector< value_type > const &vector, std::vector< value_type > &result) const
Multiplies the vector to the matrix from the left and writes the result to the given result vector.
void multiplyAndReduceBackward(storm::solver::OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &vector, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint64_t > *choices) const
index_type getNumRowsInRowGroups(storm::storage::BitVector const &groupConstraint) const
Returns the total number of rows that are in one of the specified row groups.
void makeRowsAbsorbing(storm::storage::BitVector const &rows, bool dropZeroEntries=false)
This function makes the given rows absorbing.
rows getRows(index_type startRow, index_type endRow)
Returns an object representing the consecutive rows given by the parameters.
void multiplyAndReduceBackward(std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &vector, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint64_t > *choices) const
ValueType multiplyRowWithVector(index_type row, std::vector< ValueType > const &vector, ValueType offset=storm::utility::zero< ValueType >()) const
Multiplies a single row of the matrix with the given vector and adds the given offset to the result.
SparseMatrix(SparseMatrix< value_type > const &other)
Constructs a sparse matrix by performing a deep-copy of the given matrix.
void multiplyWithVector(std::vector< value_type > const &vector, std::vector< value_type > &result, std::vector< value_type > const *summand=nullptr) const
Multiplies the matrix with the given vector and writes the result to the given result vector.
void updateNonzeroEntryCount() const
Recompute the nonzero entry count.
void multiplyWithVectorBackward(std::vector< value_type > const &vector, std::vector< value_type > &result, std::vector< value_type > const *summand=nullptr) const
boost::integer_range< index_type > getRowGroupIndices(index_type group) const
Returns the row indices within the given group.
SparseMatrix getSubmatrix(bool useGroups, storm::storage::BitVector const &rowConstraint, storm::storage::BitVector const &columnConstraint, bool insertDiagonalEntries=false, storm::storage::BitVector const &makeZeroColumns=storm::storage::BitVector()) const
Creates a submatrix of the current matrix by dropping all rows and columns whose bits are not set to ...
void performWalkerChaeStep(std::vector< ValueType > const &x, std::vector< ValueType > const &columnSums, std::vector< ValueType > const &b, std::vector< ValueType > const &ax, std::vector< ValueType > &result) const
Performs one step of the Walker-Chae technique.
SparseMatrix(SparseMatrix< value_type > &&other)
Constructs a sparse matrix by moving the contents of the given matrix to the newly created one.
void updateDimensions() const
Recomputes the number of columns and the number of non-zero entries.
const_iterator begin(index_type row) const
Retrieves an iterator that points to the beginning of the given row.
void printAsMatlabMatrix(std::ostream &out) const
Prints the matrix in a dense format, as also used by e.g.
void performSuccessiveOverRelaxationStep(ValueType omega, std::vector< ValueType > &x, std::vector< ValueType > const &b) const
Performs one step of the successive over-relaxation technique.
SparseMatrix(index_type columnCount, std::vector< index_type > const &rowIndications, std::vector< MatrixEntry< index_type, value_type > > const &columnsAndValues, boost::optional< std::vector< index_type > > const &rowGroupIndices)
Constructs a sparse matrix by copying the given contents.
std::vector< value_type > getConstrainedRowSumVector(storm::storage::BitVector const &rowConstraint, storm::storage::BitVector const &columnConstraint) const
Computes a vector whose i-th entry is the sum of the entries in the i-th selected row where only thos...
BitVector duplicateRowsInRowgroups() const
Finds duplicate rows in a rowgroup.
bool compareRows(index_type i1, index_type i2) const
Compares two rows.
const_rows getRowGroup(index_type rowGroup) const
Returns an object representing the given row group.
SparseMatrix permuteRows(std::vector< index_type > const &inversePermutation) const
Permute rows of the matrix according to the vector.
void setRowGroupIndices(std::vector< index_type > const &newRowGroupIndices)
Sets the row grouping to the given one.
void negateAllNonDiagonalEntries()
Negates (w.r.t.
const_iterator begin() const
Retrieves an iterator that points to the beginning of the first row of the matrix.
std::vector< index_type > swapRowGroupIndices(std::vector< index_type > &&newRowGrouping)
Swaps the grouping of rows of this matrix.
storm::utility::ExtendedNumber< ValueType > multiplyRowWithVector(index_type row, std::vector< storm::utility::ExtendedNumber< ValueType > > const &vector, storm::utility::ExtendedNumber< ValueType > offset=storm::utility::zero< ValueType >()) const
Same as above, but for vectors whose values can be infinite (see storm/utility/ExtendedNumber....
SparseMatrix restrictRows(storm::storage::BitVector const &rowsToKeep, bool allowEmptyRowGroups=false) const
Restrict rows in grouped rows matrix.
std::vector< ValueType > getRowSumVector() const
Sums the entries in all rows.
SparseMatrix< NewValueType > toValueType() const
Returns a copy of the matrix with the chosen internal data type.
SparseMatrix< ValueType > transposeSelectedRowsFromRowGroups(std::vector< uint64_t > const &rowGroupChoices, bool keepZeros=false) const
Transposes the matrix w.r.t.
iterator begin()
Retrieves an iterator that points to the beginning of the first row of the matrix.
std::vector< index_type > const & getRowIndices() const
Returns the entry indices within the given row.
index_type getRowEntryCount(index_type const row) const
Returns the number of entries in the given row of the matrix.
void multiplyAndReduceForward(storm::solver::OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &vector, std::vector< ValueType > const *b, std::vector< ValueType > &result, std::vector< uint64_t > *choices) const
value_type getRowSum(index_type row) const
Computes the sum of the entries in a given row.
const_iterator end(index_type row) const
Retrieves an iterator that points past the end of the given row.
SparseMatrix permuteRowGroupsAndColumns(std::vector< index_type > const &inverseRowGroupPermutation, std::vector< index_type > const &columnPermutation) const
Permutes row groups and columns of the matrix according to the given permutations.
iterator begin(index_type row)
Retrieves an iterator that points to the beginning of the given row.
void multiplyAndReduce(storm::solver::OptimizationDirection const &dir, std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &vector, std::vector< ValueType > const *summand, std::vector< ValueType > &result, std::vector< uint64_t > *choices) const
Multiplies the matrix with the given vector, reduces it according to the given direction and and writ...
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
const_rows getRow(index_type rowGroup, index_type offset) const
Returns an object representing the offset'th row in the rowgroup.
bool isSubmatrixOf(SparseMatrix< OtherValueType > const &matrix) const
Checks if the current matrix is a submatrix of the given matrix, where a matrix A is called a submatr...
SparseMatrix< value_type > & operator=(SparseMatrix< value_type > const &other)
Assigns the contents of the given matrix to the current one by deep-copying its contents.
void makeRowGroupsAbsorbing(storm::storage::BitVector const &rowGroupConstraint, bool dropZeroEntries=false)
This function makes the groups of rows given by the bit vector absorbing.
std::string getDimensionsAsString() const
Returns a string describing the dimensions of the matrix.
index_type getColumnCount() const
Returns the number of columns of the matrix.
std::pair< storm::storage::SparseMatrix< value_type >, std::vector< value_type > > getJacobiDecomposition() const
Calculates the Jacobi decomposition of this sparse matrix.
void makeRowDirac(index_type row, index_type column, bool dropZeroEntries=false)
This function makes the given row Dirac.
std::vector< MatrixEntry< index_type, value_type > >::const_iterator const_iterator
value_type getConstrainedRowSum(index_type row, storm::storage::BitVector const &columns) const
Sums the entries in the given row and columns.
SparseMatrix(SparseMatrix< value_type > const &other, bool insertDiagonalElements)
Constructs a sparse matrix by performing a deep-copy of the given matrix.
rows getRow(index_type rowGroup, index_type offset)
Returns an object representing the offset'th row in the rowgroup.
std::vector< ResultValueType > getPointwiseProductRowSumVector(storm::storage::SparseMatrix< OtherValueType > const &otherMatrix) const
Performs a pointwise matrix multiplication of the matrix with the given matrix and returns a vector c...
void deleteDiagonalEntries(bool dropZeroEntries=false)
Sets all diagonal elements to zero.
rows getRowGroup(index_type rowGroup)
Returns an object representing the given row group.
SparseMatrix< value_type > & operator=(SparseMatrix< value_type > &&other)
Assigns the contents of the given matrix to the current one by moving its contents.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
void invertDiagonal()
Inverts all entries on the diagonal, i.e.
storm::storage::BitVector getRowGroupFilter(storm::storage::BitVector const &rowConstraint, bool setIfForAllRowsInGroup) const
Returns the indices of all row groups selected by the row constraints.
void makeRowGroupingTrivial()
Makes the row grouping of this matrix trivial.
SparseMatrix selectRowsFromRowIndexSequence(std::vector< index_type > const &rowIndexSequence, bool insertDiagonalEntries=true) const
Selects the rows that are given by the sequence of row indices, allowing to select rows arbitrarily o...
bool isProbabilisticGraphPreserving() const
Checks whether the support graph of the matrix is preserved by every way of resolving the uncertainty...
std::size_t hash() const
Calculates a hash value over all values contained in the matrix.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
std::vector< MatrixEntry< index_type, value_type > >::iterator iterator
iterator end()
Retrieves an iterator that points past the end of the last row of the matrix.
index_type getRowGroupSize(index_type group) const
Returns the size of the given row group.
std::vector< value_type > getConstrainedRowGroupSumVector(storm::storage::BitVector const &rowGroupConstraint, storm::storage::BitVector const &columnConstraint) const
Computes a vector whose entries represent the sums of selected columns for all rows in selected row g...
storm::storage::SparseMatrix< value_type > transpose(bool joinGroups=false, bool keepZeros=false) const
Transposes the matrix.
bool hasOnlyPositiveEntries() const
Checks whether each present entry is strictly positive (omitted entries are not considered).
friend std::ostream & operator<<(std::ostream &out, SparseMatrix< TPrime > const &matrix)
index_type getRowCount() const
Returns the number of rows of the matrix.
void updateNonzeroEntryCount(std::make_signed< index_type >::type difference)
Change the nonzero entry count by the provided value.
SparseMatrixIndexType index_type
index_type getNonzeroEntryCount() const
Returns the cached number of nonzero entries in the matrix.
const_iterator end() const
Retrieves an iterator that points past the end of the last row of the matrix.
index_type getNonconstantRowGroupCount() const
Returns the number of rowGroups that contain a non-constant value.
void scaleRowsInPlace(std::vector< value_type > const &factors)
Scales each row of the matrix, i.e., multiplies each element in row i with factors[i].
iterator end(index_type row)
Retrieves an iterator that points past the end of the given row.
index_type getRowGroupEntryCount(index_type const group) const
Returns the number of entries in the given row group of the matrix.
storm::storage::BitVector getRowFilter(storm::storage::BitVector const &groupConstraint) const
Returns a bitvector representing the set of rows, with all indices set that correspond to one of the ...
void multiplyAndReduceForward(std::vector< uint64_t > const &rowGroupIndices, std::vector< ValueType > const &vector, std::vector< ValueType > const *summand, std::vector< ValueType > &result, std::vector< uint64_t > *choices) const
SparseMatrix filterEntries(storm::storage::BitVector const &rowFilter) const
Returns a copy of this matrix that only considers entries in the selected rows.
A value of ValueType extended with the two infinities -infinity and +infinity.
std::size_t hash_value(MatrixEntry< IndexType, ValueType > const &matrixEntry)
Computes the hash value of a matrix entry.
storm::storage::sparse::state_type SparseMatrixIndexType
ValueType zero()
Definition constants.cpp:26
The contract of a DD backend.