Storm
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

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 newRowGroup (index_type startingRow)
 Starts a new row group in the matrix.
 
SparseMatrix< value_typebuild (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 137 of file SparseMatrix.h.

Member Typedef Documentation

◆ index_type

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

Definition at line 139 of file SparseMatrix.h.

◆ value_type

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

Definition at line 140 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 83 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 120 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, we take the sum of the two values provided to addDiagonalEntry and addNextValue

Definition at line 432 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. As multiple entries per column are admitted, consecutive calls to this method are admitted to mention the same row-column-pair. If rows are skipped entirely, the corresponding rows are treated as empty. 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 156 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 281 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 361 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 370 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 356 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 253 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 399 of file SparseMatrix.cpp.


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