Browse Source

Moved from call to list::size to counting member in bisimulation partition to avoid gcc's O(n) list::size.

Former-commit-id: aaae9886b7
tempestpy_adaptions
dehnert 10 years ago
parent
commit
0bc685969d
  1. 20
      src/storage/DeterministicModelBisimulationDecomposition.cpp
  2. 4
      src/storage/DeterministicModelBisimulationDecomposition.h

20
src/storage/DeterministicModelBisimulationDecomposition.cpp

@ -242,9 +242,9 @@ namespace storm {
} }
template<typename ValueType> template<typename ValueType>
DeterministicModelBisimulationDecomposition<ValueType>::Partition::Partition(std::size_t numberOfStates, bool keepSilentProbabilities) : stateToBlockMapping(numberOfStates), statesAndValues(numberOfStates), positions(numberOfStates), keepSilentProbabilities(keepSilentProbabilities), silentProbabilities() {
DeterministicModelBisimulationDecomposition<ValueType>::Partition::Partition(std::size_t numberOfStates, bool keepSilentProbabilities) : numberOfBlocks(0), stateToBlockMapping(numberOfStates), statesAndValues(numberOfStates), positions(numberOfStates), keepSilentProbabilities(keepSilentProbabilities), silentProbabilities() {
// Create the block and give it an iterator to itself. // Create the block and give it an iterator to itself.
typename std::list<Block>::iterator it = blocks.emplace(this->blocks.end(), 0, numberOfStates, nullptr, nullptr, this->blocks.size());
typename std::list<Block>::iterator it = blocks.emplace(this->blocks.end(), 0, numberOfStates, nullptr, nullptr, numberOfBlocks++);
it->setIterator(it); it->setIterator(it);
// Set up the different parts of the internal structure. // Set up the different parts of the internal structure.
@ -261,8 +261,8 @@ namespace storm {
} }
template<typename ValueType> template<typename ValueType>
DeterministicModelBisimulationDecomposition<ValueType>::Partition::Partition(std::size_t numberOfStates, storm::storage::BitVector const& prob0States, storm::storage::BitVector const& prob1States, std::string const& otherLabel, std::string const& prob1Label, bool keepSilentProbabilities) : stateToBlockMapping(numberOfStates), statesAndValues(numberOfStates), positions(numberOfStates), keepSilentProbabilities(keepSilentProbabilities), silentProbabilities() {
typename std::list<Block>::iterator firstIt = blocks.emplace(this->blocks.end(), 0, prob0States.getNumberOfSetBits(), nullptr, nullptr, this->blocks.size());
DeterministicModelBisimulationDecomposition<ValueType>::Partition::Partition(std::size_t numberOfStates, storm::storage::BitVector const& prob0States, storm::storage::BitVector const& prob1States, std::string const& otherLabel, std::string const& prob1Label, bool keepSilentProbabilities) : numberOfBlocks(0), stateToBlockMapping(numberOfStates), statesAndValues(numberOfStates), positions(numberOfStates), keepSilentProbabilities(keepSilentProbabilities), silentProbabilities() {
typename std::list<Block>::iterator firstIt = blocks.emplace(this->blocks.end(), 0, prob0States.getNumberOfSetBits(), nullptr, nullptr, numberOfBlocks++);
Block& firstBlock = *firstIt; Block& firstBlock = *firstIt;
firstBlock.setIterator(firstIt); firstBlock.setIterator(firstIt);
@ -275,7 +275,7 @@ namespace storm {
} }
firstBlock.setAbsorbing(true); firstBlock.setAbsorbing(true);
typename std::list<Block>::iterator secondIt = blocks.emplace(this->blocks.end(), position, position + prob1States.getNumberOfSetBits(), &firstBlock, nullptr, this->blocks.size(), std::shared_ptr<std::string>(new std::string(prob1Label)));
typename std::list<Block>::iterator secondIt = blocks.emplace(this->blocks.end(), position, position + prob1States.getNumberOfSetBits(), &firstBlock, nullptr, numberOfBlocks++, std::shared_ptr<std::string>(new std::string(prob1Label)));
Block& secondBlock = *secondIt; Block& secondBlock = *secondIt;
secondBlock.setIterator(secondIt); secondBlock.setIterator(secondIt);
@ -287,7 +287,7 @@ namespace storm {
} }
secondBlock.setAbsorbing(true); secondBlock.setAbsorbing(true);
typename std::list<Block>::iterator thirdIt = blocks.emplace(this->blocks.end(), position, numberOfStates, &secondBlock, nullptr, this->blocks.size(), otherLabel == "true" ? std::shared_ptr<std::string>(nullptr) : std::shared_ptr<std::string>(new std::string(otherLabel)));
typename std::list<Block>::iterator thirdIt = blocks.emplace(this->blocks.end(), position, numberOfStates, &secondBlock, nullptr, numberOfBlocks++, otherLabel == "true" ? std::shared_ptr<std::string>(nullptr) : std::shared_ptr<std::string>(new std::string(otherLabel)));
Block& thirdBlock = *thirdIt; Block& thirdBlock = *thirdIt;
thirdBlock.setIterator(thirdIt); thirdBlock.setIterator(thirdIt);
@ -408,7 +408,7 @@ namespace storm {
} }
// Actually create the new block and insert it at the correct position. // Actually create the new block and insert it at the correct position.
typename std::list<Block>::iterator selfIt = this->blocks.emplace(block.getIterator(), block.getBegin(), position, block.getPreviousBlockPointer(), &block, this->blocks.size(), block.getLabelPtr());
typename std::list<Block>::iterator selfIt = this->blocks.emplace(block.getIterator(), block.getBegin(), position, block.getPreviousBlockPointer(), &block, numberOfBlocks++, block.getLabelPtr());
selfIt->setIterator(selfIt); selfIt->setIterator(selfIt);
Block& newBlock = *selfIt; Block& newBlock = *selfIt;
@ -432,7 +432,7 @@ namespace storm {
} }
// Actually insert the new block. // Actually insert the new block.
typename std::list<Block>::iterator it = this->blocks.emplace(block.getIterator(), begin, block.getBegin(), block.getPreviousBlockPointer(), &block, this->blocks.size());
typename std::list<Block>::iterator it = this->blocks.emplace(block.getIterator(), begin, block.getBegin(), block.getPreviousBlockPointer(), &block, numberOfBlocks++);
Block& newBlock = *it; Block& newBlock = *it;
newBlock.setIterator(it); newBlock.setIterator(it);
@ -570,13 +570,13 @@ namespace storm {
} }
std::cout << std::endl; std::cout << std::endl;
} }
std::cout << "size: " << this->blocks.size() << std::endl;
std::cout << "size: " << numberOfBlocks << std::endl;
assert(this->check()); assert(this->check());
} }
template<typename ValueType> template<typename ValueType>
std::size_t DeterministicModelBisimulationDecomposition<ValueType>::Partition::size() const { std::size_t DeterministicModelBisimulationDecomposition<ValueType>::Partition::size() const {
return this->blocks.size();
return numberOfBlocks;
} }
template<typename ValueType> template<typename ValueType>

4
src/storage/DeterministicModelBisimulationDecomposition.h

@ -371,6 +371,10 @@ namespace storm {
// The list of blocks in the partition. // The list of blocks in the partition.
std::list<Block> blocks; std::list<Block> blocks;
// The number of blocks of the partition. Although this could be retrieved via block.size(), we want to
// guarantee constant access time (which is currently not guaranteed by gcc'c standard libary).
uint_fast64_t numberOfBlocks;
// A mapping of states to their blocks. // A mapping of states to their blocks.
std::vector<Block*> stateToBlockMapping; std::vector<Block*> stateToBlockMapping;

Loading…
Cancel
Save