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