15namespace modelchecker {
18template<
typename ValueType,
bool Nondeterministic>
20 : _transitionMatrix(transitionMatrix),
21 _markovianStates(nullptr),
23 _backwardTransitions(nullptr),
24 _longRunComponentDecomposition(nullptr) {
28template<
typename ValueType,
bool Nondeterministic>
31 std::vector<ValueType>
const& exitRates)
32 : _transitionMatrix(transitionMatrix),
33 _markovianStates(&markovianStates),
34 _exitRates(&exitRates),
35 _backwardTransitions(nullptr),
36 _longRunComponentDecomposition(nullptr) {
40template<
typename ValueType,
bool Nondeterministic>
42 std::vector<ValueType>
const& exitRates)
43 : _transitionMatrix(transitionMatrix),
44 _markovianStates(nullptr),
45 _exitRates(&exitRates),
46 _backwardTransitions(nullptr),
47 _longRunComponentDecomposition(nullptr) {
51template<
typename ValueType,
bool Nondeterministic>
53 STORM_LOG_WARN_COND(_backwardTransitions ==
nullptr,
"Backwards transitions were provided but they were already computed or provided before.");
54 _backwardTransitions = &backwardTransitions;
57template<
typename ValueType,
bool Nondeterministic>
61 "Long Run Component Decomposition was provided but it was already computed or provided before.");
62 _longRunComponentDecomposition = &decomposition;
65template<
typename ValueType,
bool Nondeterministic>
68 return computeLongRunAverageValues(
69 env, [&psiStates](uint64_t stateIndex) {
return psiStates.
get(stateIndex) ? storm::utility::one<ValueType>() : storm::utility::zero<ValueType>(); },
70 [](uint64_t) {
return storm::utility::zero<ValueType>(); });
73template<
typename ValueType,
bool Nondeterministic>
78 stateRewardsGetter = [&rewardModel](uint64_t stateIndex) {
return rewardModel.
getStateReward(stateIndex); };
80 stateRewardsGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
82 ValueGetter actionRewardsGetter;
85 actionRewardsGetter = [&](uint64_t globalChoiceIndex) {
89 actionRewardsGetter = [&](uint64_t globalChoiceIndex) {
return rewardModel.
getStateActionReward(globalChoiceIndex); };
92 actionRewardsGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
95 return computeLongRunAverageValues(env, stateRewardsGetter, actionRewardsGetter);
98template<
typename ValueType,
bool Nondeterministic>
100 std::vector<ValueType>
const* stateValues,
101 std::vector<ValueType>
const* actionValues) {
104 stateValuesGetter = [&stateValues](uint64_t stateIndex) {
return (*stateValues)[stateIndex]; };
106 stateValuesGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
110 actionValuesGetter = [&actionValues](uint64_t globalChoiceIndex) {
return (*actionValues)[globalChoiceIndex]; };
112 actionValuesGetter = [](uint64_t) {
return storm::utility::zero<ValueType>(); };
115 return computeLongRunAverageValues(env, stateValuesGetter, actionValuesGetter);
118template<
typename ValueType,
bool Nondeterministic>
127 auto underlyingSolverEnvironment = env;
130 storm::RationalNumber newPrecision = env.
solver().
lra().
getPrecision() / storm::utility::convertNumber<storm::RationalNumber>(2);
131 underlyingSolverEnvironment.solver().minMax().setPrecision(newPrecision);
134 underlyingSolverEnvironment.solver().lra().setPrecision(newPrecision);
138 if (Nondeterministic && this->isProduceSchedulerSet()) {
139 if (!_producedOptimalChoices.is_initialized()) {
140 _producedOptimalChoices.emplace();
142 _producedOptimalChoices->resize(_transitionMatrix.getRowGroupCount());
144 STORM_LOG_ASSERT(Nondeterministic || !this->isProduceSchedulerSet(),
"Scheduler production enabled for deterministic model.");
147 createDecomposition();
151 std::string
const componentString = (Nondeterministic ? std::string(
"Maximal end") : std::string(
"Bottom strongly connected")) +
152 (_longRunComponentDecomposition->size() == 1 ? std::string(
" component") : std::string(
" components"));
154 progress.
setMaxCount(_longRunComponentDecomposition->size());
156 STORM_LOG_INFO(
"Computing long run average values for " << _longRunComponentDecomposition->size() <<
" " << componentString <<
" individually...");
157 std::vector<ValueType> componentLraValues;
158 componentLraValues.reserve(_longRunComponentDecomposition->size());
159 for (
auto const& c : *_longRunComponentDecomposition) {
160 componentLraValues.push_back(computeLraForComponent(underlyingSolverEnvironment, stateRewardsGetter, actionRewardsGetter, c));
166 return buildAndSolveSsp(underlyingSolverEnvironment, componentLraValues);
169template<
typename ValueType,
bool Nondeterministic>
171 STORM_LOG_ASSERT((_markovianStates ==
nullptr) || (_exitRates !=
nullptr),
"Inconsistent information given: Have Markovian states but no exit rates.");
172 return _exitRates !=
nullptr;
175template<
typename ValueType,
bool Nondeterministic>
177 if (this->_backwardTransitions ==
nullptr) {
178 this->_computedBackwardTransitions =
179 std::make_unique<storm::storage::SparseMatrix<ValueType>>(this->_transitionMatrix.transpose(
true,
false));
180 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 getStateActionAndTransitionReward(uint_fast64_t choiceIndex, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix) const
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.
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(uint64_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)