Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
TerminationCondition.cpp
Go to the documentation of this file.
3
5
8
9namespace storm {
10namespace solver {
11
12template<typename ValueType>
13bool TerminationCondition<ValueType>::terminateNow(std::vector<ValueType> const& currentValues, SolverGuarantee const& guarantee) const {
14 return terminateNow([&currentValues](uint64_t const& i) { return currentValues[i]; }, guarantee);
15}
16
17template<typename ValueType>
18bool NoTerminationCondition<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter, SolverGuarantee const& guarantee) const {
19 return false;
20}
21
22template<typename ValueType>
26
27template<typename ValueType>
29 bool strict)
30 : threshold(threshold), filter(filter), strict(strict) {
31 // Intentionally left empty.
32}
33
34template<typename ValueType>
35bool TerminateIfFilteredSumExceedsThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
36 SolverGuarantee const& guarantee) const {
37 if (guarantee != SolverGuarantee::LessOrEqual) {
38 return false;
39 }
40
41 ValueType sum = storm::utility::zero<ValueType>();
42 for (auto pos : filter) {
43 sum += valueGetter(pos);
44 // Exiting this loop early is not possible as values might be negative
45 }
46 return strict ? sum > this->threshold : sum >= this->threshold;
47}
48
49template<typename ValueType>
53
54template<typename ValueType>
56 ValueType const& threshold, bool useMinimum)
57 : TerminateIfFilteredSumExceedsThreshold<ValueType>(filter, threshold, strict), useMinimum(useMinimum) {
58 // Intentionally left empty.
59 STORM_LOG_THROW(!this->filter.empty(), storm::exceptions::InvalidArgumentException, "Empty Filter; Can not take extremum over empty set.");
60 cachedExtremumIndex = this->filter.getNextSetIndex(0);
61}
62
63template<typename ValueType>
64bool TerminateIfFilteredExtremumExceedsThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
65 SolverGuarantee const& guarantee) const {
66 if (guarantee != SolverGuarantee::LessOrEqual) {
67 return false;
68 }
69
70 ValueType extremum = valueGetter(cachedExtremumIndex);
71 if (useMinimum && (this->strict ? extremum <= this->threshold : extremum < this->threshold)) {
72 // The extremum can only become smaller so we can return right now.
73 return false;
74 }
75
76 if (useMinimum) {
77 if (this->strict) {
78 for (auto pos : this->filter) {
79 extremum = std::min(valueGetter(pos), extremum);
80 if (extremum <= this->threshold) {
81 cachedExtremumIndex = pos;
82 return false;
83 }
84 }
85 } else {
86 for (auto pos : this->filter) {
87 extremum = std::min(valueGetter(pos), extremum);
88 if (extremum < this->threshold) {
89 cachedExtremumIndex = pos;
90 return false;
91 }
92 }
93 }
94 } else {
95 for (auto pos : this->filter) {
96 extremum = std::max(valueGetter(pos), extremum);
97 }
98 }
99
100 return this->strict ? extremum > this->threshold : extremum >= this->threshold;
101}
102
103template<typename ValueType>
107
108template<typename ValueType>
110 ValueType const& threshold, bool useMinimum)
111 : TerminateIfFilteredSumExceedsThreshold<ValueType>(filter, threshold, strict), useMinimum(useMinimum) {
112 STORM_LOG_THROW(!this->filter.empty(), storm::exceptions::InvalidArgumentException, "Empty Filter; Can not take extremum over empty set.");
113 cachedExtremumIndex = this->filter.getNextSetIndex(0);
114}
115
116template<typename ValueType>
117bool TerminateIfFilteredExtremumBelowThreshold<ValueType>::terminateNow(std::function<ValueType(uint64_t const&)> const& valueGetter,
118 SolverGuarantee const& guarantee) const {
119 if (guarantee != SolverGuarantee::GreaterOrEqual) {
120 return false;
121 }
122
123 ValueType extremum = valueGetter(cachedExtremumIndex);
124 if (!useMinimum && (this->strict ? extremum >= this->threshold : extremum > this->threshold)) {
125 // The extremum can only become larger so we can return right now.
126 return false;
127 }
128
129 if (useMinimum) {
130 for (auto pos : this->filter) {
131 extremum = std::min(valueGetter(pos), extremum);
132 }
133 } else {
134 if (this->strict) {
135 for (auto pos : this->filter) {
136 extremum = std::max(valueGetter(pos), extremum);
137 if (extremum >= this->threshold) {
138 cachedExtremumIndex = pos;
139 return false;
140 }
141 }
142 } else {
143 for (auto pos : this->filter) {
144 extremum = std::max(valueGetter(pos), extremum);
145 if (extremum > this->threshold) {
146 cachedExtremumIndex = pos;
147 return false;
148 }
149 }
150 }
151 }
152
153 return this->strict ? extremum < this->threshold : extremum <= this->threshold;
154}
155
156template<typename ValueType>
160
161template class TerminationCondition<double>;
162template class NoTerminationCondition<double>;
166
172
178
179} // namespace solver
180} // 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:18
uint_fast64_t getNextSetIndex(uint_fast64_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
LabParser.cpp.
Definition cli.cpp:18