Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Ctmc.cpp
Go to the documentation of this file.
2
6
7namespace storm {
8namespace models {
9namespace sparse {
10
11template<typename ValueType, typename RewardModelType>
13 std::unordered_map<std::string, RewardModelType> const& rewardModels)
14 : Ctmc<ValueType, RewardModelType>(storm::storage::sparse::ModelComponents<ValueType, RewardModelType>(rateMatrix, stateLabeling, rewardModels, true)) {
15 // Intentionally left empty
16}
17
18template<typename ValueType, typename RewardModelType>
20 std::unordered_map<std::string, RewardModelType>&& rewardModels)
22 storm::storage::sparse::ModelComponents<ValueType, RewardModelType>(std::move(rateMatrix), std::move(stateLabeling), std::move(rewardModels), true)) {
23 // Intentionally left empty
24}
25
26template<typename ValueType, typename RewardModelType>
29 if (components.exitRates) {
30 exitRates = components.exitRates.get();
31 } else {
32 STORM_LOG_ASSERT(components.rateTransitions, "No rate information given for CTMC.");
33 exitRates = createExitRateVector(this->getTransitionMatrix());
34 }
35
36 if (!components.rateTransitions) {
37 this->getTransitionMatrix().scaleRowsInPlace(exitRates);
38 }
39}
40
41template<typename ValueType, typename RewardModelType>
43 : DeterministicModel<ValueType, RewardModelType>(storm::models::ModelType::Ctmc, std::move(components)) {
44 if (components.exitRates) {
45 exitRates = std::move(components.exitRates.get());
46 } else {
47 STORM_LOG_ASSERT(components.rateTransitions, "No rate information given for CTMC.");
48 exitRates = createExitRateVector(this->getTransitionMatrix());
49 }
50
51 if (!components.rateTransitions) {
52 this->getTransitionMatrix().scaleRowsInPlace(exitRates);
53 }
54}
55
56template<typename ValueType, typename RewardModelType>
57std::vector<ValueType> const& Ctmc<ValueType, RewardModelType>::getExitRateVector() const {
58 return exitRates;
59}
60
61template<typename ValueType, typename RewardModelType>
63 return exitRates;
64}
65
66template<typename ValueType, typename RewardModelType>
68 std::vector<ValueType> exitRates(rateMatrix.getRowCount());
69 for (uint_fast64_t row = 0; row < rateMatrix.getRowCount(); ++row) {
70 exitRates[row] = rateMatrix.getRowSum(row);
71 }
72 return exitRates;
73}
74
75template<typename ValueType, typename RewardModelType>
77 for (auto& rewardModel : this->getRewardModels()) {
78 rewardModel.second.reduceToStateBasedRewards(this->getTransitionMatrix(), true, &exitRates);
79 }
80}
81
82template<typename ValueType, typename RewardModelType>
84 // Turn the rates into probabilities by scaling each row with the exit rate of the state.
85 storm::storage::SparseMatrix<ValueType> result(this->getTransitionMatrix());
86 for (uint_fast64_t row = 0; row < result.getRowCount(); ++row) {
87 for (auto& entry : result.getRow(row)) {
88 entry.setValue(entry.getValue() / exitRates[row]);
89 }
90 }
91 return result;
92}
93
94template class Ctmc<double>;
95template class Ctmc<storm::RationalNumber>;
98template class Ctmc<storm::Interval>;
99} // namespace sparse
100} // namespace models
101} // namespace storm
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
storm::storage::SparseMatrix< ValueType > computeProbabilityMatrix() const
Definition Ctmc.cpp:83
virtual void reduceToStateBasedRewards() override
Converts the transition rewards of all reward models to state-based rewards.
Definition Ctmc.cpp:76
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:12
std::vector< ValueType > const & getExitRateVector() const
Retrieves the vector of exit rates of the model.
Definition Ctmc.cpp:57
The base class of all sparse deterministic models.
storm::storage::SparseMatrix< ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:191
CRewardModelType RewardModelType
Definition Model.h:35
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.
#define STORM_LOG_ASSERT(cond, message)
Definition macros.h:11
boost::optional< std::vector< ValueType > > exitRates