Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
storm::storage::SparseMatrixBuilder< ValueType > Class Template Reference

A class that can be used to build a sparse matrix by adding value by value. More...

#include <SparseMatrix.h>

Public Types

enum class  AccumulationMode { Sum , ExpectSame , ExpectNone }
 Specifies how values that are added for the same row and column are combined. More...
typedef SparseMatrixIndexType index_type
typedef ValueType value_type

Public Member Functions

 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, columns and entries.
 SparseMatrixBuilder (SparseMatrix< ValueType > &&matrix)
 Moves the contents of the given matrix into the matrix builder so that its contents can be modified again.
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 setAccumulationMode (AccumulationMode mode)
 Sets how values that are added for the same row and column are combined.
AccumulationMode getAccumulationMode () const
 Retrieves how values that are added for the same row and column are combined.
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)
index_type getLastRow () const
 Retrieves the most recently used row.
index_type getCurrentRowGroupCount () const
 Retrieves the current row group count.
index_type getLastColumn () const
 Retrieves the most recently used row.
void replaceColumns (std::vector< index_type > const &replacements, index_type offset)
 Replaces all columns with id > offset according to replacements.
void addDiagonalEntry (index_type row, ValueType const &value)
 Makes sure that a diagonal entry will be inserted at the given row.

Detailed Description

template<typename ValueType>
class storm::storage::SparseMatrixBuilder< ValueType >

A class that can be used to build a sparse matrix by adding value by value.

Definition at line 134 of file SparseMatrix.h.

Member Typedef Documentation

◆ index_type

template<typename ValueType>
typedef SparseMatrixIndexType storm::storage::SparseMatrixBuilder< ValueType >::index_type

Definition at line 136 of file SparseMatrix.h.

◆ value_type

template<typename ValueType>
typedef ValueType storm::storage::SparseMatrixBuilder< ValueType >::value_type

Definition at line 137 of file SparseMatrix.h.

Member Enumeration Documentation

◆ AccumulationMode

template<typename ValueType>
enum class storm::storage::SparseMatrixBuilder::AccumulationMode
strong

Specifies how values that are added for the same row and column are combined.

Enumerator
Sum 

The values are summed up.

ExpectSame 

All values added for the same row and column must be equal. The (single) entry keeps this value.

ExpectNone 

There must not be multiple values for the same row and column.

Definition at line 142 of file SparseMatrix.h.

Constructor & Destructor Documentation

◆ SparseMatrixBuilder() [1/2]

template<typename ValueType>
storm::storage::SparseMatrixBuilder< ValueType >::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, columns and entries.

The number of rows, columns and entries is reserved upon creation. If more rows/columns or entries are added, this will possibly lead to a reallocation.

Parameters
rowsThe number of rows of the resulting matrix.
columnsThe number of columns of the resulting matrix.
entriesThe number of entries of the resulting matrix.
forceDimensionsIf this flag is set, the matrix is expected to have exactly the given number of rows, columns and entries for all of these entities that are set to a nonzero value.
hasCustomRowGroupingA flag indicating whether the builder is used to create a non-canonical grouping of rows for this matrix.
rowGroupsThe number of row groups of the resulting matrix. This is only relevant if the matrix has a custom row grouping.

Definition at line 84 of file SparseMatrix.cpp.

◆ SparseMatrixBuilder() [2/2]

template<typename ValueType>
storm::storage::SparseMatrixBuilder< ValueType >::SparseMatrixBuilder ( SparseMatrix< ValueType > && matrix)

Moves the contents of the given matrix into the matrix builder so that its contents can be modified again.

This is, for example, useful if rows need to be added to the matrix.

Parameters
matrixThe matrix that is to be made editable again.

Definition at line 121 of file SparseMatrix.cpp.

Member Function Documentation

◆ addDiagonalEntry()

template<typename ValueType>
void storm::storage::SparseMatrixBuilder< ValueType >::addDiagonalEntry ( index_type row,
ValueType const & value )

Makes sure that a diagonal entry will be inserted at the given row.

All other entries of this row must be set immediately after calling this (without setting values at other rows in between) The provided row must not be smaller than the row of the most recent insertion. If there is a row grouping, the column of the diagonal entry will correspond to the current row group. If addNextValue is called on the given row and the diagonal column (or addDiagonalEntry is called again for the same row), the two values are combined according to the accumulation mode (by default, we take their sum).

