Storm 1.11.1.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>
45 : DeterministicModel<ValueType, RewardModelType>(storm::models::ModelType::Ctmc, std::move(components)) {
46 if (components.exitRates) {
47 exitRates = std::move(components.exitRates.get());
48 } else {
49 STORM_LOG_ASSERT(components.rateTransitions, "No rate information given for CTMC.");
50 exitRates = createExitRateVector(this->getTransitionMatrix());
51 }
52
53 if (!components.rateTransitions) {
54 this->getTransitionMatrix().scaleRowsInPlace(exitRates);
55 }
56}
57
58template<typename ValueType, typename RewardModelType>
59std::vector<ValueType> const& Ctmc<ValueType, RewardModelType>::getExitRateVector() const {
60 return exitRates;
61}
62
63template<typename ValueType, typename RewardModelType>
65 return exitRates;
66}
67
68template<typename ValueType, typename RewardModelType>
70 std::vector<ValueType> exitRates(rateMatrix.getRowCount());
71 for (uint_fast64_t row = 0; row < rateMatrix.getRowCount(); ++row) {
72 exitRates[row] = rateMatrix.getRowSum(row);
73 }
74 return exitRates;
75}
76
77template<typename ValueType, typename RewardModelType>
79 for (auto& rewardModel : this->getRewardModels()) {
80 rewardModel.second.reduceToStateBasedRewards(this->getTransitionMatrix(), true, &exitRates);
81 }
82}
83
84template<typename ValueType, typename RewardModelType>
86 // Turn the rates into probabilities by scaling each row with the exit rate of the state.
87 storm::storage::SparseMatrix<ValueType> result(this->getTransitionMatrix());
88 for (uint_fast64_t row = 0; row < result.getRowCount(); ++row) {
89 for (auto& entry : result.getRow(row)) {
90 entry.setValue(entry.getValue() / exitRates[row]);
91 }
92 }
93 return result;
94}
95
96template class Ctmc<double>;
97template class Ctmc<storm::RationalNumber>;
100template class Ctmc<storm::Interval>;
101} // namespace sparse
102} // namespace models
103} // namespace storm
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
storm::storage::SparseMatrix< ValueType > computeProbabilityMatrix() const
Definition Ctmc.cpp:85
virtual void reduceToStateBasedRewards() override
Converts the transition rewards of all reward models to state-based rewards.
Definition Ctmc.cpp:78
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:59
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:199
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