Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Extremum.h
Go to the documentation of this file.
1#pragma once
2
3#include <limits>
4#include <optional>
5#include <type_traits>
6
8
9namespace storm::utility {
10
14template<storm::OptimizationDirection Dir, typename ValueType>
15class Extremum {
16 public:
17 Extremum() = default;
18 Extremum(ValueType const& value);
19 Extremum(ValueType&& value);
20 Extremum(Extremum const&) = default;
21 Extremum(Extremum&&) = default;
22 Extremum& operator=(Extremum const&) = default;
24 ~Extremum() = default;
25
30 Extremum& operator=(ValueType const& value);
31
36 Extremum& operator=(ValueType&& value);
37
42 bool better(ValueType const& value) const;
43
49 bool operator&=(Extremum const& other);
50
56 bool operator&=(Extremum&& other);
57
63 bool operator&=(ValueType const& value);
64
70 bool operator&=(ValueType&& value);
71
75 bool empty() const;
76
81 ValueType const& operator*() const;
82
87 ValueType& operator*();
88
92 std::optional<ValueType> getOptionalValue() const;
93
97 void reset();
98
99 private:
101 static bool const SupportsInfinity = std::numeric_limits<ValueType>::is_iec559;
102
104 struct DefaultData {
105 ValueType value;
106 bool empty{true};
107 };
108
110 struct DataInfinity {
111 ValueType constexpr baseValue() const {
112 if constexpr (storm::solver::minimize(Dir)) {
113 return std::numeric_limits<ValueType>::infinity();
114 } else {
115 static_assert(storm::solver::maximize(Dir));
116 return -std::numeric_limits<ValueType>::infinity();
117 }
118 }
119 ValueType value{baseValue()};
120 };
121
123 std::conditional_t<SupportsInfinity, DataInfinity, DefaultData> data;
124};
125
126template<typename ValueType>
128template<typename ValueType>
130
131} // namespace storm::utility
Stores and manages an extremal (maximal or minimal) value.
Definition Extremum.h:15
bool operator&=(Extremum const &other)
Updates the stored value, if the given extremal value is better.
Definition Extremum.cpp:56
ValueType const & operator*() const
Definition Extremum.cpp:105
std::optional< ValueType > getOptionalValue() const
Definition Extremum.cpp:117
bool better(ValueType const &value) const
Definition Extremum.cpp:41
Extremum(Extremum &&)=default
Extremum(Extremum const &)=default
void reset()
Forgets the extremal value so that this represents the extremum over an empty set.
Definition Extremum.cpp:126
Extremum & operator=(Extremum &&)=default
Extremum & operator=(Extremum const &)=default
SFTBDDChecker::ValueType ValueType
bool constexpr maximize(OptimizationDirection d)
bool constexpr minimize(OptimizationDirection d)