Definition at line 456 of file SparseMatrix.cpp.

◆ addNextValue()

template<typename ValueType>
void storm::storage::SparseMatrixBuilder< ValueType >::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.

After all entries have been added, a call to finalize(false) is mandatory.

Note: this is a linear setter. That is, it must be called consecutively for each entry, row by row and column by column. If rows are skipped entirely, the corresponding rows are treated as empty. Within a row, columns may be added in arbitrary order (the builder keeps the row sorted), but adding a column that is smaller than the previous one is slower than adding in order. If a row-column-pair is added multiple times, the values are combined according to the accumulation mode (by default, they are summed up). If these constraints are not met, an exception is thrown.

Parameters
rowThe row in which the matrix entry is to be set.
columnThe column in which the matrix entry is to be set.
valueThe value that is to be set at the specified row and column.

Definition at line 198 of file SparseMatrix.cpp.

◆ build()

template<typename ValueType>
SparseMatrix< ValueType > storm::storage::SparseMatrixBuilder< ValueType >::build ( index_type overriddenRowCount = 0,
index_type overriddenColumnCount = 0,
index_type overriddenRowGroupCount = 0 )

Definition at line 293 of file SparseMatrix.cpp.

◆ getAccumulationMode()

template<typename ValueType>
SparseMatrixBuilder< ValueType >::AccumulationMode storm::storage::SparseMatrixBuilder< ValueType >::getAccumulationMode ( ) const

Retrieves how values that are added for the same row and column are combined.

Returns
The current accumulation mode.

Definition at line 193 of file SparseMatrix.cpp.

◆ getCurrentRowGroupCount()

template<typename ValueType>
SparseMatrixBuilder< ValueType >::index_type storm::storage::SparseMatrixBuilder< ValueType >::getCurrentRowGroupCount ( ) const

Retrieves the current row group count.

Returns
The current row group count.

Definition at line 384 of file SparseMatrix.cpp.

◆ getLastColumn()

template<typename ValueType>
SparseMatrixBuilder< ValueType >::index_type storm::storage::SparseMatrixBuilder< ValueType >::getLastColumn ( ) const

Retrieves the most recently used row.

Returns
The most recently used row.

Definition at line 393 of file SparseMatrix.cpp.

◆ getLastRow()

template<typename ValueType>
SparseMatrixBuilder< ValueType >::index_type storm::storage::SparseMatrixBuilder< ValueType >::getLastRow ( ) const

Retrieves the most recently used row.

Returns
The most recently used row.

Definition at line 379 of file SparseMatrix.cpp.

◆ newRowGroup()

template<typename ValueType>
void storm::storage::SparseMatrixBuilder< ValueType >::newRowGroup ( index_type startingRow)

Starts a new row group in the matrix.

Note that this needs to be called before any entries in the new row group are added.

Parameters
startingRowThe starting row of the new row group.

Definition at line 265 of file SparseMatrix.cpp.

◆ replaceColumns()

template<typename ValueType>
void storm::storage::SparseMatrixBuilder< ValueType >::replaceColumns ( std::vector< index_type > const & replacements,
index_type offset )

Replaces all columns with id > offset according to replacements.

Every state with id offset+i is replaced by the id in replacements[i]. Afterwards the columns are sorted.

Parameters
replacementsMapping indicating the replacements from offset+i -> value of i.
offsetOffset to add to each id in vector index.

Definition at line 423 of file SparseMatrix.cpp.

◆ setAccumulationMode()

template<typename ValueType>
void storm::storage::SparseMatrixBuilder< ValueType >::setAccumulationMode ( AccumulationMode mode)

Sets how values that are added for the same row and column are combined.

The default is AccumulationMode::Sum. If the mode is not AccumulationMode::Sum, adding a value that violates the mode makes addNextValue throw an InvalidArgumentException. This also applies to values added via addDiagonalEntry. The mode should be set before adding any values.

Parameters
modeThe new accumulation mode.

Definition at line 188 of file SparseMatrix.cpp.


The documentation for this class was generated from the following files: