9namespace modelchecker {
12template<
typename ValueType,
bool TrivialRowGrouping>
14 : localA(nullptr), A(&A), discountFactor(discountFactor) {
18 discountedA = discountedMatrix;
21template<
typename ValueType,
bool TrivialRowGrouping>
24 : localA(nullptr), A(&A), discountFactor(discountFactor), trackScheduler(trackScheduler) {
28 discountedA = discountedMatrix;
31template<
typename ValueType,
bool TrivialRowGrouping>
34 viOperator = std::make_shared<solver::helper::ValueIterationOperator<ValueType, TrivialRowGrouping>>();
35 viOperator->setMatrixBackwards(this->discountedA);
39template<
typename ValueType,
bool TrivialRowGrouping>
40void DiscountingHelper<ValueType, TrivialRowGrouping>::showProgressIterative(uint64_t iteration)
const {
41 progressMeasurement->updateProgress(iteration);
44template<
typename ValueType,
bool TrivialRowGrouping>
46 std::optional<OptimizationDirection> dir, std::vector<ValueType>& x,
47 std::vector<ValueType>
const& b)
const {
51 uint64_t numIterations{0};
53 auto maximalAbsoluteReward = storm::utility::zero<ValueType>();
54 for (
auto const& entry : b) {
59 progressMeasurement->startNewMeasurement(0);
61 storm::utility::convertNumber<ValueType>(env.
solver().
minMax().
getPrecision()), discountFactor, maximalAbsoluteReward,
65 if (this->isTrackSchedulerSet()) {
66 this->extractScheduler(x, b, dir.value(),
true);
71template<
typename ValueType,
bool TrivialRowGrouping>
73 STORM_LOG_THROW(hasScheduler(), storm::exceptions::IllegalFunctionCallException,
"Cannot retrieve scheduler, because none was generated.");
75 uint_fast64_t state = 0;
76 for (
auto const& schedulerChoice : schedulerChoices.get()) {
83template<
typename ValueType,
bool TrivialRowGrouping>
85 return static_cast<bool>(schedulerChoices);
93void 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,
100 if (!this->schedulerChoices) {
101 this->schedulerChoices = std::vector<uint64_t>(x.size(), 0);
103 this->schedulerChoices->resize(x.size(), 0);
106 STORM_LOG_WARN_COND(viOperator,
"Expected VI operator to be initialized for scheduler extraction. Initializing now, but this is inefficient.");
111 schedHelper.computeScheduler(x, b, dir, *this->schedulerChoices, robust,
nullptr);
114template<
typename ValueType,
bool TrivialRowGrouping>
116 this->trackScheduler = trackScheduler;
117 if (!this->trackScheduler) {
118 schedulerChoices = boost::none;
122template<
typename ValueType,
bool TrivialRowGrouping>
124 return this->trackScheduler;
SolverEnvironment & solver()
storm::solver::MultiplicationStyle const & getMultiplicationStyle() const
storm::RationalNumber const & getPrecision() const
bool const & getRelativeTerminationCriterion() const
MinMaxSolverEnvironment & minMax()
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
Helper class to extract optimal scheduler choices from a MinMax equation system solution.
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)