Browse Source

Refactored DftExplorationHeuristic

tempestpy_adaptions
Matthias Volk 6 years ago
parent
commit
6afcaa291d
  1. 63
      src/storm-dft/builder/DftExplorationHeuristic.cpp
  2. 86
      src/storm-dft/builder/DftExplorationHeuristic.h

63
src/storm-dft/builder/DftExplorationHeuristic.cpp

@ -1,81 +1,30 @@
#include "DftExplorationHeuristic.h"
#include "storm/adapters/RationalFunctionAdapter.h"
#include "storm/utility/macros.h"
#include "storm/utility/constants.h"
#include "storm/exceptions/NotImplementedException.h"
namespace storm {
namespace builder {
template<typename ValueType>
DFTExplorationHeuristic<ValueType>::DFTExplorationHeuristic(size_t id) : id(id), expand(true), lowerBound(storm::utility::zero<ValueType>()), upperBound(storm::utility::infinity<ValueType>()), depth(0), probability(storm::utility::one<ValueType>()) {
// Intentionally left empty
}
template<typename ValueType>
DFTExplorationHeuristic<ValueType>::DFTExplorationHeuristic(size_t id, DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate) : id(id), expand(false), lowerBound(storm::utility::zero<ValueType>()), upperBound(storm::utility::zero<ValueType>()), depth(predecessor.depth + 1) {
STORM_LOG_ASSERT(storm::utility::zero<ValueType>() < exitRate, "Exit rate is 0");
probability = predecessor.probability * rate/exitRate;
}
template<typename ValueType>
void DFTExplorationHeuristic<ValueType>::setBounds(ValueType lowerBound, ValueType upperBound) {
this->lowerBound = lowerBound;
this->upperBound = upperBound;
}
template<>
bool DFTExplorationHeuristicProbability<double>::updateHeuristicValues(DFTExplorationHeuristic<double> const& predecessor, double rate, double exitRate) {
STORM_LOG_ASSERT(exitRate > 0, "Exit rate is 0");
probability += predecessor.getProbability() * rate/exitRate;
return true;
}
template<>
bool DFTExplorationHeuristicProbability<storm::RationalFunction>::updateHeuristicValues(DFTExplorationHeuristic<storm::RationalFunction> const& predecessor, 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<>
double DFTExplorationHeuristicProbability<double>::getPriority() const {
return probability;
}
template<>
double DFTExplorationHeuristicProbability<storm::RationalFunction>::getPriority() const {
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic rate ration does not work for rational functions.");
}
template<>
bool DFTExplorationHeuristicBoundDifference<double>::updateHeuristicValues(DFTExplorationHeuristic<double> const& predecessor, double rate, double exitRate) {
STORM_LOG_ASSERT(exitRate > 0, "Exit rate is 0");
probability += predecessor.getProbability() * rate/exitRate;
return true;
}
template<>
bool DFTExplorationHeuristicBoundDifference<storm::RationalFunction>::updateHeuristicValues(DFTExplorationHeuristic<storm::RationalFunction> const& predecessor, 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<typename ValueType>
void DFTExplorationHeuristicBoundDifference<ValueType>::setBounds(ValueType lowerBound, ValueType upperBound) {
this->lowerBound = lowerBound;
this->upperBound = upperBound;
difference = (storm::utility::one<ValueType>() / upperBound) - (storm::utility::one<ValueType>() / lowerBound);
double DFTExplorationHeuristicProbability<ValueType>::getPriority() const {
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic 'probability' does not work for this data type.");
}
template<>
double DFTExplorationHeuristicBoundDifference<double>::getPriority() const {
double difference = (storm::utility::one<double>() / upperBound) - (storm::utility::one<double>() / lowerBound);
return probability * difference;
}
template<>
double DFTExplorationHeuristicBoundDifference<storm::RationalFunction>::getPriority() const {
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic bound difference does not work for rational functions.");
template<typename ValueType>
double DFTExplorationHeuristicBoundDifference<ValueType>::getPriority() const {
STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Heuristic 'bound difference' does not work for this data type.");
}
// Instantiate templates.

86
src/storm-dft/builder/DftExplorationHeuristic.h

@ -1,6 +1,10 @@
#pragma once
#include <memory>
#include "storm/utility/constants.h"
#include "storm/utility/macros.h"
namespace storm {
namespace builder {
@ -12,25 +16,32 @@ namespace storm {
/*!
* General super class for appoximation heuristics.
* General super class for approximation heuristics.
*/
template<typename ValueType>
class DFTExplorationHeuristic {
public:
DFTExplorationHeuristic(size_t id);
explicit DFTExplorationHeuristic(size_t id) : id(id), expand(true), lowerBound(storm::utility::zero<ValueType>()), upperBound(storm::utility::infinity<ValueType>()), depth(0), probability(storm::utility::one<ValueType>()) {
// Intentionally left empty
}
DFTExplorationHeuristic(size_t id, DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate);
DFTExplorationHeuristic(size_t id, DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate) : id(id), expand(false), lowerBound(storm::utility::zero<ValueType>()), upperBound(storm::utility::zero<ValueType>()), depth(predecessor.depth + 1), probability(storm::utility::one<ValueType>()) {
this->updateHeuristicValues(predecessor, rate, exitRate);
}
virtual ~DFTExplorationHeuristic() = default;
void setBounds(ValueType lowerBound, ValueType upperBound);
virtual bool updateHeuristicValues(DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate) = 0;
virtual double getPriority() const = 0;
void setBounds(ValueType lowerBound, ValueType upperBound) {
this->lowerBound = lowerBound;
this->upperBound = upperBound;
}
virtual bool isSkip(double approximationThreshold) const = 0;
virtual bool updateHeuristicValues(DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate) {
STORM_LOG_ASSERT(!storm::utility::isZero<ValueType>(exitRate), "Exit rate is 0");
probability += predecessor.getProbability() * rate/exitRate;
return true;
}
void markExpand() {
expand = true;
@ -40,7 +51,7 @@ namespace storm {
return id;
}
bool isExpand() {
bool isExpand() const {
return expand;
}
@ -60,6 +71,16 @@ namespace storm {
return upperBound;
}
virtual double getPriority() const = 0;
virtual bool isSkip(double approximationThreshold) const {
return !this->isExpand() && this->getPriority() < approximationThreshold;
}
virtual bool operator<(DFTExplorationHeuristic<ValueType> const& other) const {
return this->getPriority() < other.getPriority();
}
protected:
size_t id;
bool expand;
@ -76,7 +97,7 @@ namespace storm {
// Intentionally left empty
}
DFTExplorationHeuristicNone(size_t id, DFTExplorationHeuristicNone<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
DFTExplorationHeuristicNone(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
// Intentionally left empty
}
@ -91,10 +112,6 @@ namespace storm {
bool isSkip(double) const override {
return false;
}
bool operator<(DFTExplorationHeuristicNone<ValueType> const& other) const {
return this->id > other.id;
}
};
template<typename ValueType>
@ -104,7 +121,7 @@ namespace storm {
// Intentionally left empty
}
DFTExplorationHeuristicDepth(size_t id, DFTExplorationHeuristicDepth<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
DFTExplorationHeuristicDepth(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
// Intentionally left empty
}
@ -116,17 +133,16 @@ namespace storm {
return false;
}
double getPriority() const override {
return this->depth;
}
bool isSkip(double approximationThreshold) const override {
return !this->expand && this->depth > approximationThreshold;
return !this->expand && this->getPriority() > approximationThreshold;
}
bool operator<(DFTExplorationHeuristicDepth<ValueType> const& other) const {
return this->depth > other.depth;
bool operator<(DFTExplorationHeuristic<ValueType> const& other) const override {
return this->getPriority() > other.getPriority();
}
};
@ -137,21 +153,11 @@ namespace storm {
// Intentionally left empty
}
DFTExplorationHeuristicProbability(size_t id, DFTExplorationHeuristicProbability<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
DFTExplorationHeuristicProbability(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
// Intentionally left empty
}
bool updateHeuristicValues(DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) override;
double getPriority() const override;
bool isSkip(double approximationThreshold) const override {
return !this->expand && this->getPriority() < approximationThreshold;
}
bool operator<(DFTExplorationHeuristicProbability<ValueType> const& other) const {
return this->getPriority() < other.getPriority();
}
};
template<typename ValueType>
@ -161,28 +167,12 @@ namespace storm {
// Intentionally left empty
}
DFTExplorationHeuristicBoundDifference(size_t id, DFTExplorationHeuristicBoundDifference<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
DFTExplorationHeuristicBoundDifference(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) : DFTExplorationHeuristic<ValueType>(id, predecessor, rate, exitRate) {
// Intentionally left empty
}
void setBounds(ValueType lowerBound, ValueType upperBound);
bool updateHeuristicValues(DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) override;
double getPriority() const override;
bool isSkip(double approximationThreshold) const override {
return !this->expand && this->getPriority() < approximationThreshold;
}
bool operator<(DFTExplorationHeuristicBoundDifference<ValueType> const& other) const {
return this->getPriority() < other.getPriority();
}
private:
ValueType difference;
};
}
}
Loading…
Cancel
Save