30namespace modelchecker {
33template<
typename ValueType,
bool Nondeterministic>
35 : _transitionMatrix(transitionMatrix),
36 _markovianStates(nullptr),
38 _backwardTransitions(nullptr),
39 _longRunComponentDecomposition(nullptr) {
43template<
typename ValueType,
bool Nondeterministic>
46 std::vector<ValueType>
const& exitRates)
47 : _transitionMatrix(transitionMatrix),
48 _markovianStates(&markovianStates),
49 _exitRates(&exitRates),
50 _backwardTransitions(nullptr),
51 _longRunComponentDecomposition(nullptr) {
55template<
typename ValueType,
bool Nondeterministic>
57 std::vector<ValueType>
const& exitRates)
58 : _transitionMatrix(transitionMatrix),
59 _markovianStates(nullptr),
60 _exitRates(&exitRates),
61 _backwardTransitions(nullptr),
62 _longRunComponentDecomposition(nullptr) {
66template<
typename ValueType,
bool Nondeterministic>
68 STORM_LOG_WARN_COND(_backwardTransitions ==
nullptr,
"Backwards transitions were provided but they were already computed or provided before.");
69 _backwardTransitions = &backwardTransitions;
72template<
typename ValueType,
bool Nondeterministic>
76 "Long Run Component Decomposition was provided but it was already computed or provided before.");
77 _longRunComponentDecomposition = &decomposition;
80template<
typename ValueType,
bool Nondeterministic>
83 return computeLongRunAverageValues(
84 env, [&psiStates](uint64_t stateIndex) {
return psiStates.
get(stateIndex) ? storm::utility::one<ValueType>() : storm::utility::zero<ValueType>(); },
85 [](uint64_t) {
return storm::utility::zero<ValueType>(); });
88template<
typename ValueType,
bool Nondeterministic>
93 stateRewardsGetter = [&rewardModel](uint64_t stateIndex) {
return rewardModel.
getStateReward(stateIndex); };
95 stateRewardsGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
100 actionRewardsGetter = [&](uint64_t globalChoiceIndex) {
104 actionRewardsGetter = [&](uint64_t globalChoiceIndex) {
return rewardModel.
getStateActionReward(globalChoiceIndex); };
107 actionRewardsGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
110 return computeLongRunAverageValues(env, stateRewardsGetter, actionRewardsGetter);
113template<
typename ValueType,
bool Nondeterministic>
115 std::vector<ValueType>
const* stateValues,
116 std::vector<ValueType>
const* actionValues) {
119 stateValuesGetter = [&stateValues](uint64_t stateIndex) {
return (*stateValues)[stateIndex]; };
121 stateValuesGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
123 ValueGetter actionValuesGetter;
125 actionValuesGetter = [&actionValues](uint64_t globalChoiceIndex) {
return (*actionValues)[globalChoiceIndex]; };
127 actionValuesGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
130 return computeLongRunAverageValues(env, stateValuesGetter, actionValuesGetter);
133template<
typename ValueType,
bool Nondeterministic>
142 auto underlyingSolverEnvironment = env;
145 storm::RationalNumber newPrecision = env.
solver().
lra().
getPrecision() / storm::utility::convertNumber<storm::RationalNumber>(2);
146 underlyingSolverEnvironment.solver().minMax().setPrecision(newPrecision);
149 underlyingSolverEnvironment.solver().lra().setPrecision(newPrecision);
153 if (Nondeterministic && this->isProduceSchedulerSet()) {
154 if (!_producedOptimalChoices.is_initialized()) {
155 _producedOptimalChoices.emplace();
157 _producedOptimalChoices->resize(_transitionMatrix.getRowGroupCount());
159 STORM_LOG_ASSERT(Nondeterministic || !this->isProduceSchedulerSet(),
"Scheduler production enabled for deterministic model.");
162 createDecomposition();
166 std::string
const componentString = (Nondeterministic ? std::string(
"Maximal end") : std::string(
"Bottom strongly connected")) +
167 (_longRunComponentDecomposition->size() == 1 ? std::string(
" component") : std::string(
" components"));
169 progress.
setMaxCount(_longRunComponentDecomposition->size());
171 STORM_LOG_INFO(
"Computing long run average values for " << _longRunComponentDecomposition->size() <<
" " << componentString <<
" individually...");
172 std::vector<ValueType> componentLraValues;
173 componentLraValues.reserve(_longRunComponentDecomposition->size());
174 for (
auto const& c : *_longRunComponentDecomposition) {
175 componentLraValues.push_back(computeLraForComponent(underlyingSolverEnvironment, stateRewardsGetter, actionRewardsGetter, c));
181 return buildAndSolveSsp(underlyingSolverEnvironment, componentLraValues);
184template<
typename ValueType,
bool Nondeterministic>
186 STORM_LOG_ASSERT((_markovianStates ==
nullptr) || (_exitRates !=
nullptr),
"Inconsistent information given: Have Markovian states but no exit rates.");
187 return _exitRates !=
nullptr;
190template<
typename ValueType,
bool Nondeterministic>
192 if (this->_backwardTransitions ==
nullptr) {
193 this->_computedBackwardTransitions =
194 std::make_unique<storm::storage::SparseMatrix<ValueType>>(this->_transitionMatrix.transpose(
true,
false));
195 this->_backwardTransitions = this->_computedBackwardTransitions.get();
SolverEnvironment & solver()
storm::RationalNumber const & getPrecision() const
bool const & getRelativeTerminationCriterion() const
LongRunAverageSolverEnvironment & lra()
bool isForceSoundness() const
Helper class for model checking queries that depend on the long run behavior of the (nondeterministic...
bool isContinuousTime() const
void provideBackwardTransitions(storm::storage::SparseMatrix< ValueType > const &backwardsTransitions)
Provides backward transitions that can be used during the computation.
std::vector< ValueType > computeLongRunAverageRewards(Environment const &env, storm::models::sparse::StandardRewardModel< ValueType > const &rewardModel)
Computes the long run average rewards, i.e., the average reward collected per time unit.
std::function< ValueType(uint64_t)> ValueGetter
Function mapping from indices to values.
void provideLongRunComponentDecomposition(storm::storage::Decomposition< LongRunComponentType > const &decomposition)
Provides the decomposition into long run components (BSCCs/MECs) that can be used during the computat...
SparseInfiniteHorizonHelper(storm::storage::SparseMatrix< ValueType > const &transitionMatrix)
Initializes the helper for a discrete time (i.e.
void createBackwardTransitions()
std::vector< ValueType > computeLongRunAverageProbabilities(Environment const &env, storm::storage::BitVector const &psiStates)
Computes the long run average probabilities, i.e., the fraction of the time we are in a psiState.
std::vector< ValueType > computeLongRunAverageValues(Environment const &env, std::vector< ValueType > const *stateValues=nullptr, std::vector< ValueType > const *actionValues=nullptr)
Computes the long run average value given the provided state and action-based rewards.
bool hasTransitionRewards() const
Retrieves whether the reward model has transition rewards.
ValueType const & getStateReward(uint_fast64_t state) const
ValueType const & getStateActionReward(uint_fast64_t choiceIndex) const
Retrieves the state-action reward for the given choice.
ValueType getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
bool hasStateRewards() const
Retrieves whether the reward model has state rewards.
bool hasStateActionRewards() const
Retrieves whether the reward model has state-action rewards.
A bit vector that is internally represented as a vector of 64-bit values.
bool get(uint_fast64_t index) const
Retrieves the truth value of the bit at the given index and performs a bound check.
This class represents the decomposition of a model into blocks which are of the template type.
A class that holds a possibly non-square matrix in the compressed row storage format.
A class that provides convenience operations to display run times.
bool updateProgress(uint64_t count)
Updates the progress to the current count and prints it if the delay passed.
void setMaxCount(uint64_t maxCount)
Sets the maximal possible count.
void startNewMeasurement(uint64_t startCount)
Starts a new measurement, dropping all progress information collected so far.
#define STORM_LOG_INFO(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_WARN_COND(cond, message)