21template<
typename ValueType>
23 std::optional<std::vector<ValueType>>
lower;
24 std::optional<std::vector<ValueType>>
upper;
30 return lower.has_value();
37 return upper.has_value();
50 bool encloses(std::vector<ValueType>
const& values)
const {
51 auto const isBoundedBy = [&values](std::optional<std::vector<ValueType>>
const& bound,
bool fromBelow) {
52 if (!bound.has_value()) {
55 if (bound->size() != values.size()) {
58 for (uint64_t i = 0; i < values.size(); ++i) {
59 if (fromBelow ? (*bound)[i] > values[i] : (*bound)[i] < values[i]) {
65 return isBoundedBy(
lower,
true) && isBoundedBy(
upper,
false);
78 bool isWithinPrecision(std::vector<ValueType>
const& values, ValueType
const& precision,
bool relative)
const {
82 STORM_LOG_THROW(
lower->size() == values.size() &&
upper->size() == values.size(), storm::exceptions::InvalidArgumentException,
83 "The given values do not match the size of the bounds.");
85 for (uint64_t i = 0; i < values.size(); ++i) {
86 ValueType
const& low = (*lower)[i];
87 ValueType
const& up = (*upper)[i];
88 ValueType allowed = precision;
95 if (!(values[i] - low <= allowed) || !(up - values[i] <= allowed)) {
105 void setExact(std::vector<ValueType>
const& values) {
116 std::ranges::transform(*
lower,
lower->begin(), oneMinus);
119 std::ranges::transform(*
upper,
upper->begin(), oneMinus);
128 template<
typename Function>
144 void widenTo(std::vector<ValueType>
const& values) {
146 std::ranges::transform(*
lower, values,
lower->begin(), [](ValueType
const& bound, ValueType
const& value) { return std::min(bound, value); });
149 std::ranges::transform(*
upper, values,
upper->begin(), [](ValueType
const& bound, ValueType
const& value) { return std::max(bound, value); });
157 lower = std::nullopt;
158 upper = std::nullopt;
#define STORM_LOG_THROW(cond, exception, message)
ValueType abs(ValueType const &number)
Sound lower and upper bounds on a solution vector.
bool hasAny() const
Returns true if at least one of the bounds is set.
std::optional< std::vector< ValueType > > lower
bool hasUpper() const
Returns true if the upper bound is set.
auto transform(Function const &function) const
Applies the given function to whichever of the bounds are set, e.g.
bool hasLower() const
Returns true if the lower bound is set.
std::optional< std::vector< ValueType > > upper
void widenTo(std::vector< ValueType > const &values)
Widens whichever bounds are set until they enclose the given values.
void invertProbabilityBounds()
Turns bounds on a probability p into bounds on 1-p, i.e.
void clear()
Clears both bounds.
bool isWithinPrecision(std::vector< ValueType > const &values, ValueType const &precision, bool relative) const
Returns true if both bounds are set and neither is further from its value than the given precision al...
bool encloses(std::vector< ValueType > const &values) const
Returns true if every one of the given values lies within the bounds that are set.
bool isExact() const
Returns true if both bounds are set and coincide.
void setExact(std::vector< ValueType > const &values)
Sets both bounds to the given values, i.e.