Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TerminationCondition.cpp
Go to the documentation of this file.
2
9
10namespace storm {
11namespace solver {
12
13template<typename ValueType>
14bool TerminationCondition<ValueType>::terminateNow(std::vector<ValueType> const& currentValues, SolverGuarantee const& guarantee) const {
15 return terminateNow([&currentValues](uint64_t const& i) { return currentValues[i]; }, guarantee);
16}
17
18template<typename ValueType>
19bool NoTerminationCondition<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter, SolverGuarantee const& guarantee) const {
20 return false;
21}
22
23template<typename ValueType>
27
28template<typename ValueType>
30 bool strict)
31 : threshold(threshold), filter(filter), strict(strict) {
32 // Intentionally left empty.
33}
34
35template<typename ValueType>
36bool TerminateIfFilteredSumExceedsThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
37 SolverGuarantee const& guarantee) const {
38 if (guarantee != SolverGuarantee::LessOrEqual) {
39 return false;
40 }
41
42 ValueType sum = storm::utility::zero<ValueType>();
43 for (auto pos : filter) {
44 sum += valueGetter(pos);
45 // Exiting this loop early is not possible as values might be negative
46 }
47 return strict ? sum > this->threshold : sum >= this->threshold;
48}
49
50template<typename ValueType>
54
55template<typename ValueType>
57 ValueType const& threshold, bool useMinimum)
58 : TerminateIfFilteredSumExceedsThreshold<ValueType>(filter, threshold, strict), useMinimum(useMinimum) {
59 // Intentionally left empty.
60 STORM_LOG_THROW(!this->filter.empty(), storm::exceptions::InvalidArgumentException, "Empty Filter; Can not take extremum over empty set.");
61 cachedExtremumIndex = this->filter.getNextSetIndex(0);
62}
63
64template<typename ValueType>
65bool TerminateIfFilteredExtremumExceedsThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
66 SolverGuarantee const& guarantee) const {
67 if (guarantee != SolverGuarantee::LessOrEqual) {
68 return false;
69 }
70
71 ValueType extremum = valueGetter(cachedExtremumIndex);
72 if (useMinimum && (this->strict ? extremum <= this->threshold : extremum < this->threshold)) {
73 // The extremum can only become smaller so we can return right now.
74 return false;
75 }
76
77 if (useMinimum) {
78 if (this->strict) {
79 for (auto pos : this->filter) {
80 extremum = std::min(valueGetter(pos), extremum);
81 if (extremum <= this->threshold) {
82 cachedExtremumIndex = pos;
83 return false;
84 }
85 }
86 } else {
87 for (auto pos : this->filter) {
88 extremum = std::min(valueGetter(pos), extremum);
89 if (extremum < this->threshold) {
90 cachedExtremumIndex = pos;
91 return false;
92 }
93 }
94 }
95 } else {
96 for (auto pos : this->filter) {
97 extremum = std::max(valueGetter(pos), extremum);
98 }
99 }
100
101 return this->strict ? extremum > this->threshold : extremum >= this->threshold;
102}
103
104template<typename ValueType>
108
109template<typename ValueType>
111 ValueType const& threshold, bool useMinimum)
112 : TerminateIfFilteredSumExceedsThreshold<ValueType>(filter, threshold, strict), useMinimum(useMinimum) {
113 STORM_LOG_THROW(!this->filter.empty(), storm::exceptions::InvalidArgumentException, "Empty Filter; Can not take extremum over empty set.");
114 cachedExtremumIndex = this->filter.getNextSetIndex(0);
115}
116
117template<typename ValueType>
118bool TerminateIfFilteredExtremumBelowThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
119 SolverGuarantee const& guarantee) const {
120 if (guarantee != SolverGuarantee::GreaterOrEqual) {
121 return false;
122 }
123
124 ValueType extremum = valueGetter(cachedExtremumIndex);
125 if (!useMinimum && (this->strict ? extremum >= this->threshold : extremum > this->threshold)) {
126 // The extremum can only become larger so we can return right now.
127 return false;
128 }
129
130 if (useMinimum) {
131 for (auto pos : this->filter) {
132 extremum = std::min(valueGetter(pos), extremum);
133 }
134 } else {
135 if (this->strict) {
136 for (auto pos : this->filter) {
137 extremum = std::max(valueGetter(pos), extremum);
138 if (extremum >= this->threshold) {
139 cachedExtremumIndex = pos;
140 return false;
141 }
142 }
143 } else {
144 for (auto pos : this->filter) {
145 extremum = std::max(valueGetter(pos), extremum);
146 if (extremum > this->threshold) {
147 cachedExtremumIndex = pos;
148 return false;
149 }
150 }
151 }
152 }
153
154 return this->strict ? extremum < this->threshold : extremum <= this->threshold;
155}
156
157template<typename ValueType>
161
162template class TerminationCondition<double>;
163template class NoTerminationCondition<double>;
167
173
179
180} // namespace solver
181} // namespace storm
virtual bool terminateNow(std::function< ValueType(uint64_t const &)> const &valueGetter, SolverGuarantee const &guarantee=SolverGuarantee::None) const override
virtual bool requiresGuarantee(SolverGuarantee const &guarantee) const override
Retrieves whether the termination criterion requires the given guarantee in order to decide terminati...
TerminateIfFilteredExtremumBelowThreshold(storm::storage::BitVector const &filter, bool strict, ValueType const &threshold, bool useMinimum)
bool terminateNow(std::function< ValueType(uint64_t const &)> const &valueGetter, SolverGuarantee const &guarantee=SolverGuarantee::None) const override
virtual bool requiresGuarantee(SolverGuarantee const &guarantee) const override
Retrieves whether the termination criterion requires the given guarantee in order to decide terminati...
TerminateIfFilteredExtremumExceedsThreshold(storm::storage::BitVector const &filter, bool strict, ValueType const &threshold, bool useMinimum)
bool terminateNow(std::function< ValueType(uint64_t const &)> const &valueGetter, SolverGuarantee const &guarantee=SolverGuarantee::None) const override
virtual bool requiresGuarantee(SolverGuarantee const &guarantee) const override
Retrieves whether the termination criterion requires the given guarantee in order to decide terminati...
virtual bool requiresGuarantee(SolverGuarantee const &guarantee) const override
Retrieves whether the termination criterion requires the given guarantee in order to decide terminati...
bool terminateNow(std::function< ValueType(uint64_t const &)> const &valueGetter, SolverGuarantee const &guarantee=SolverGuarantee::None) const override
TerminateIfFilteredSumExceedsThreshold(storm::storage::BitVector const &filter, ValueType const &threshold, bool strict)
virtual bool terminateNow(std::vector< ValueType > const &currentValues, SolverGuarantee const &guarantee=SolverGuarantee::None) const
Retrieves whether the guarantee provided by the solver for the current result is sufficient to termin...
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
uint64_t getNextSetIndex(uint64_t startingIndex) const
Retrieves the index of the bit that is the next bit set to true in the bit vector.
bool empty() const
Retrieves whether no bits are set to true in this bit vector.
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30