Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
transformation.h
Go to the documentation of this file.
1#pragma once
2
7
13
14namespace storm {
15namespace api {
16
20template<typename ValueType>
21std::pair<std::shared_ptr<storm::models::sparse::Model<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>> eliminateNonMarkovianChains(
22 std::shared_ptr<storm::models::sparse::MarkovAutomaton<ValueType>> const& ma, std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas,
25 STORM_LOG_WARN_COND(newFormulas.size() == formulas.size(), "The state elimination does not preserve all properties.");
27 "Labels are not preserved by the state elimination. This may cause incorrect results.");
28 return std::make_pair(storm::transformer::NonMarkovianChainTransformer<ValueType>::eliminateNonmarkovianStates(ma, labelBehavior), newFormulas);
29}
30
35template<typename ValueType>
36std::pair<std::shared_ptr<storm::models::sparse::Model<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>>
38 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
40
41 std::string timeRewardName = "_time";
42 while (model->hasRewardModel(timeRewardName)) {
43 timeRewardName += "_";
44 }
45 auto newFormulas = transformer.checkAndTransformFormulas(formulas, timeRewardName);
46 STORM_LOG_WARN_COND(newFormulas.size() == formulas.size(),
47 "Transformation of a " << model->getType() << " to a discrete time model does not preserve all properties.");
48
49 if (model->isOfType(storm::models::ModelType::Ctmc)) {
50 return std::make_pair(transformer.transform(*model->template as<storm::models::sparse::Ctmc<ValueType>>(), timeRewardName), newFormulas);
51 } else if (model->isOfType(storm::models::ModelType::MarkovAutomaton)) {
52 return std::make_pair(transformer.transform(*model->template as<storm::models::sparse::MarkovAutomaton<ValueType>>(), timeRewardName), newFormulas);
53 } else {
54 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
55 "Transformation of a " << model->getType() << " to a discrete time model is not supported");
56 }
57 return std::make_pair(nullptr, newFormulas);
58}
59
65template<typename ValueType>
66std::pair<std::shared_ptr<storm::models::sparse::Model<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>>
68 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
70
71 std::string timeRewardName = "_time";
72 while (model.hasRewardModel(timeRewardName)) {
73 timeRewardName += "_";
74 }
75 auto newFormulas = transformer.checkAndTransformFormulas(formulas, timeRewardName);
76 STORM_LOG_WARN_COND(newFormulas.size() == formulas.size(),
77 "Transformation of a " << model.getType() << " to a discrete time model does not preserve all properties.");
78
79 if (model.isOfType(storm::models::ModelType::Ctmc)) {
80 return std::make_pair(transformer.transform(std::move(*model.template as<storm::models::sparse::Ctmc<ValueType>>()), timeRewardName), newFormulas);
81 } else if (model.isOfType(storm::models::ModelType::MarkovAutomaton)) {
82 return std::make_pair(transformer.transform(std::move(*model.template as<storm::models::sparse::MarkovAutomaton<ValueType>>()), timeRewardName),
83 newFormulas);
84 } else {
85 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
86 "Transformation of a " << model.getType() << " to a discrete time model is not supported.");
87 }
88 return std::make_pair(nullptr, newFormulas);
89}
90
91template<typename ValueType>
92std::shared_ptr<storm::logic::Formula const> checkAndTransformContinuousToDiscreteTimeFormula(storm::logic::Formula const& formula,
93 std::string const& timeRewardName = "_time") {
95 if (transformer.preservesFormula(formula)) {
96 return transformer.checkAndTransformFormulas({formula.asSharedPointer()}, timeRewardName).front();
97 } else {
98 STORM_LOG_ERROR("Unable to transform formula " << formula << " to discrete time.");
99 }
100 return nullptr;
101}
102
106template<storm::dd::DdType Type, typename ValueType>
107std::shared_ptr<storm::models::sparse::Model<ValueType>> transformSymbolicToSparseModel(
108 std::shared_ptr<storm::models::symbolic::Model<Type, ValueType>> const& symbolicModel,
109 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas = std::vector<std::shared_ptr<storm::logic::Formula const>>()) {
110 switch (symbolicModel->getType()) {
113 *symbolicModel->template as<storm::models::symbolic::Dtmc<Type, ValueType>>(), formulas);
116 *symbolicModel->template as<storm::models::symbolic::Mdp<Type, ValueType>>(), formulas);
119 *symbolicModel->template as<storm::models::symbolic::Ctmc<Type, ValueType>>(), formulas);
122 *symbolicModel->template as<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>(), formulas);
123 default:
124 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
125 "Transformation of symbolic " << symbolicModel->getType() << " to sparse model is not supported.");
126 }
127 return nullptr;
128}
129
130template<typename ValueType>
131std::shared_ptr<storm::models::sparse::Model<ValueType>> transformToNondeterministicModel(storm::models::sparse::Model<ValueType>&& model) {
132 storm::storage::sparse::ModelComponents<ValueType> components(std::move(model.getTransitionMatrix()), std::move(model.getStateLabeling()),
133 std::move(model.getRewardModels()));
134 components.choiceLabeling = std::move(model.getOptionalChoiceLabeling());
135 components.stateValuations = std::move(model.getOptionalStateValuations());
136 components.choiceOrigins = std::move(model.getOptionalChoiceOrigins());
137 if (model.isOfType(storm::models::ModelType::Dtmc)) {
139 } else if (model.isOfType(storm::models::ModelType::Ctmc)) {
140 components.rateTransitions = true;
141 components.markovianStates = storm::storage::BitVector(components.transitionMatrix.getRowGroupCount(), true);
143 } else {
144 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException,
145 "Cannot transform model of type " << model.getType() << " to a nondeterministic model.");
146 }
147}
148
154template<typename ValueType>
155std::shared_ptr<storm::models::sparse::Model<ValueType>> permuteModelStates(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model,
157 std::optional<uint64_t> seed = std::nullopt) {
158 std::vector<storm::utility::permutation::index_type> permutation;
159 if (order == storm::utility::permutation::OrderKind::Random && seed.has_value()) {
160 permutation = storm::utility::permutation::createRandomPermutation(model->getNumberOfStates(), seed.value());
161 } else {
162 permutation = storm::utility::permutation::createPermutation(order, model->getTransitionMatrix(), model->getInitialStates());
163 }
164 return storm::transformer::permuteStates(*model, permutation);
165}
166
167} // namespace api
168} // namespace storm
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:571
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
This class represents a Markov automaton.
Base class for all sparse models.
Definition Model.h:32
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
This class represents a discrete-time Markov chain.
Definition Dtmc.h:13
This class represents a discrete-time Markov decision process.
This class represents a discrete-time Markov decision process.
Definition Mdp.h:13
Base class for all symbolic models.
Definition Model.h:42
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:16
static std::vector< std::shared_ptr< storm::logic::Formula const > > checkAndTransformFormulas(std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, std::string const &timeRewardName)
static std::shared_ptr< storm::models::sparse::Dtmc< ValueType, RewardModelType > > transform(storm::models::sparse::Ctmc< ValueType, RewardModelType > const &ctmc, boost::optional< std::string > const &timeRewardModelName=boost::none)
Transformer for eliminating chains of non-Markovian states (instantaneous path fragment leading to th...
static std::vector< std::shared_ptr< storm::logic::Formula const > > checkAndTransformFormulas(std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
Checks for the given formulae if the specified properties are preserved and removes formulae of prope...
static std::shared_ptr< storm::models::sparse::Ctmc< ValueType > > translate(storm::models::symbolic::Ctmc< Type, ValueType > const &symbolicCtmc, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas=std::vector< std::shared_ptr< storm::logic::Formula const > >())
std::shared_ptr< storm::models::sparse::Dtmc< ValueType > > translate(storm::models::symbolic::Dtmc< Type, ValueType > const &symbolicDtmc, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas=std::vector< std::shared_ptr< storm::logic::Formula const > >())
static std::shared_ptr< storm::models::sparse::MarkovAutomaton< ValueType > > translate(storm::models::symbolic::MarkovAutomaton< Type, ValueType > const &symbolicMa, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas=std::vector< std::shared_ptr< storm::logic::Formula const > >())
static std::shared_ptr< storm::models::sparse::Mdp< ValueType > > translate(storm::models::symbolic::Mdp< Type, ValueType > const &symbolicMdp, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas=std::vector< std::shared_ptr< storm::logic::Formula const > >())
#define STORM_LOG_ERROR(message)
Definition logging.h:26
#define STORM_LOG_WARN_COND(cond, message)
Definition macros.h:38
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
std::shared_ptr< storm::models::sparse::Model< ValueType > > transformToNondeterministicModel(storm::models::sparse::Model< ValueType > &&model)
std::shared_ptr< storm::models::sparse::Model< ValueType > > permuteModelStates(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, storm::utility::permutation::OrderKind order, std::optional< uint64_t > seed=std::nullopt)
Permutes the order of the states of the model according to the given order.
std::pair< std::shared_ptr< storm::models::sparse::Model< ValueType > >, std::vector< std::shared_ptr< storm::logic::Formula const > > > eliminateNonMarkovianChains(std::shared_ptr< storm::models::sparse::MarkovAutomaton< ValueType > > const &ma, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas, storm::transformer::EliminationLabelBehavior labelBehavior)
Eliminates chains of non-Markovian states from a given Markov Automaton.
std::shared_ptr< storm::models::sparse::Model< ValueType > > transformSymbolicToSparseModel(std::shared_ptr< storm::models::symbolic::Model< Type, ValueType > > const &symbolicModel, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas=std::vector< std::shared_ptr< storm::logic::Formula const > >())
Transforms the given symbolic model to a sparse model.
std::pair< std::shared_ptr< storm::models::sparse::Model< ValueType > >, std::vector< std::shared_ptr< storm::logic::Formula const > > > transformContinuousToDiscreteTimeSparseModel(std::shared_ptr< storm::models::sparse::Model< ValueType > > const &model, std::vector< std::shared_ptr< storm::logic::Formula const > > const &formulas)
Transforms the given continuous model to a discrete time model.
std::shared_ptr< storm::logic::Formula const > checkAndTransformContinuousToDiscreteTimeFormula(storm::logic::Formula const &formula, std::string const &timeRewardName="_time")
EliminationLabelBehavior
Specify criteria whether a state can be eliminated and how its labels should be treated.
std::shared_ptr< storm::models::sparse::Model< ValueType > > permuteStates(storm::models::sparse::Model< ValueType > const &originalModel, std::vector< uint64_t > const &permutation)
Applies the given permutation to the states of the given model.
std::shared_ptr< storm::models::sparse::Model< ValueType, RewardModelType > > buildModelFromComponents(storm::models::ModelType modelType, storm::storage::sparse::ModelComponents< ValueType, RewardModelType > &&components)
Definition builder.cpp:19
OrderKind
The order in which the states of a matrix are visited in a depth-first search or breadth-first search...
Definition permutation.h:21
std::vector< index_type > createRandomPermutation(index_type size)
Creates a random (uniformly distributed) permutation of the given size.
std::vector< index_type > createPermutation(OrderKind order, storm::storage::SparseMatrix< ValueType > const &transitionMatrix, storm::storage::BitVector const &initialStates)
Creates a permutation that orders the states of the given matrix in the given exploration order.
std::optional< storm::storage::sparse::StateValuations > stateValuations
storm::storage::SparseMatrix< ValueType > transitionMatrix
boost::optional< storm::storage::BitVector > markovianStates
std::optional< std::shared_ptr< storm::storage::sparse::ChoiceOrigins > > choiceOrigins
std::optional< storm::models::sparse::ChoiceLabeling > choiceLabeling