From e05c4dab0dfdb2d6a7f923867052f74e5ff39c75 Mon Sep 17 00:00:00 2001 From: Mavo Date: Thu, 13 Oct 2016 16:00:32 +0200 Subject: [PATCH] Use custom DynamicPriorityQueue Former-commit-id: b4b552a84d9f43880bc0c37b19b4edd90f3b6ddf --- src/builder/ExplicitDFTModelBuilderApprox.cpp | 18 +++-- src/builder/ExplicitDFTModelBuilderApprox.h | 3 +- src/storage/DynamicPriorityQueue.h | 67 +++++++++++++++++++ 3 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 src/storage/DynamicPriorityQueue.h diff --git a/src/builder/ExplicitDFTModelBuilderApprox.cpp b/src/builder/ExplicitDFTModelBuilderApprox.cpp index ac26129df..88af5276d 100644 --- a/src/builder/ExplicitDFTModelBuilderApprox.cpp +++ b/src/builder/ExplicitDFTModelBuilderApprox.cpp @@ -23,14 +23,17 @@ namespace storm { } template - ExplicitDFTModelBuilderApprox::ExplicitDFTModelBuilderApprox(storm::storage::DFT const& dft, storm::storage::DFTIndependentSymmetries const& symmetries, bool enableDC) : dft(dft), stateGenerationInfo(std::make_shared(dft.buildStateGenerationInfo(symmetries))), enableDC(enableDC), generator(dft, *stateGenerationInfo, enableDC, mergeFailedStates), matrixBuilder(!generator.isDeterministicModel()), stateStorage(((dft.stateVectorSize() / 64) + 1) * 64) { + ExplicitDFTModelBuilderApprox::ExplicitDFTModelBuilderApprox(storm::storage::DFT const& dft, storm::storage::DFTIndependentSymmetries const& symmetries, bool enableDC) : + dft(dft), + stateGenerationInfo(std::make_shared(dft.buildStateGenerationInfo(symmetries))), + enableDC(enableDC), + generator(dft, *stateGenerationInfo, enableDC, mergeFailedStates), + matrixBuilder(!generator.isDeterministicModel()), + stateStorage(((dft.stateVectorSize() / 64) + 1) * 64), + statesToExplore(storm::storage::DynamicPriorityQueue, std::function>(&storm::builder::compareDepth)) + { // stateVectorSize is bound for size of bitvector - heuristic = storm::settings::getModule().getApproximationHeuristic(); - - // Compare states by their distance from the initial state - // TODO Matthias: customize - statesToExplore = std::priority_queue, std::function>(&storm::builder::compareDepth); } template @@ -279,6 +282,9 @@ namespace storm { } } + // Update priority queue + statesToExplore.fix(); + if (statesToExplore.empty()) { explorationFinished = true; // Before ending the exploration check for pseudo states which are not initialized yet diff --git a/src/builder/ExplicitDFTModelBuilderApprox.h b/src/builder/ExplicitDFTModelBuilderApprox.h index cb9a444af..9dfb3f63d 100644 --- a/src/builder/ExplicitDFTModelBuilderApprox.h +++ b/src/builder/ExplicitDFTModelBuilderApprox.h @@ -10,6 +10,7 @@ #include "src/storage/sparse/StateStorage.h" #include "src/storage/dft/DFT.h" #include "src/storage/dft/SymmetricUnits.h" +#include "src/storage/DynamicPriorityQueue.h" #include #include #include @@ -286,7 +287,7 @@ namespace storm { storm::storage::sparse::StateStorage stateStorage; // A pniority queue of states that still need to be explored. - std::priority_queue, std::function> statesToExplore; + storm::storage::DynamicPriorityQueue, std::function> statesToExplore; // Holds all skipped states which were not yet expanded. More concretely it is a mapping from matrix indices // to the corresponding skipped states. diff --git a/src/storage/DynamicPriorityQueue.h b/src/storage/DynamicPriorityQueue.h new file mode 100644 index 000000000..a416a89b6 --- /dev/null +++ b/src/storage/DynamicPriorityQueue.h @@ -0,0 +1,67 @@ +#ifndef STORM_STORAGE_DYNAMICPRIORITYQUEUE_H_ +#define STORM_STORAGE_DYNAMICPRIORITYQUEUE_H_ + +#include +#include + +namespace storm { + namespace storage { + + template, typename Compare = std::less> + class DynamicPriorityQueue { + + private: + Container container; + Compare compare; + + public: + explicit DynamicPriorityQueue(const Compare& compare) : container(), compare(compare) { + // Intentionally left empty + } + + explicit DynamicPriorityQueue(Container&& container, const Compare& compare) : container(std::move(container)), compare(compare) { + std::make_heap(container.begin(), container.end(), compare); + } + + void fix() { + std::make_heap(container.begin(), container.end(), compare); + } + + bool empty() const { + return container.empty(); + } + + std::size_t size() const { + return container.size(); + } + + const T& top() const { + return container.front(); + } + + void push(const T& item) { + container.push_back(item); + std::push_heap(container.begin(), container.end(), compare); + } + + void push(T&& item) { + container.push_back(std::move(item)); + std::push_heap(container.begin(), container.end(), compare); + } + + void pop() { + std::pop_heap(container.begin(), container.end(), compare); + container.pop_back(); + } + + T popTop() { + T item = top(); + pop(); + return item; + } + + }; + } +} + +#endif // STORM_STORAGE_DYNAMICPRIORITYQUEUE_H_