Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DftExplorationHeuristic.h
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4
5#include <memory>
6
10
11namespace storm::dft {
12namespace builder {
13
18
22template<typename ValueType>
24 public:
25 explicit DFTExplorationHeuristic(size_t id) : id(id), expand(false) {
26 // Intentionally left empty
27 }
28
29 virtual ~DFTExplorationHeuristic() = default;
30
31 virtual bool updateHeuristicValues(DFTExplorationHeuristic const& predecessor, ValueType rate, ValueType exitRate) = 0;
32
33 virtual void setBounds(ValueType /*lowerBound*/, ValueType /*upperBound*/) {
34 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Should be handled by specialized heuristic.");
35 }
36
37 void markExpand() {
38 expand = true;
39 }
40
41 size_t getId() const {
42 return id;
43 }
44
45 bool isExpand() const {
46 return expand;
47 }
48
49 virtual size_t getDepth() const {
50 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Should be handled by specialized heuristic.");
51 }
52
53 virtual ValueType getProbability() const {
54 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Should be handled by specialized heuristic.");
55 }
56
57 virtual ValueType getLowerBound() const {
58 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Should be handled by specialized heuristic.");
59 }
60
61 virtual ValueType getUpperBound() const {
62 STORM_LOG_THROW(false, storm::exceptions::NotImplementedException, "Should be handled by specialized heuristic.");
63 }
64
65 virtual double getPriority() const = 0;
66
67 virtual bool isSkip(double approximationThreshold) const {
68 return !this->isExpand() && this->getPriority() < approximationThreshold;
69 }
70
71 virtual bool operator<(DFTExplorationHeuristic<ValueType> const& other) const {
72 return this->getPriority() < other.getPriority();
73 }
74
75 protected:
76 size_t id;
77 bool expand;
78};
79
80template<typename ValueType>
82 public:
84
86 : DFTExplorationHeuristic<ValueType>(id), depth(predecessor.getDepth() + 1) {}
87
88 bool updateHeuristicValues(DFTExplorationHeuristic<ValueType> const& predecessor, ValueType, ValueType) override {
89 if (predecessor.getDepth() + 1 < this->depth) {
90 this->depth = predecessor.getDepth() + 1;
91 return true;
92 }
93 return false;
94 }
95
96 size_t getDepth() const override {
97 return depth;
98 }
99
100 double getPriority() const override {
101 return this->depth;
102 }
103
104 bool isSkip(double approximationThreshold) const override {
105 return !this->expand && this->getPriority() > approximationThreshold;
106 }
107
108 bool operator<(DFTExplorationHeuristic<ValueType> const& other) const override {
109 return this->getPriority() > other.getPriority();
110 }
111
112 protected:
113 size_t depth;
114};
115
116template<typename ValueType>
118 public:
120
121 DFTExplorationHeuristicProbability(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate)
122 : DFTExplorationHeuristic<ValueType>(id), probability(storm::utility::zero<ValueType>()) {
123 this->updateHeuristicValues(predecessor, rate, exitRate);
124 }
125
126 bool updateHeuristicValues(DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate) override {
127 STORM_LOG_ASSERT(!storm::utility::isZero<ValueType>(exitRate), "Exit rate is 0.");
128 probability += predecessor.getProbability() * rate / exitRate;
129 return true;
130 }
131
132 ValueType getProbability() const override {
133 return probability;
134 }
135
136 double getPriority() const override;
137
138 protected:
139 ValueType probability;
140};
141
142template<typename ValueType>
144 public:
146
147 DFTExplorationHeuristicBoundDifference(size_t id, DFTExplorationHeuristic<ValueType> const& predecessor, ValueType rate, ValueType exitRate)
148 : DFTExplorationHeuristicProbability<ValueType>(id, predecessor, rate, exitRate) {}
149
150 void setBounds(ValueType lowerBound, ValueType upperBound) override {
151 this->lowerBound = lowerBound;
152 this->upperBound = upperBound;
153 }
154
155 ValueType getLowerBound() const override {
156 STORM_LOG_ASSERT(lowerBound.has_value(), "Bounds have not been set for this heuristic.");
157 return *lowerBound;
158 }
159
160 ValueType getUpperBound() const override {
161 STORM_LOG_ASSERT(upperBound.has_value(), "Bounds have not been set for this heuristic.");
162 return *upperBound;
163 }
164
165 double getPriority() const override;
166
167 protected:
170 std::optional<ValueType> lowerBound;
171 std::optional<ValueType> upperBound;
172};
173
174} // namespace builder
175} // namespace storm::dft
std::optional< ValueType > lowerBound
The bounds are set by the model builder before the heuristic enters the exploration queue.
DFTExplorationHeuristicBoundDifference(size_t id, DFTExplorationHeuristic< ValueType > const &predecessor, ValueType rate, ValueType exitRate)
void setBounds(ValueType lowerBound, ValueType upperBound) override
DFTExplorationHeuristicDepth(size_t id, DFTExplorationHeuristic< ValueType > const &predecessor)
bool operator<(DFTExplorationHeuristic< ValueType > const &other) const override
bool updateHeuristicValues(DFTExplorationHeuristic< ValueType > const &predecessor, ValueType, ValueType) override
bool isSkip(double approximationThreshold) const override
General super class for approximation heuristics.
virtual bool isSkip(double approximationThreshold) const
virtual bool operator<(DFTExplorationHeuristic< ValueType > const &other) const
virtual bool updateHeuristicValues(DFTExplorationHeuristic const &predecessor, ValueType rate, ValueType exitRate)=0
DFTExplorationHeuristicProbability(size_t id, DFTExplorationHeuristic< ValueType > const &predecessor, ValueType rate, ValueType exitRate)
bool updateHeuristicValues(DFTExplorationHeuristic< ValueType > const &predecessor, ValueType rate, ValueType exitRate) override
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
ApproximationHeuristic
Enum representing the heuristic used for deciding which states to expand.
bool isZero(ValueType const &a)
Definition constants.cpp:42