14template<
typename ValueType,
bool TrivialRowGrouping>
17 : viOperator(viOperator) {
21template<
typename ValueType, OptimizationDirection Dir,
bool Smooth,
bool RoundingTowardsInf>
26 STORM_LOG_ASSERT(!Smooth,
"Gamma must be set for smooth interval iteration.");
31 void firstRow(std::pair<ValueType, ValueType>&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
32 xBest = std::move(value.first);
33 yBest = std::move(value.second);
36 void nextRow(std::pair<ValueType, ValueType>&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
37 xBest &= std::move(value.first);
38 yBest &= std::move(value.second);
41 void applyUpdate(ValueType& xCurr, ValueType& yCurr, [[maybe_unused]] uint64_t rowGroup) {
42 if constexpr (Smooth) {
43 if constexpr (RoundingTowardsInf) {
45 auto const diff = xCurr - *xBest;
46 xCurr = *xBest + gamma *
diff;
50 auto const diff = *xBest - xCurr;
51 xCurr = *xBest - gamma *
diff;
52 if constexpr (std::is_same_v<ValueType, double>) {
53 if (xCurr == *xBest) {
54 xCurr = std::nextafter(xCurr, xCurr - 1.0);
60 auto const diff = yCurr - *yBest;
61 yCurr = *yBest + gamma *
diff;
62 if constexpr (!RoundingTowardsInf && std::is_same_v<ValueType, double>) {
63 if (yCurr == *yBest) {
64 yCurr = std::nextafter(yCurr, yCurr + 1.0);
69 if constexpr (RoundingTowardsInf) {
70 xCurr = std::min(xCurr, *xBest);
72 xCurr = std::max(xCurr, *xBest);
74 yCurr = std::min(yCurr, *yBest);
93 ValueType
const gamma;
96template<
typename ValueType,
bool RoundingTowardsInf>
97bool checkConvergence(std::pair<std::vector<ValueType>, std::vector<ValueType>>
const& xy, uint64_t& convergenceCheckState,
98 std::function<
void()>
const& getNextConvergenceCheckState,
bool relative, ValueType
const& precision) {
100 for (; convergenceCheckState < xy.first.size(); getNextConvergenceCheckState()) {
101 ValueType
const& l = RoundingTowardsInf ? -xy.first[convergenceCheckState] : xy.first[convergenceCheckState];
102 ValueType
const& u = xy.second[convergenceCheckState];
104 if ((u - l) > l * precision) {
108 if ((l - u) < u * precision) {
118 for (; convergenceCheckState < xy.first.size(); getNextConvergenceCheckState()) {
119 ValueType
const& l = RoundingTowardsInf ? -xy.first[convergenceCheckState] : xy.first[convergenceCheckState];
120 if (xy.second[convergenceCheckState] - l > precision) {
128template<
typename ValueType,
bool TrivialRowGrouping>
129template<OptimizationDirection Dir,
typename OffsetType,
bool Smooth,
bool RoundingTowardsInf>
131 OffsetType
const& offsets, uint64_t& numIterations,
bool relative,
132 ValueType
const& precision,
134 std::optional<storm::storage::BitVector>
const& relevantValues,
135 ValueType
const& gamma)
const {
138 uint64_t convergenceCheckState = 0;
139 std::function<void()> getNextConvergenceCheckState;
140 if (relevantValues) {
141 convergenceCheckState = relevantValues->getNextSetIndex(0);
142 getNextConvergenceCheckState = [&convergenceCheckState, &relevantValues]() {
143 convergenceCheckState = relevantValues->getNextSetIndex(++convergenceCheckState);
146 getNextConvergenceCheckState = [&convergenceCheckState]() { ++convergenceCheckState; };
150 viOperator->applyInPlace(xy, offsets, backend);
153 }
else if (iterationCallback) {
160template<
typename ValueType,
bool TrivialRowGrouping>
162 std::pair<std::vector<ValueType>, std::vector<ValueType>>
const& offsets,
163 uint64_t& numIterations,
bool relative, ValueType
const& precision,
164 std::optional<storm::OptimizationDirection>
const& dir,
166 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
167 if (!dir.has_value() ||
maximize(*dir)) {
174template<
typename ValueType,
bool TrivialRowGrouping>
176 std::pair<std::vector<ValueType>, std::vector<ValueType>>
const& offsets,
177 uint64_t& numIterations,
bool relative, ValueType
const& precision,
178 ValueType
const& gamma, [[maybe_unused]] ValueType
const& delta,
179 std::optional<storm::OptimizationDirection>
const& dir,
181 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
183 if (!dir.has_value() ||
maximize(*dir)) {
191 if (!dir.has_value() ||
maximize(*dir)) {
193 relevantValues, gamma);
196 relevantValues, gamma);
201template<
typename ValueType,
bool TrivialRowGrouping>
203 std::pair<std::vector<ValueType>, std::vector<ValueType>>
const& offsets,
204 uint64_t& numIterations,
bool relative, ValueType
const& precision,
205 ValueType
const& gamma, [[maybe_unused]] ValueType
const& delta,
206 std::optional<storm::OptimizationDirection>
const& dir,
208 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
209 if (!dir.has_value() ||
maximize(*dir)) {
218template<
typename ValueType,
bool TrivialRowGrouping>
220 std::vector<ValueType>& operand, std::vector<ValueType>
const& offsets, uint64_t& numIterations,
bool relative, ValueType
const& precision,
221 std::function<
void(std::vector<ValueType>&)>
const& prepareLowerBounds, std::function<
void(std::vector<ValueType>&)>
const& prepareUpperBounds,
225 std::pair<std::vector<ValueType>, std::vector<ValueType>> xy;
226 auto& auxVector = viOperator->allocateAuxiliaryVector(operand.size());
227 xy.first.swap(operand);
228 xy.second.swap(auxVector);
229 prepareLowerBounds(xy.first);
230 prepareUpperBounds(xy.second);
231 auto doublePrec = precision + precision;
232 if constexpr (std::is_same_v<ValueType, double>) {
233 doublePrec -= precision * 1e-6;
236 if (!dir.has_value() ||
maximize(*dir)) {
241 if (solutionBounds.has_value()) {
244 solutionBounds->lower = xy.first;
245 solutionBounds->upper = xy.second;
250 xy.first, xy.second, xy.first, [&two](ValueType
const& a, ValueType
const& b) -> ValueType { return (a + b) / two; });
252 xy.first.swap(operand);
253 xy.second.swap(auxVector);
254 viOperator->freeAuxiliaryVector();
258template<
typename ValueType,
bool TrivialRowGrouping>
260 ValueType
const& precision,
261 std::function<
void(std::vector<ValueType>&)>
const& prepareLowerBounds,
262 std::function<
void(std::vector<ValueType>&)>
const& prepareUpperBounds,
263 std::optional<storm::OptimizationDirection>
const& dir,
265 std::optional<storm::storage::BitVector>
const& relevantValues)
const {
266 uint64_t numIterations = 0;
267 return II(operand, offsets, numIterations, relative, precision, prepareLowerBounds, prepareUpperBounds, dir, iterationCallback, relevantValues);
Helper class that optionally holds a reference to an object of type T.
void endOfIteration() const
void firstRow(std::pair< ValueType, ValueType > &&value, uint64_t rowGroup, uint64_t row)
void nextRow(std::pair< ValueType, ValueType > &&value, uint64_t rowGroup, uint64_t row)
IIBackend(ValueType const &gamma)
void applyUpdate(ValueType &xCurr, ValueType &yCurr, uint64_t rowGroup)
bool constexpr abort() const
bool constexpr converged() const
Implements interval iteration.
SolverStatus II(std::pair< std::vector< ValueType >, std::vector< ValueType > > &xy, OffsetType const &offsets, uint64_t &numIterations, bool relative, ValueType const &precision, std::function< SolverStatus(IIData< ValueType > const &)> const &iterationCallback={}, std::optional< storm::storage::BitVector > const &relevantValues={}, ValueType const &gamma=storm::utility::zero< ValueType >()) const
SolverStatus roundII(std::pair< std::vector< ValueType >, std::vector< ValueType > > &xy, std::pair< std::vector< ValueType >, std::vector< ValueType > > const &offsets, uint64_t &numIterations, bool relative, ValueType const &precision, ValueType const &gamma, ValueType const &delta, std::optional< storm::OptimizationDirection > const &dir={}, std::function< SolverStatus(IIData< ValueType > const &)> const &iterationCallback={}, std::optional< storm::storage::BitVector > const &relevantValues={}) const
Variant of interval iteration for floating point numbers with directed rounding.
SolverStatus smoothII(std::pair< std::vector< ValueType >, std::vector< ValueType > > &xy, std::pair< std::vector< ValueType >, std::vector< ValueType > > const &offsets, uint64_t &numIterations, bool relative, ValueType const &precision, ValueType const &gamma, ValueType const &delta, std::optional< storm::OptimizationDirection > const &dir={}, std::function< SolverStatus(IIData< ValueType > const &)> const &iterationCallback={}, std::optional< storm::storage::BitVector > const &relevantValues={}) const
Smooth variant of interval iteration: Instead of taking over the bounds computed by the Bellman opera...
IntervalIterationHelper(std::shared_ptr< ValueIterationOperator< ValueType, TrivialRowGrouping > > viOperator)
This class represents the Value Iteration Operator (also known as Bellman operator).
Stores and manages an extremal (maximal or minimal) value.
#define STORM_LOG_ASSERT(cond, message)
bool checkConvergence(std::pair< std::vector< ValueType >, std::vector< ValueType > > const &xy, uint64_t &convergenceCheckState, std::function< void()> const &getNextConvergenceCheckState, bool relative, ValueType const &precision)
static ValueType diff(ValueType const &oldValue, ValueType const &newValue)
bool constexpr maximize(OptimizationDirection d)
OptimizationDirection constexpr invert(OptimizationDirection d)
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...
bool isZero(ValueType const &a)
TargetType convertNumber(SourceType const &number)
The contract of a DD backend.
Sound lower and upper bounds on a solution vector.