Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
LowerUpperBoundsComputer.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4#include <functional>
5
15
16namespace storm::modelchecker {
17
18template<typename ValueType, bool Lower>
19std::vector<ValueType> computeLowerOrUpperBoundsTotalReward(storm::storage::SparseMatrix<ValueType> const& matrix, std::vector<ValueType> const& offsets,
20 storm::storage::BitVector const& exitRows, std::vector<ValueType> const& exitProbabilities,
21 std::optional<storm::OptimizationDirection> dir) {
22 STORM_LOG_ASSERT(matrix.hasTrivialRowGrouping() || dir.has_value(), "Optimization direction needs to be given if matrix is nondeterministic.");
24 // Try to compute a lower and an upper bound the "easy" way
25 auto const insideRows = ~exitRows;
26 std::conditional_t<Lower, std::greater_equal<ValueType>, std::less_equal<ValueType>> comp;
27 bool const canEasy =
28 std::all_of(insideRows.begin(), insideRows.end(), [&offsets, &comp](uint64_t row) { return comp(offsets[row], storm::utility::zero<ValueType>()); });
29
30 if (canEasy) {
31 for (auto const row : exitRows) {
32 STORM_LOG_ASSERT(!storm::utility::isZero(exitProbabilities.at(row)), "Exit probability must not be zero.");
33 ValueType const rowValue = offsets[row] / exitProbabilities[row];
34 globalBound &= rowValue;
35 }
36 }
37
38 // We might have to invoke the respective reward bound computers.
39 if (!canEasy) {
40 if (dir.has_value() && (Lower == minimize(*dir))) {
41 // Baier's algorithm provides a lower and an upper bound that hold for all strategies. It supports positive and negative rewards.
42 auto const bounds =
44 globalBound &= Lower ? bounds.lower : bounds.upper;
45 } else {
46 // For lower bounds, we actually compute upper bounds for the negated rewards.
47 // For upper bounds, we potentially cut away negative offsets.
48 std::optional<std::vector<ValueType>> tmpOffsets;
49 if (Lower) {
50 tmpOffsets.emplace(offsets.size());
51 storm::utility::vector::applyPointwise(offsets, *tmpOffsets,
52 [](ValueType const& v) { return std::max<ValueType>(storm::utility::zero<ValueType>(), -v); });
53 } else if (std::any_of(offsets.begin(), offsets.end(), [](ValueType const& v) { return v < storm::utility::zero<ValueType>(); })) {
54 tmpOffsets.emplace(offsets.size());
55 storm::utility::vector::applyPointwise(offsets, *tmpOffsets, [](ValueType const& v) { return std::max(storm::utility::zero<ValueType>(), v); });
56 }
58 matrix, tmpOffsets.has_value() ? tmpOffsets.value() : offsets, exitProbabilities)
60 if (Lower) {
61 storm::utility::vector::applyPointwise(bounds, bounds, [](ValueType const& v) { return -v; });
62 }
63 return bounds;
64 }
65 }
66 STORM_LOG_ASSERT(!globalBound.empty(), "Could not compute lower or upper bound for total reward.");
67 return std::vector<ValueType>(matrix.getRowGroupCount(), *globalBound);
68}
69
70template std::vector<double> computeLowerOrUpperBoundsTotalReward<double, true>(storm::storage::SparseMatrix<double> const&, std::vector<double> const&,
71 storm::storage::BitVector const&, std::vector<double> const&,
72 std::optional<storm::OptimizationDirection>);
73template std::vector<double> computeLowerOrUpperBoundsTotalReward<double, false>(storm::storage::SparseMatrix<double> const&, std::vector<double> const&,
74 storm::storage::BitVector const&, std::vector<double> const&,
75 std::optional<storm::OptimizationDirection>);
77 storm::storage::SparseMatrix<storm::RationalNumber> const&, std::vector<storm::RationalNumber> const&, storm::storage::BitVector const&,
78 std::vector<storm::RationalNumber> const&, std::optional<storm::OptimizationDirection>);
80 storm::storage::SparseMatrix<storm::RationalNumber> const&, std::vector<storm::RationalNumber> const&, storm::storage::BitVector const&,
81 std::vector<storm::RationalNumber> const&, std::optional<storm::OptimizationDirection>);
82
83} // namespace storm::modelchecker
Bounds computeTotalRewardBounds(std::vector< ValueType > const &rewards)
Computes a lower and an upper bound on the expected total rewards.
std::vector< ValueType > computeUpperBounds()
Computes upper bounds on the expected rewards.
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
bool hasTrivialRowGrouping() const
Retrieves whether the matrix has a trivial row grouping.
Stores and manages an extremal (maximal or minimal) value.
Definition Extremum.h:17
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:9
std::vector< ValueType > computeLowerOrUpperBoundsTotalReward(storm::storage::SparseMatrix< ValueType > const &matrix, std::vector< ValueType > const &offsets, storm::storage::BitVector const &exitRows, std::vector< ValueType > const &exitProbabilities, std::optional< storm::OptimizationDirection > dir)
Computes for each state a lower (if Lower is true) or an upper (otherwise) bound on the optimal total...
template std::vector< storm::RationalNumber > computeLowerOrUpperBoundsTotalReward< storm::RationalNumber, true >(storm::storage::SparseMatrix< storm::RationalNumber > const &, std::vector< storm::RationalNumber > const &, storm::storage::BitVector const &, std::vector< storm::RationalNumber > const &, std::optional< storm::OptimizationDirection >)
template std::vector< double > computeLowerOrUpperBoundsTotalReward< double, true >(storm::storage::SparseMatrix< double > const &, std::vector< double > const &, storm::storage::BitVector const &, std::vector< double > const &, std::optional< storm::OptimizationDirection >)
template std::vector< storm::RationalNumber > computeLowerOrUpperBoundsTotalReward< storm::RationalNumber, false >(storm::storage::SparseMatrix< storm::RationalNumber > const &, std::vector< storm::RationalNumber > const &, storm::storage::BitVector const &, std::vector< storm::RationalNumber > const &, std::optional< storm::OptimizationDirection >)
template std::vector< double > computeLowerOrUpperBoundsTotalReward< double, false >(storm::storage::SparseMatrix< double > const &, std::vector< double > const &, storm::storage::BitVector const &, std::vector< double > const &, std::optional< storm::OptimizationDirection >)
void applyPointwise(std::vector< InValueType1 > const &firstOperand, std::vector< InValueType2 > const &secondOperand, std::vector< OutValueType > &target, Operation f=Operation())
Applies the given operation pointwise on the two given vectors and writes the result to the third vec...
Definition vector.h:375
bool isZero(ValueType const &a)
Definition constants.cpp:44
ValueType zero()
Definition constants.cpp:26