Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Decomposition.cpp
Go to the documentation of this file.
2
3#include <vector>
4
8
9namespace storm {
10namespace storage {
11
12template<typename BlockType>
14 // Intentionally left empty.
15}
16
17template<typename BlockType>
18Decomposition<BlockType>::Decomposition(Decomposition const& other) : blocks(other.blocks) {
19 // Intentionally left empty.
20}
21
22template<typename BlockType>
24 this->blocks = other.blocks;
25 return *this;
26}
28template<typename BlockType>
29Decomposition<BlockType>::Decomposition(Decomposition&& other) : blocks(std::move(other.blocks)) {
30 // Intentionally left empty.
31}
32
33template<typename BlockType>
35 this->blocks = std::move(other.blocks);
36 return *this;
37}
38
39template<typename BlockType>
40std::size_t Decomposition<BlockType>::size() const {
41 return blocks.size();
42}
43
44template<typename BlockType>
46 return blocks.empty();
48
49template<typename BlockType>
53
54template<typename BlockType>
58
59template<typename BlockType>
63
64template<typename BlockType>
66 return blocks.end();
67}
68
69template<typename BlockType>
70BlockType const& Decomposition<BlockType>::getBlock(uint_fast64_t index) const {
71 return blocks.at(index);
72}
73
74template<typename BlockType>
75BlockType& Decomposition<BlockType>::getBlock(uint_fast64_t index) {
76 return blocks.at(index);
77}
78
79template<typename BlockType>
80BlockType const& Decomposition<BlockType>::operator[](uint_fast64_t index) const {
81 return blocks[index];
82}
84template<typename BlockType>
85BlockType& Decomposition<BlockType>::operator[](uint_fast64_t index) {
86 return blocks[index];
87}
88
89template<typename BlockType>
90template<typename ValueType>
92 // First, we need to create a mapping of states to their block index, to ease the computation of dependency
93 // transitions later.
94 std::vector<uint_fast64_t> stateToBlockMap(matrix.getRowGroupCount());
95 for (uint_fast64_t i = 0; i < this->size(); ++i) {
96 for (auto state : this->getBlock(i)) {
97 stateToBlockMap[state] = i;
98 }
99 }
100
101 // The resulting sparse matrix will have as many rows/columns as there are blocks in the partition.
102 storm::storage::SparseMatrixBuilder<ValueType> dependencyGraphBuilder(this->size(), this->size());
103
104 for (uint_fast64_t currentBlockIndex = 0; currentBlockIndex < this->size(); ++currentBlockIndex) {
105 // Get the next block.
106 block_type const& block = this->getBlock(currentBlockIndex);
107
108 // Now, we determine the blocks which are reachable (in one step) from the current block.
110 for (auto state : block) {
111 for (auto const& transitionEntry : matrix.getRowGroup(state)) {
112 uint_fast64_t targetBlock = stateToBlockMap[transitionEntry.getColumn()];
113
114 // We only need to consider transitions that are actually leaving the SCC.
115 if (targetBlock != currentBlockIndex) {
116 allTargetBlocks.insert(targetBlock);
117 }
118 }
119 }
121 // Now we can just enumerate all the target blocks and insert the corresponding transitions.
122 for (auto const& targetBlock : allTargetBlocks) {
123 dependencyGraphBuilder.addNextValue(currentBlockIndex, targetBlock, storm::utility::one<ValueType>());
124 }
125 }
126
127 return dependencyGraphBuilder.build();
129
130template<typename BlockType>
131std::ostream& operator<<(std::ostream& out, Decomposition<BlockType> const& decomposition) {
132 out << "[";
133 if (decomposition.size() > 0) {
134 for (uint_fast64_t blockIndex = 0; blockIndex < decomposition.size() - 1; ++blockIndex) {
135 out << decomposition.blocks[blockIndex] << ", ";
137 out << decomposition.blocks.back();
138 }
139 out << "]";
140 return out;
141}
142
144 storm::storage::SparseMatrix<double> const& matrix) const;
145template class Decomposition<StateBlock>;
146template std::ostream& operator<<(std::ostream& out, Decomposition<StateBlock> const& decomposition);
147
149 storm::storage::SparseMatrix<double> const& matrix) const;
151template std::ostream& operator<<(std::ostream& out, Decomposition<StronglyConnectedComponent> const& decomposition);
152
154template std::ostream& operator<<(std::ostream& out, Decomposition<MaximalEndComponent> const& decomposition);
155} // namespace storage
156} // namespace storm
This class represents the decomposition of a model into blocks which are of the template type.
std::vector< block_type >::iterator iterator
Decomposition & operator=(Decomposition const &other)
Assigns the contents of the given decomposition to the current one by copying the contents.
storm::storage::SparseMatrix< ValueType > extractPartitionDependencyGraph(storm::storage::SparseMatrix< ValueType > const &matrix) const
block_type const & operator[](uint_fast64_t index) const
Retrieves the block with the given index.
std::vector< block_type >::const_iterator const_iterator
block_type const & getBlock(uint_fast64_t index) const
Retrieves the block with the given index.
Decomposition()
Creates an empty decomposition.
iterator begin()
Retrieves an iterator that points to the first block of this decomposition.
std::vector< block_type > blocks
iterator end()
Retrieves an iterator that points past the last block of this decomposition.
bool empty() const
Checks if the decomposition is empty.
std::size_t size() const
Retrieves the number of blocks of this decomposition.
A class that can be used to build a sparse matrix by adding value by value.
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
boost::container::flat_set< Key, std::less< Key >, boost::container::new_allocator< Key > > FlatSet
Redefinition of flat_set was needed, because from Boost 1.70 on the default allocator is set to void.
Definition BoostTypes.h:13
std::ostream & operator<<(std::ostream &out, ParameterRegion< ParametricType > const &region)
LabParser.cpp.
Definition cli.cpp:18