13template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
17 : exactOperator(exactViOperator), impreciseOperator(impreciseViOperator) {
21template<
typename ValueType,
typename ExactValueType, storm::OptimizationDirection Dir>
28 void firstRow(ExactValueType&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
29 best = std::move(value);
32 void nextRow(ExactValueType&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
36 void applyUpdate(ExactValueType& currValue, [[maybe_unused]] uint64_t rowGroup) {
37 if (currValue != *best) {
59template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
60template<
typename ValueType, storm::OptimizationDirection Dir>
61RSResult RationalSearchHelper<TargetValueType, ExactValueType, ImpreciseValueType, TrivialRowGrouping>::sharpen(uint64_t precision,
62 std::vector<ValueType>
const& operand,
63 std::vector<ExactValueType>
const& exactOffsets,
64 std::vector<TargetValueType>& target)
const {
65 RSBackend<ValueType, ExactValueType, Dir> backend;
66 auto& sharpOperand = exactOperator->allocateAuxiliaryVector(operand.size());
68 for (uint64_t p = 0; p <= precision; ++p) {
70 if (std::is_same_v<ExactValueType, TargetValueType> && std::is_same_v<ValueType, ImpreciseValueType> &&
71 p > std::numeric_limits<ImpreciseValueType>::max_digits10) {
72 exactOperator->freeAuxiliaryVector();
77 if (exactOperator->applyInPlace(sharpOperand, exactOffsets, backend)) {
79 if constexpr (std::is_same_v<ExactValueType, TargetValueType>) {
80 target.swap(sharpOperand);
82 target.resize(sharpOperand.size());
85 exactOperator->freeAuxiliaryVector();
89 exactOperator->freeAuxiliaryVector();
93template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
94template<
typename ValueType>
95std::shared_ptr<ValueIterationOperator<ValueType, TrivialRowGrouping>>
const&
97 if constexpr (std::is_same_v<ValueType, ExactValueType>) {
100 return impreciseOperator;
104template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
105template<
typename ValueType, storm::OptimizationDirection Dir>
107 std::vector<ValueType>& operand, std::vector<ValueType>
const& offsets, uint64_t& numIterations, ExactValueType precision,
108 std::vector<ExactValueType>
const& exactOffsets, std::vector<TargetValueType>& target,
114 auto viStatus = viHelper.VI(operand, offsets, numIterations,
false, storm::utility::convertNumber<ValueType>(precision), Dir, iterationCallback);
117 auto p = storm::utility::convertNumber<uint64_t>(
118 storm::utility::ceil(storm::utility::log10<ExactValueType>(storm::utility::one<ExactValueType>() / precision)));
121 result = sharpen<ValueType, Dir>(p, operand, exactOffsets, target);
131 precision /= storm::utility::convertNumber<ExactValueType>(
static_cast<uint64_t
>(10));
139 return std::pair(result, status);
142template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
143template<storm::OptimizationDirection Dir>
145 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, uint64_t& numIterations, TargetValueType
const& precision,
147 if constexpr (std::is_same_v<TargetValueType, ExactValueType>) {
150 auto& impreciseOperand = impreciseOperator->allocateAuxiliaryVector(operand.size());
152 auto impreciseOffsets = storm::utility::vector::convertNumericVector<ImpreciseValueType>(offsets);
153 auto [result, status] = RS<ImpreciseValueType, Dir>(impreciseOperand, impreciseOffsets, numIterations, precision, offsets, operand, iterationCallback);
157 STORM_LOG_WARN(
"Precision of value type was exceeded, trying to recover by switching to rational arithmetic.");
159 return RS<TargetValueType, Dir>(operand, offsets, numIterations, precision, offsets, operand, iterationCallback).second;
162 auto exactOffsets = storm::utility::vector::convertNumericVector<ExactValueType>(offsets);
163 return RS<TargetValueType, Dir>(operand, offsets, numIterations, storm::utility::convertNumber<ExactValueType>(precision), exactOffsets, operand,
169template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
171 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, uint64_t& numIterations, TargetValueType
const& precision,
172 std::optional<storm::OptimizationDirection>
const& dir, std::function<
SolverStatus(
SolverStatus const&)>
const& iterationCallback)
const {
173 STORM_LOG_ASSERT(TrivialRowGrouping || dir.has_value(),
"no optimization direction given!");
174 if (!dir.has_value() ||
maximize(*dir)) {
175 return RS<storm::OptimizationDirection::Maximize>(operand, offsets, numIterations, precision, iterationCallback);
177 return RS<storm::OptimizationDirection::Minimize>(operand, offsets, numIterations, precision, iterationCallback);
181template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
183 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, TargetValueType
const& precision,
184 std::optional<storm::OptimizationDirection>
const& dir, std::function<
SolverStatus(
SolverStatus const&)>
const& iterationCallback)
const {
185 uint64_t numIterations = 0;
186 return RS(operand, offsets, numIterations, precision, dir, iterationCallback);
void endOfIteration() const
bool constexpr abort() const
void firstRow(ExactValueType &&value, uint64_t rowGroup, uint64_t row)
void nextRow(ExactValueType &&value, uint64_t rowGroup, uint64_t row)
void applyUpdate(ExactValueType &currValue, uint64_t rowGroup)
Implements rational search.
SolverStatus RS(std::vector< TargetValueType > &operand, std::vector< TargetValueType > const &offsets, uint64_t &numIterations, TargetValueType const &precision, std::function< SolverStatus(SolverStatus const &)> const &iterationCallback={}) const
RationalSearchHelper(std::shared_ptr< ValueIterationOperator< ExactValueType, TrivialRowGrouping > > exactViOperator, std::shared_ptr< ValueIterationOperator< ImpreciseValueType, TrivialRowGrouping > > impreciseViOperator)
This class represents the Value Iteration Operator (also known as Bellman operator).
Stores and manages an extremal (maximal or minimal) value.
#define STORM_LOG_WARN(message)
#define STORM_LOG_ASSERT(cond, message)
bool constexpr maximize(OptimizationDirection d)
RationalType sharpen(uint64_t precision, ImpreciseType const &value)
std::vector< TargetType > convertNumericVector(std::vector< SourceType > const &oldVector)
Converts the given vector to the given ValueType Assumes that both, TargetType and SourceType are num...
ValueType ceil(ValueType const &number)