From 82a3964e5dab0c6d9d0404a0efa08c576bb0a554 Mon Sep 17 00:00:00 2001 From: Mavo Date: Sat, 22 Oct 2016 18:30:26 +0200 Subject: [PATCH] Only fix queue when needed Former-commit-id: 50231c4554e3bf6cdeeb7b6de37778fa3faedb3a --- src/builder/DftExplorationHeuristic.cpp | 71 +++++-------------- src/builder/DftExplorationHeuristic.h | 66 +++++++++++++---- src/builder/ExplicitDFTModelBuilderApprox.cpp | 3 +- 3 files changed, 73 insertions(+), 67 deletions(-) diff --git a/src/builder/DftExplorationHeuristic.cpp b/src/builder/DftExplorationHeuristic.cpp index 4bc72ccc1..3b9c2e110 100644 --- a/src/builder/DftExplorationHeuristic.cpp +++ b/src/builder/DftExplorationHeuristic.cpp @@ -14,69 +14,34 @@ namespace storm { // Intentionally left empty } - template - void DFTExplorationHeuristic::updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate) { - this->depth = std::min(this->depth, depth); - this->rate = std::max(this->rate, rate); - this->exitRate = std::max(this->exitRate, exitRate); - } - - template - DFTExplorationHeuristicNone::DFTExplorationHeuristicNone(size_t id) : DFTExplorationHeuristic(id) { - // Intentionally left empty + template<> + bool DFTExplorationHeuristicRateRatio::updateHeuristicValues(size_t depth, double rate, double exitRate) { + bool update = false; + if (this->rate < rate) { + this->rate = rate; + update = true; + } + if (this->exitRate < exitRate) { + this->exitRate = exitRate; + update = true; + } + return update; } - template - bool DFTExplorationHeuristicNone::isSkip(double approximationThreshold) const { + template<> + bool DFTExplorationHeuristicRateRatio::updateHeuristicValues(size_t depth, storm::RationalFunction rate, storm::RationalFunction exitRate) { + STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic rate ration does not work for rational functions."); return false; } - template - bool DFTExplorationHeuristicNone::operator<(DFTExplorationHeuristicNone const& other) const { - // Just use memory address for comparing - // TODO Matthias: better idea? - return this > &other; - } - - template - DFTExplorationHeuristicDepth::DFTExplorationHeuristicDepth(size_t id) : DFTExplorationHeuristic(id) { - // Intentionally left empty - } - - template - bool DFTExplorationHeuristicDepth::isSkip(double approximationThreshold) const { - return !this->expand && this->depth > approximationThreshold; - } - - template - bool DFTExplorationHeuristicDepth::operator<(DFTExplorationHeuristicDepth const& other) const { - return this->depth > other.depth; - } - - template - DFTExplorationHeuristicRateRatio::DFTExplorationHeuristicRateRatio(size_t id) : DFTExplorationHeuristic(id) { - // Intentionally left empty - } - - template - bool DFTExplorationHeuristicRateRatio::isSkip(double approximationThreshold) const { - return !this->expand && this->getRateRatio() < approximationThreshold; - } - - template - bool DFTExplorationHeuristicRateRatio::operator<(DFTExplorationHeuristicRateRatio const& other) const { - return this->getRateRatio() < other.getRateRatio(); - } - - template<> - double DFTExplorationHeuristicRateRatio::getRateRatio() const { + double DFTExplorationHeuristicRateRatio::getPriority() const { return rate/exitRate; } template<> - double DFTExplorationHeuristicRateRatio::getRateRatio() const { - STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic rate ration does not work."); + double DFTExplorationHeuristicRateRatio::getPriority() const { + STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic rate ration does not work for rational functions."); } diff --git a/src/builder/DftExplorationHeuristic.h b/src/builder/DftExplorationHeuristic.h index 8f12d2ec1..2b4fc5047 100644 --- a/src/builder/DftExplorationHeuristic.h +++ b/src/builder/DftExplorationHeuristic.h @@ -22,7 +22,9 @@ namespace storm { public: DFTExplorationHeuristic(size_t id); - void updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate); + virtual bool updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate) = 0; + + virtual double getPriority() const = 0; virtual bool isSkip(double approximationThreshold) const = 0; @@ -50,34 +52,74 @@ namespace storm { template class DFTExplorationHeuristicNone : public DFTExplorationHeuristic { public: - DFTExplorationHeuristicNone(size_t id); + DFTExplorationHeuristicNone(size_t id) : DFTExplorationHeuristic(id) { + // Intentionally left empty + } + + bool updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate) override { + return false; + } + + double getPriority() const override { + return this->id; + } - bool isSkip(double approximationThreshold) const override; + bool isSkip(double approximationThreshold) const override { + return false; + } - bool operator<(DFTExplorationHeuristicNone const& other) const; + bool operator<(DFTExplorationHeuristicNone const& other) const { + return this->id > other.id; + } }; template class DFTExplorationHeuristicDepth : public DFTExplorationHeuristic { public: - DFTExplorationHeuristicDepth(size_t id); + DFTExplorationHeuristicDepth(size_t id) : DFTExplorationHeuristic(id) { + // Intentionally left empty + } + + bool updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate) override { + if (depth < this->depth) { + this->depth = depth; + return true; + } + return false; + } + - bool isSkip(double approximationThreshold) const override; + double getPriority() const override { + return this->depth; + } + + bool isSkip(double approximationThreshold) const override { + return !this->expand && this->depth > approximationThreshold; + } - bool operator<(DFTExplorationHeuristicDepth const& other) const; + bool operator<(DFTExplorationHeuristicDepth const& other) const { + return this->depth > other.depth; + } }; template class DFTExplorationHeuristicRateRatio : public DFTExplorationHeuristic { public: - DFTExplorationHeuristicRateRatio(size_t id); + DFTExplorationHeuristicRateRatio(size_t id) : DFTExplorationHeuristic(id) { + // Intentionally left empty + } - bool isSkip(double approximationThreshold) const override; + bool updateHeuristicValues(size_t depth, ValueType rate, ValueType exitRate) override; - bool operator<(DFTExplorationHeuristicRateRatio const& other) const; + double getPriority() const override; - private: - double getRateRatio() const; + bool isSkip(double approximationThreshold) const override { + return !this->expand && this->getPriority() < approximationThreshold; + } + + bool operator<(DFTExplorationHeuristicRateRatio const& other) const { + return this->getPriority() < other.getPriority(); + } }; } diff --git a/src/builder/ExplicitDFTModelBuilderApprox.cpp b/src/builder/ExplicitDFTModelBuilderApprox.cpp index 5595a5f49..ed7c1500d 100644 --- a/src/builder/ExplicitDFTModelBuilderApprox.cpp +++ b/src/builder/ExplicitDFTModelBuilderApprox.cpp @@ -290,8 +290,7 @@ namespace storm { // Do not skip absorbing state or if reached by dependencies iter->second.second->markExpand(); } - iter->second.second->updateHeuristicValues(currentExplorationHeuristic->getDepth() + 1, stateProbabilityPair.second, choice.getTotalMass()); - fixQueue = true; + fixQueue = iter->second.second->updateHeuristicValues(currentExplorationHeuristic->getDepth() + 1, stateProbabilityPair.second, choice.getTotalMass()); } } matrixBuilder.finishRow();