Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Ctmc.cpp
Go to the documentation of this file.
2
8
9namespace storm {
10namespace models {
11namespace sparse {
12
13template<typename ValueType, typename RewardModelType>
15 std::unordered_map<std::string, RewardModelType> const& rewardModels)
16 : Ctmc<ValueType, RewardModelType>(storm::storage::sparse::ModelComponents<ValueType, RewardModelType>(rateMatrix, stateLabeling, rewardModels, true)) {
17 // Intentionally left empty
18}
19
20template<typename ValueType, typename RewardModelType>
22 std::unordered_map<std::string, RewardModelType>&& rewardModels)
24 storm::storage::sparse::ModelComponents<ValueType, RewardModelType>(std::move(rateMatrix), std::move(stateLabeling), std::move(rewardModels), true)) {
25 // Intentionally left empty
26}
27
28template<typename ValueType, typename RewardModelType>
31 if (components.exitRates) {
32 exitRates = components.exitRates.get();
33 } else {
34 STORM_LOG_ASSERT(components.rateTransitions, "No rate information given for CTMC.");
35 exitRates = createExitRateVector(this->getTransitionMatrix());
36 }
37
38 if (!components.rateTransitions) {
39 this->getTransitionMatrix().scaleRowsInPlace(exitRates);
40 }
41}
42
43template<typename ValueType, typename RewardModelType>
46 // NOLINTBEGIN(bugprone-use-after-move) The base constructor only consumes the base-relevant fields of components.
47 if (components.exitRates) {
48 exitRates = std::move(components.exitRates.get());
49 } else {
50 STORM_LOG_ASSERT(components.rateTransitions, "No rate information given for CTMC.");
51 exitRates = createExitRateVector(this->getTransitionMatrix());
52 }
53
54 if (!components.rateTransitions) {
55 this->getTransitionMatrix().scaleRowsInPlace(exitRates);
56 }
57 // NOLINTEND(bugprone-use-after-move)
58}
59
60template<typename ValueType, typename RewardModelType>
61std::vector<ValueType> const& Ctmc<ValueType, RewardModelType>::getExitRateVector() const {
62 return exitRates;
63}
64
65template<typename ValueType, typename RewardModelType>
67 return exitRates;
68}
69
70template<typename ValueType, typename RewardModelType>
71std::vector<ValueType> Ctmc<ValueType, RewardModelType>::createExitRateVector(storm::storage::SparseMatrix<ValueType> const& rateMatrix) {
72 std::vector<ValueType> exitRates(rateMatrix.getRowCount());
73 for (uint_fast64_t row = 0; row < rateMatrix.getRowCount(); ++row) {
74 exitRates[row] = rateMatrix.getRowSum(row);
75 }
76 return exitRates;
77}
78
79template<typename ValueType, typename RewardModelType>
81 for (auto& rewardModel : this->getRewardModels()) {
82 rewardModel.second.reduceToStateBasedRewards(this->getTransitionMatrix(), true, &exitRates);
83 }
84}
85
86template<typename ValueType, typename RewardModelType>
88 // Turn the rates into probabilities by scaling each row with the exit rate of the state.
90 for (uint_fast64_t row = 0; row < result.getRowCount(); ++row) {
91 for (auto& entry : result.getRow(row)) {
92 entry.setValue(entry.getValue() / exitRates[row]);
93 }
94 }
95 return result;
96}
97
98template class Ctmc<double>;
99template class Ctmc<storm::RationalNumber>;
102template class Ctmc<storm::RationalFunction>;
103template class Ctmc<storm::Interval>;
104template class Ctmc<storm::RationalInterval>;
105} // namespace sparse
106} // namespace models
107} // namespace storm
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
storm::storage::SparseMatrix< ValueType > computeProbabilityMatrix() const
Definition Ctmc.cpp:87
virtual void reduceToStateBasedRewards() override
Converts the transition rewards of all reward models to state-based rewards.
Definition Ctmc.cpp:80
Ctmc(storm::storage::SparseMatrix< ValueType > const &rateMatrix, storm::models::sparse::StateLabeling const &stateLabeling, std::unordered_map< std::string, RewardModelType > const &rewardModels=std::unordered_map< std::string, RewardModelType >())
Constructs a model from the given data.
Definition Ctmc.cpp:14
std::vector< ValueType > const & getExitRateVector() const
Retrieves the vector of exit rates of the model.
Definition Ctmc.cpp:61
DeterministicModel(ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > const &components)
Constructs a model from the given data.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:198
std::unordered_map< std::string, RewardModelType > const & getRewardModels() const
Retrieves the reward models.
Definition Model.cpp:690
RewardModelType & rewardModel(std::string const &rewardModelName)
Definition Model.cpp:213
CRewardModelType RewardModelType
Definition Model.h:33
This class manages the labeling of the state space with a number of (atomic) labels.
A class that holds a possibly non-square matrix in the compressed row storage format.
const_rows getRow(index_type row) const
Returns an object representing the given row.
value_type getRowSum(index_type row) const
Computes the sum of the entries in a given row.
index_type getRowCount() const
Returns the number of rows of the matrix.
boost::optional< std::vector< ValueType > > exitRates