Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Partition.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <memory>
5
8
9namespace storm {
10namespace storage {
11namespace bisimulation {
12
13template<typename DataType>
14class Partition {
15 public:
21 Partition(std::size_t numberOfStates);
22
35 Partition(std::size_t numberOfStates, storm::storage::BitVector const& prob0States, storm::storage::BitVector const& prob1States,
36 std::optional<storm::storage::sparse::state_type> representativeProb1State);
37
38 Partition() = default;
39 Partition(Partition const& other) = default;
40 Partition& operator=(Partition const& other) = default;
41 Partition(Partition&& other) = default;
42 Partition& operator=(Partition&& other) = default;
43
44 // Retrieves the size of the partition, i.e. the number of blocks.
45 std::size_t size() const;
46
47 // Prints the partition to the standard output.
48 void print() const;
49
50 // Splits the block at the given position and inserts a new block after the current one holding the rest
51 // of the states.
52 std::pair<typename std::vector<std::unique_ptr<Block<DataType>>>::iterator, bool> splitBlock(Block<DataType>& block,
54
55 // Sorts the given range of the partition according to the given order.
57 std::function<bool(storm::storage::sparse::state_type, storm::storage::sparse::state_type)> const& less, bool updatePositions = true);
58
59 // Sorts the block according to the given order.
61 bool updatePositions = true);
62
63 // Computes the start indices of equal ranges within the given range wrt. to the given less function.
64 std::vector<uint_fast64_t> computeRangesOfEqualValue(
65 uint_fast64_t startIndex, uint_fast64_t endIndex,
67
68 // Splits the block by sorting the states according to the given function and then identifying the split
69 // points. The callback function is called for every newly created block.
71 std::function<void(Block<DataType>&)> const& newBlockCallback);
72
73 // Splits the block by sorting the states according to the given function and then identifying the split
74 // points.
76
77 // Splits all blocks by using the sorting-based splitting. The callback is called for all newly created
78 // blocks.
80 std::function<void(Block<DataType>&)> const& newBlockCallback);
81
82 // Splits all blocks by using the sorting-based splitting.
84
85 // Splits the block such that the resulting blocks contain only states in the given set or none at all.
86 // If the block is split, the given block will contain the states *not* in the given set and the newly
87 // created block will contain the states *in* the given set.
88 void splitStates(Block<DataType>& block, storm::storage::BitVector const& states);
89
94 void splitStates(storm::storage::BitVector const& states);
95
96 // Sorts the block based on the state indices.
97 void sortBlock(Block<DataType> const& block);
98
99 // Retrieves the blocks of the partition.
100 std::vector<std::unique_ptr<Block<DataType>>> const& getBlocks() const;
101
102 // Retrieves the blocks of the partition.
103 std::vector<std::unique_ptr<Block<DataType>>>& getBlocks();
104
105 // Checks the partition for internal consistency.
106 bool check() const;
107
108 // Returns an iterator to the beginning of the states of the given block.
109 std::vector<storm::storage::sparse::state_type>::iterator begin(Block<DataType> const& block);
110
111 // Returns an iterator to the beginning of the states of the given block.
112 std::vector<storm::storage::sparse::state_type>::const_iterator begin(Block<DataType> const& block) const;
113
114 // Returns an iterator to the beginning of the states of the given block.
115 std::vector<storm::storage::sparse::state_type>::iterator end(Block<DataType> const& block);
116
117 // Returns an iterator to the beginning of the states of the given block.
118 std::vector<storm::storage::sparse::state_type>::const_iterator end(Block<DataType> const& block) const;
119
120 // Returns an iterator to the beginning of the states in the partition.
121 std::vector<storm::storage::sparse::state_type>::iterator begin();
122
123 // Returns an iterator to the beginning of the states in the partition.
124 std::vector<storm::storage::sparse::state_type>::const_iterator begin() const;
125
126 // Returns an iterator to the end of the states in the partition.
127 std::vector<storm::storage::sparse::state_type>::iterator end();
128
129 // Returns an iterator to the end of the states in the partition.
130 std::vector<storm::storage::sparse::state_type>::const_iterator end() const;
131
132 // Swaps the positions of the two given states.
134
135 // Retrieves the block of the given state.
137
138 // Retrieves the block of the given state.
140
141 // Retrieves the position of the given state.
143
144 // Sets the position of the state to the given position.
146
147 // Updates the block mapping for the given range of states to the specified block.
148 void mapStatesToBlock(Block<DataType>& block, std::vector<storm::storage::sparse::state_type>::iterator first,
149 std::vector<storm::storage::sparse::state_type>::iterator last);
150
151 // Update the state to position for the states in the given block.
152 void mapStatesToPositions(Block<DataType> const& block);
153
154 // Update the state to position for the states in the given range.
155 void mapStatesToPositions(std::vector<storm::storage::sparse::state_type>::const_iterator first,
156 std::vector<storm::storage::sparse::state_type>::const_iterator last);
157
158 // Swaps the positions of the two states given by their positions.
160
161 private:
162 // The of blocks in the partition.
163 std::vector<std::unique_ptr<Block<DataType>>> blocks;
164
165 // A mapping of states to their blocks.
166 std::vector<Block<DataType>*> stateToBlockMapping;
167
168 // A vector containing all the states. It is ordered in a way such that the blocks only need to define
169 // their start/end indices.
170 std::vector<storm::storage::sparse::state_type> states;
171
172 // This vector keeps track of the position of each state in the state vector.
173 std::vector<storm::storage::sparse::state_type> positions;
174};
175} // namespace bisimulation
176} // namespace storage
177} // namespace storm
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
void sortRange(storm::storage::sparse::state_type beginIndex, storm::storage::sparse::state_type endIndex, std::function< bool(storm::storage::sparse::state_type, storm::storage::sparse::state_type)> const &less, bool updatePositions=true)
storm::storage::sparse::state_type const & getPosition(storm::storage::sparse::state_type state) const
Definition Partition.cpp:89
std::pair< typename std::vector< std::unique_ptr< Block< DataType > > >::iterator, bool > splitBlock(Block< DataType > &block, storm::storage::sparse::state_type position)
Block< DataType > & getBlock(storm::storage::sparse::state_type state)
storm::storage::sparse::state_type const & getState(storm::storage::sparse::state_type position) const
Definition Partition.cpp:94
void sortBlock(Block< DataType > &block, std::function< bool(storm::storage::sparse::state_type, storm::storage::sparse::state_type)> const &less, bool updatePositions=true)
void splitStates(Block< DataType > &block, storm::storage::BitVector const &states)
void mapStatesToPositions(Block< DataType > const &block)
Partition(Partition const &other)=default
Partition & operator=(Partition &&other)=default
void swapStates(storm::storage::sparse::state_type state1, storm::storage::sparse::state_type state2)
Definition Partition.cpp:74
std::vector< std::unique_ptr< Block< DataType > > > const & getBlocks() const
Partition & operator=(Partition const &other)=default
Partition(Partition &&other)=default
bool split(std::function< bool(storm::storage::sparse::state_type, storm::storage::sparse::state_type)> const &less, std::function< void(Block< DataType > &)> const &newBlockCallback)
std::vector< storm::storage::sparse::state_type >::iterator begin()
void mapStatesToBlock(Block< DataType > &block, std::vector< storm::storage::sparse::state_type >::iterator first, std::vector< storm::storage::sparse::state_type >::iterator last)
Definition Partition.cpp:99
void swapStatesAtPositions(storm::storage::sparse::state_type position1, storm::storage::sparse::state_type position2)
Definition Partition.cpp:80
std::vector< storm::storage::sparse::state_type >::iterator end()
std::vector< uint_fast64_t > computeRangesOfEqualValue(uint_fast64_t startIndex, uint_fast64_t endIndex, std::function< bool(storm::storage::sparse::state_type, storm::storage::sparse::state_type)> const &less)