11namespace bisimulation {
12template<
typename DataType>
14 blocks.emplace_back(
new Block<DataType>(0, numberOfStates,
nullptr,
nullptr, blocks.size()));
18 states[state] = state;
19 positions[state] = state;
20 stateToBlockMapping[state] = blocks.back().get();
24template<
typename DataType>
26 std::optional<storm::storage::sparse::state_type> representativeProb1State)
27 : stateToBlockMapping(numberOfStates), states(numberOfStates), positions(numberOfStates) {
32 if (!prob0States.
empty()) {
34 firstBlock = blocks.front().get();
36 for (
auto state : prob0States) {
37 states[position] = state;
38 positions[state] = position;
39 stateToBlockMapping[state] = firstBlock;
42 firstBlock->
data().setAbsorbing(
true);
47 secondBlock = blocks.back().get();
49 for (
auto state : prob1States) {
50 states[position] = state;
51 positions[state] = position;
52 stateToBlockMapping[state] = secondBlock;
55 secondBlock->
data().setAbsorbing(
true);
56 secondBlock->
data().setRepresentativeState(representativeProb1State.value());
61 blocks.emplace_back(
new Block<DataType>(position, numberOfStates, secondBlock,
nullptr, blocks.size()));
62 thirdBlock = blocks.back().get();
64 for (
auto state : otherStates) {
65 states[position] = state;
66 positions[state] = position;
67 stateToBlockMapping[state] = thirdBlock;
73template<
typename DataType>
75 std::swap(this->states[this->positions[state1]], this->states[this->positions[state2]]);
76 std::swap(this->positions[state1], this->positions[state2]);
79template<
typename DataType>
83 std::swap(this->states[position1], this->states[position2]);
84 this->positions[state1] = position2;
85 this->positions[state2] = position1;
88template<
typename DataType>
90 return this->positions[state];
93template<
typename DataType>
95 return this->states[position];
98template<
typename DataType>
100 std::vector<storm::storage::sparse::state_type>::iterator last) {
101 for (; first != last; ++first) {
102 this->stateToBlockMapping[*first] = █
106template<
typename DataType>
108 std::vector<storm::storage::sparse::state_type>::const_iterator last) {
110 for (; first != last; ++first, ++position) {
111 this->positions[*first] = position;
115template<
typename DataType>
117 mapStatesToPositions(this->begin(block), this->end(block));
120template<
typename DataType>
122 return *this->stateToBlockMapping[state];
125template<
typename DataType>
127 return *this->stateToBlockMapping[state];
130template<
typename DataType>
132 auto it = this->states.begin();
137template<
typename DataType>
139 auto it = this->states.begin();
144template<
typename DataType>
146 auto it = this->states.begin();
151template<
typename DataType>
153 auto it = this->states.begin();
158template<
typename DataType>
160 return this->states.begin();
163template<
typename DataType>
165 return this->states.begin();
168template<
typename DataType>
170 return this->states.end();
173template<
typename DataType>
175 return this->states.end();
178template<
typename DataType>
181 bool updatePositions) {
182 std::sort(this->states.begin() + beginIndex, this->states.begin() + endIndex, less);
184 if (updatePositions) {
185 mapStatesToPositions(this->states.begin() + beginIndex, this->states.begin() + endIndex);
189template<
typename DataType>
192 bool updatePositions) {
196template<
typename DataType>
199 auto it = this->states.cbegin() + startIndex;
200 auto ite = this->states.cbegin() + endIndex;
202 std::vector<storm::storage::sparse::state_type>::const_iterator upperBound;
203 std::vector<uint_fast64_t> result;
204 result.push_back(startIndex);
206 upperBound = std::upper_bound(it, ite, *it, less);
207 result.push_back(std::distance(this->states.cbegin(), upperBound));
209 }
while (upperBound != ite);
214template<
typename DataType>
223 auto it = blocks.begin();
224 std::advance(it, block.
getId());
225 return std::make_pair(it,
false);
230 auto newBlockIt = std::prev(blocks.end());
233 block.setBeginIndex(position);
236 this->mapStatesToBlock(**newBlockIt, this->begin(**newBlockIt), this->end(**newBlockIt));
238 return std::make_pair(newBlockIt,
true);
241template<
typename DataType>
246 this->sortBlock(block, less,
false);
252 auto ite = this->states.cbegin() + block.
getEndIndex();
254 bool wasSplit =
false;
255 std::vector<storm::storage::sparse::state_type>::const_iterator upperBound;
257 upperBound = std::upper_bound(it, ite, *it, less);
259 if (upperBound != ite) {
261 auto result = this->splitBlock(block, std::distance(this->states.cbegin(), upperBound));
262 newBlockCallback(**result.first);
265 }
while (upperBound != ite);
268 mapStatesToPositions(this->states.begin() + originalBegin, this->states.begin() + originalEnd);
275template<
typename DataType>
281template<
typename DataType>
287 std::size_t currentSize = this->size();
288 for (uint_fast64_t index = 0; index < currentSize; ++index) {
289 result |= splitBlock(*blocks[index], less, newBlockCallback);
294template<
typename DataType>
299template<
typename DataType>
305template<
typename DataType>
311template<
typename DataType>
313 std::sort(this->begin(block), this->end(block),
315 mapStatesToPositions(block);
318template<
typename DataType>
323template<
typename DataType>
328template<
typename DataType>
330 for (uint_fast64_t state = 0; state < this->positions.size(); ++state) {
331 STORM_LOG_ASSERT(this->states[this->positions[state]] == state,
"Position mapping corrupted.");
333 for (
auto const& blockPtr : this->blocks) {
335 for (
auto stateIt = this->begin(*blockPtr), stateIte = this->end(*blockPtr); stateIt != stateIte; ++stateIt) {
336 STORM_LOG_ASSERT(this->stateToBlockMapping[*stateIt] == blockPtr.get(),
"Block mapping corrupted.");
342template<
typename DataType>
344 for (
auto const& block : this->blocks) {
347 std::cout <<
"states in partition\n";
348 for (
auto const& state : states) {
349 std::cout << state <<
" ";
351 std::cout <<
"\npositions: \n";
352 for (
auto const& index : positions) {
353 std::cout << index <<
" ";
355 std::cout <<
"\nstate to block mapping: \n";
356 for (
auto const& block : stateToBlockMapping) {
357 std::cout << block <<
"[" << block->
getId() <<
"] ";
359 std::cout <<
"\nsize: " << blocks.size() <<
'\n';
363template<
typename DataType>
365 return blocks.size();
A bit vector that is internally represented as a vector of 64-bit values.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
uint64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
storm::storage::sparse::state_type getEndIndex() const
Block * getPreviousBlockPointer()
void print(Partition< DataType > const &partition) const
storm::storage::sparse::state_type getBeginIndex() const
std::size_t getId() const
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
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
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)
void swapStates(storm::storage::sparse::state_type state1, storm::storage::sparse::state_type state2)
std::vector< std::unique_ptr< Block< DataType > > > const & getBlocks() const
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)
void swapStatesAtPositions(storm::storage::sparse::state_type position1, storm::storage::sparse::state_type position2)
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)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)