12template<
typename ValueType,
bool TrivialRowGrouping>
14 : localA(nullptr), A(&A), discountFactor(discountFactor) {
17 discountedA = discountedMatrix;
20template<
typename ValueType,
bool TrivialRowGrouping>
23 : localA(nullptr), A(&A), discountFactor(discountFactor), trackScheduler(trackScheduler) {
26 discountedA = discountedMatrix;
29template<
typename ValueType,
bool TrivialRowGrouping>
30void DiscountingHelper<ValueType, TrivialRowGrouping>::setUpViOperator()
const {
32 viOperator = std::make_shared<solver::helper::ValueIterationOperator<ValueType, TrivialRowGrouping>>();
33 viOperator->setMatrixBackwards(this->discountedA);
37template<
typename ValueType,
bool TrivialRowGrouping>
38void DiscountingHelper<ValueType, TrivialRowGrouping>::showProgressIterative(uint64_t iteration)
const {
39 progressMeasurement->updateProgress(iteration);
42template<
typename ValueType,
bool TrivialRowGrouping>
44 std::optional<OptimizationDirection> dir, std::vector<ValueType>& x,
45 std::vector<ValueType>
const& b)
const {
49 uint64_t numIterations{0};
52 for (
auto const& entry : b) {
58 progressMeasurement->startNewMeasurement(0);
65 this->extractScheduler(x, b, dir.value(), UncertaintyResolutionMode::Robust);
70template<
typename ValueType,
bool TrivialRowGrouping>
72 STORM_LOG_THROW(
hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler, because none was generated.");
74 uint_fast64_t state = 0;
75 for (
auto const& schedulerChoice : schedulerChoices.get()) {
82template<
typename ValueType,
bool TrivialRowGrouping>
84 return static_cast<bool>(schedulerChoices);
88void DiscountingHelper<double, true>::extractScheduler(std::vector<double>& x, std::vector<double>
const& b,
OptimizationDirection const& dir,
92void DiscountingHelper<storm::RationalNumber, true>::extractScheduler(std::vector<storm::RationalNumber>& x, std::vector<storm::RationalNumber>
const& b,
96template<
typename ValueType,
bool TrivialRowGrouping>
97void DiscountingHelper<ValueType, TrivialRowGrouping>::extractScheduler(std::vector<ValueType>& x, std::vector<ValueType>
const& b,
101 if (!this->schedulerChoices) {
102 this->schedulerChoices = std::vector<uint64_t>(x.size(), 0);
104 this->schedulerChoices->resize(x.size(), 0);
107 STORM_LOG_WARN_COND(viOperator,
"Expected VI operator to be initialized for scheduler extraction. Initializing now, but this is inefficient.");
111 storm::solver::helper::SchedulerTrackingHelper<ValueType> schedHelper(viOperator);
112 schedHelper.computeScheduler(x, b, dir, *this->schedulerChoices, uncertaintyResolutionMode,
nullptr);
115template<
typename ValueType,
bool TrivialRowGrouping>
117 this->trackScheduler = trackScheduler;
118 if (!this->trackScheduler) {
119 schedulerChoices = boost::none;
123template<
typename ValueType,
bool TrivialRowGrouping>
125 return this->trackScheduler;
SolverEnvironment & solver()
storm::solver::MultiplicationStyle const & getMultiplicationStyle() const
storm::RationalNumber const & getPrecision() const
bool const & getRelativeTerminationCriterion() const
MinMaxSolverEnvironment & minMax()
uint64_t getShowProgressDelay() const
bool hasScheduler() const
Retrieves whether the solver generated a scheduler.
storm::storage::Scheduler< ValueType > computeScheduler() const
Retrieves the generated scheduler.
bool solveWithDiscountedValueIteration(Environment const &env, std::optional< OptimizationDirection > dir, std::vector< ValueType > &x, std::vector< ValueType > const &b) const
bool isTrackSchedulerSet() const
DiscountingHelper(storm::storage::SparseMatrix< ValueType > const &A, ValueType discountFactor)
void setTrackScheduler(bool trackScheduler)
SolverStatus DiscountedVI(std::vector< ValueType > &operand, std::vector< ValueType > const &offsets, uint64_t &numIterations, ValueType const &precision, ValueType const &discountFactor, ValueType const &maximalAbsoluteReward, std::function< SolverStatus(SolverStatus const &)> const &iterationCallback={}, MultiplicationStyle mult=MultiplicationStyle::GaussSeidel) const
This class defines which action is chosen in a particular state of a non-deterministic model.
void setChoice(SchedulerChoice< ValueType > const &choice, uint_fast64_t modelState, uint_fast64_t memoryState=0)
Sets the choice defined by the scheduler for the given state.
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getRowCount() const
Returns the number of rows of the matrix.
void scaleRowsInPlace(std::vector< value_type > const &factors)
Scales each row of the matrix, i.e., multiplies each element in row i with factors[i].
A class that provides convenience operations to display run times.
#define STORM_LOG_WARN_COND(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
ValueType abs(ValueType const &number)
TargetType convertNumber(SourceType const &number)
solver::UncertaintyResolutionMode UncertaintyResolutionMode
solver::OptimizationDirection OptimizationDirection