12namespace bisimulation {
13template<
typename DataType>
15 blocks.emplace_back(
new Block<DataType>(0, numberOfStates,
nullptr,
nullptr, blocks.size()));
19 states[state] = state;
20 positions[state] = state;
21 stateToBlockMapping[state] = blocks.back().get();
25template<
typename DataType>
27 boost::optional<storm::storage::sparse::state_type> representativeProb1State)
28 : stateToBlockMapping(numberOfStates), states(numberOfStates), positions(numberOfStates) {
33 if (!prob0States.
empty()) {
35 firstBlock = blocks.front().get();
37 for (
auto state : prob0States) {
38 states[position] = state;
39 positions[state] = position;
40 stateToBlockMapping[state] = firstBlock;
43 firstBlock->
data().setAbsorbing(
true);
46 if (!prob1States.
empty()) {
48 secondBlock = blocks.back().get();
50 for (
auto state : prob1States) {
51 states[position] = state;
52 positions[state] = position;
53 stateToBlockMapping[state] = secondBlock;
56 secondBlock->
data().setAbsorbing(
true);
57 secondBlock->
data().setRepresentativeState(representativeProb1State.get());
61 if (!otherStates.
empty()) {
62 blocks.emplace_back(
new Block<DataType>(position, numberOfStates, secondBlock,
nullptr, blocks.size()));
63 thirdBlock = blocks.back().get();
65 for (
auto state : otherStates) {
66 states[position] = state;
67 positions[state] = position;
68 stateToBlockMapping[state] = thirdBlock;
74template<
typename DataType>
76 std::swap(this->states[this->positions[state1]], this->states[this->positions[state2]]);
77 std::swap(this->positions[state1], this->positions[state2]);
80template<
typename DataType>
84 std::swap(this->states[position1], this->states[position2]);
85 this->positions[state1] = position2;
86 this->positions[state2] = position1;
89template<
typename DataType>
91 return this->positions[state];
94template<
typename DataType>
96 return this->states[position];
99template<
typename DataType>
101 std::vector<storm::storage::sparse::state_type>::iterator last) {
102 for (; first != last; ++first) {
103 this->stateToBlockMapping[*first] = █
107template<
typename DataType>
109 std::vector<storm::storage::sparse::state_type>::const_iterator last) {
111 for (; first != last; ++first, ++position) {
112 this->positions[*first] = position;
116template<
typename DataType>
118 mapStatesToPositions(this->begin(block), this->
end(block));
121template<
typename DataType>
123 return *this->stateToBlockMapping[state];
126template<
typename DataType>
128 return *this->stateToBlockMapping[state];
131template<
typename DataType>
133 auto it = this->states.begin();
138template<
typename DataType>
140 auto it = this->states.begin();
145template<
typename DataType>
147 auto it = this->states.begin();
152template<
typename DataType>
154 auto it = this->states.begin();
159template<
typename DataType>
161 return this->states.begin();
164template<
typename DataType>
166 return this->states.begin();
169template<
typename DataType>
171 return this->states.end();
174template<
typename DataType>
176 return this->states.end();
179template<
typename DataType>
182 bool updatePositions) {
185 std::sort(this->states.begin() + beginIndex, this->states.begin() + endIndex,
188 if (updatePositions) {
189 mapStatesToPositions(this->states.begin() + beginIndex, this->states.begin() + endIndex);
193template<
typename DataType>
196 bool updatePositions) {
200template<
typename DataType>
203 auto it = this->states.cbegin() + startIndex;
204 auto ite = this->states.cbegin() + endIndex;
206 std::vector<storm::storage::sparse::state_type>::const_iterator upperBound;
207 std::vector<uint_fast64_t> result;
208 result.push_back(startIndex);
210 upperBound = std::upper_bound(it, ite, *it, less);
211 result.push_back(std::distance(this->states.cbegin(), upperBound));
213 }
while (upperBound != ite);
218template<
typename DataType>
227 auto it = blocks.begin();
228 std::advance(it, block.
getId());
229 return std::make_pair(it,
false);
234 auto newBlockIt = std::prev(blocks.end());
237 block.setBeginIndex(position);
240 this->mapStatesToBlock(**newBlockIt, this->begin(**newBlockIt), this->end(**newBlockIt));
242 return std::make_pair(newBlockIt,
true);
245template<
typename DataType>
250 this->sortBlock(block, less,
false);
256 auto ite = this->states.cbegin() + block.
getEndIndex();
258 bool wasSplit =
false;
259 std::vector<storm::storage::sparse::state_type>::const_iterator upperBound;
261 upperBound = std::upper_bound(it, ite, *it, less);
263 if (upperBound != ite) {
265 auto result = this->splitBlock(block, std::distance(this->states.cbegin(), upperBound));
266 newBlockCallback(**result.first);
269 }
while (upperBound != ite);
272 mapStatesToPositions(this->states.begin() + originalBegin, this->states.begin() + originalEnd);
279template<
typename DataType>
285template<
typename DataType>
291 std::size_t currentSize = this->size();
292 for (uint_fast64_t index = 0; index < currentSize; ++index) {
293 result |= splitBlock(*blocks[index], less, newBlockCallback);
298template<
typename DataType>
303template<
typename DataType>
309template<
typename DataType>
315template<
typename DataType>
317 std::sort(this->begin(block), this->end(block),
319 mapStatesToPositions(block);
322template<
typename DataType>
327template<
typename DataType>
332template<
typename DataType>
334 for (uint_fast64_t state = 0; state < this->positions.size(); ++state) {
335 STORM_LOG_ASSERT(this->states[this->positions[state]] == state,
"Position mapping corrupted.");
337 for (
auto const& blockPtr : this->blocks) {
339 for (
auto stateIt = this->begin(*blockPtr), stateIte = this->end(*blockPtr); stateIt != stateIte; ++stateIt) {
340 STORM_LOG_ASSERT(this->stateToBlockMapping[*stateIt] == blockPtr.get(),
"Block mapping corrupted.");
346template<
typename DataType>
348 for (
auto const& block : this->blocks) {
351 std::cout <<
"states in partition\n";
352 for (
auto const& state : states) {
353 std::cout << state <<
" ";
355 std::cout <<
"\npositions: \n";
356 for (
auto const& index : positions) {
357 std::cout << index <<
" ";
359 std::cout <<
"\nstate to block mapping: \n";
360 for (
auto const& block : stateToBlockMapping) {
361 std::cout << block <<
"[" << block->
getId() <<
"] ";
363 std::cout <<
"\nsize: " << blocks.size() <<
'\n';
367template<
typename DataType>
369 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.
uint_fast64_t getNumberOfSetBits() const
Returns the number of bits that are set to true in this bit vector.
bool get(uint_fast64_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)
std::vector< storm::storage::sparse::state_type >::iterator end(Block< DataType > const &block)
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)