11template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
15 : exactOperator(exactViOperator), impreciseOperator(impreciseViOperator) {
19template<
typename ValueType,
typename ExactValueType, storm::OptimizationDirection Dir>
26 void firstRow(ExactValueType&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
27 best = std::move(value);
30 void nextRow(ExactValueType&& value, [[maybe_unused]] uint64_t rowGroup, [[maybe_unused]] uint64_t row) {
34 void applyUpdate(ExactValueType& currValue, [[maybe_unused]] uint64_t rowGroup) {
35 if (currValue != *best) {
57template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
58template<
typename ValueType, storm::OptimizationDirection Dir>
59RSResult RationalSearchHelper<TargetValueType, ExactValueType, ImpreciseValueType, TrivialRowGrouping>::sharpen(uint64_t precision,
60 std::vector<ValueType>
const& operand,
61 std::vector<ExactValueType>
const& exactOffsets,
62 std::vector<TargetValueType>& target)
const {
63 RSBackend<ValueType, ExactValueType, Dir> backend;
64 auto& sharpOperand = exactOperator->allocateAuxiliaryVector(operand.size());
66 for (uint64_t p = 0; p <= precision; ++p) {
68 if (std::is_same_v<ExactValueType, TargetValueType> && std::is_same_v<ValueType, ImpreciseValueType> &&
69 p > std::numeric_limits<ImpreciseValueType>::max_digits10) {
70 exactOperator->freeAuxiliaryVector();
75 if (exactOperator->applyInPlace(sharpOperand, exactOffsets, backend)) {
77 if constexpr (std::is_same_v<ExactValueType, TargetValueType>) {
78 target.swap(sharpOperand);
80 target.resize(sharpOperand.size());
83 exactOperator->freeAuxiliaryVector();
87 exactOperator->freeAuxiliaryVector();
91template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
92template<
typename ValueType>
93std::shared_ptr<ValueIterationOperator<ValueType, TrivialRowGrouping>>
const&
95 if constexpr (std::is_same_v<ValueType, ExactValueType>) {
98 return impreciseOperator;
102template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
103template<
typename ValueType, storm::OptimizationDirection Dir>
105 std::vector<ValueType>& operand, std::vector<ValueType>
const& offsets, uint64_t& numIterations, ExactValueType precision,
106 std::vector<ExactValueType>
const& exactOffsets, std::vector<TargetValueType>& target,
112 auto viStatus = viHelper.VI(operand, offsets, numIterations,
false, storm::utility::convertNumber<ValueType>(precision), Dir, iterationCallback);
115 auto p = storm::utility::convertNumber<uint64_t>(
116 storm::utility::ceil(storm::utility::log10<ExactValueType>(storm::utility::one<ExactValueType>() / precision)));
119 result = sharpen<ValueType, Dir>(p, operand, exactOffsets, target);
129 precision /= storm::utility::convertNumber<ExactValueType>(
static_cast<uint64_t
>(10));
137 return std::pair(result, status);
140template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
141template<storm::OptimizationDirection Dir>
143 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, uint64_t& numIterations, TargetValueType
const& precision,
145 if constexpr (std::is_same_v<TargetValueType, ExactValueType>) {
148 auto& impreciseOperand = impreciseOperator->allocateAuxiliaryVector(operand.size());
150 auto impreciseOffsets = storm::utility::vector::convertNumericVector<ImpreciseValueType>(offsets);
151 auto [result, status] = RS<ImpreciseValueType, Dir>(impreciseOperand, impreciseOffsets, numIterations, precision, offsets, operand, iterationCallback);
155 STORM_LOG_WARN(
"Precision of value type was exceeded, trying to recover by switching to rational arithmetic.");
157 return RS<TargetValueType, Dir>(operand, offsets, numIterations, precision, offsets, operand, iterationCallback).second;
160 auto exactOffsets = storm::utility::vector::convertNumericVector<ExactValueType>(offsets);
161 return RS<TargetValueType, Dir>(operand, offsets, numIterations, storm::utility::convertNumber<ExactValueType>(precision), exactOffsets, operand,
167template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
169 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, uint64_t& numIterations, TargetValueType
const& precision,
170 std::optional<storm::OptimizationDirection>
const& dir, std::function<
SolverStatus(
SolverStatus const&)>
const& iterationCallback)
const {
171 STORM_LOG_ASSERT(TrivialRowGrouping || dir.has_value(),
"no optimization direction given!");
172 if (!dir.has_value() ||
maximize(*dir)) {
173 return RS<storm::OptimizationDirection::Maximize>(operand, offsets, numIterations, precision, iterationCallback);
175 return RS<storm::OptimizationDirection::Minimize>(operand, offsets, numIterations, precision, iterationCallback);
179template<
typename TargetValueType,
typename ExactValueType,
typename ImpreciseValueType,
bool TrivialRowGrouping>
181 std::vector<TargetValueType>& operand, std::vector<TargetValueType>
const& offsets, TargetValueType
const& precision,
182 std::optional<storm::OptimizationDirection>
const& dir, std::function<
SolverStatus(
SolverStatus const&)>
const& iterationCallback)
const {
183 uint64_t numIterations = 0;
184 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)