Storm
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}
60
66template<typename ValueType>
67std::pair<std::shared_ptr<storm::models::sparse::Model<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>>
69 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) {
71
72 std::string timeRewardName = "_time";
73 while (model.hasRewardModel(timeRewardName)) {
74 timeRewardName += "_";
75 }
76 auto newFormulas = transformer.checkAndTransformFormulas(formulas, timeRewardName);
77 STORM_LOG_WARN_COND(newFormulas.size() == formulas.size(),
78 "Transformation of a " << model.getType() << " to a discrete time model does not preserve all properties.");
79
80 if (model.isOfType(storm::models::ModelType::Ctmc)) {
81 return std::make_pair(transformer.transform(std::move(*model.template as<storm::models::sparse::Ctmc<ValueType>>()), timeRewardName), newFormulas);
82 } else if (model.isOfType(storm::models::ModelType::MarkovAutomaton)) {
83 return std::make_pair(transformer.transform(std::move(*model.template as<storm::models::sparse::MarkovAutomaton<ValueType>>()), timeRewardName),
84 newFormulas);
85 } else {
86 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
87 "Transformation of a " << model.getType() << " to a discrete time model is not supported.");
88 }
89 return std::make_pair(nullptr, newFormulas);
90 ;
91}
92
93template<typename ValueType>
94std::shared_ptr<storm::logic::Formula const> checkAndTransformContinuousToDiscreteTimeFormula(storm::logic::Formula const& formula,
95 std::string const& timeRewardName = "_time") {
97 if (transformer.preservesFormula(formula)) {
98 return transformer.checkAndTransformFormulas({formula.asSharedPointer()}, timeRewardName).front();
99 } else {
100 STORM_LOG_ERROR("Unable to transform formula " << formula << " to discrete time.");
101 }
102 return nullptr;
103}
104
108template<storm::dd::DdType Type, typename ValueType>
109std::shared_ptr<storm::models::sparse::Model<ValueType>> transformSymbolicToSparseModel(
110 std::shared_ptr<storm::models::symbolic::Model<Type, ValueType>> const& symbolicModel,
111 std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas = std::vector<std::shared_ptr<storm::logic::Formula const>>()) {
112 switch (symbolicModel->getType()) {
115 *symbolicModel->template as<storm::models::symbolic::Dtmc<Type, ValueType>>(), formulas);
118 *symbolicModel->template as<storm::models::symbolic::Mdp<Type, ValueType>>(), formulas);
121 *symbolicModel->template as<storm::models::symbolic::Ctmc<Type, ValueType>>(), formulas);
124 *symbolicModel->template as<storm::models::symbolic::MarkovAutomaton<Type, ValueType>>(), formulas);
125 default:
126 STORM_LOG_THROW(false, storm::exceptions::NotSupportedException,
127 "Transformation of symbolic " << symbolicModel->getType() << " to sparse model is not supported.");
128 }
129 return nullptr;
130}
131
132template<typename ValueType>
133std::shared_ptr<storm::models::sparse::Model<ValueType>> transformToNondeterministicModel(storm::models::sparse::Model<ValueType>&& model) {
134 storm::storage::sparse::ModelComponents<ValueType> components(std::move(model.getTransitionMatrix()), std::move(model.getStateLabeling()),
135 std::move(model.getRewardModels()));
136 components.choiceLabeling = std::move(model.getOptionalChoiceLabeling());
137 components.stateValuations = std::move(model.getOptionalStateValuations());
138 components.choiceOrigins = std::move(model.getOptionalChoiceOrigins());
139 if (model.isOfType(storm::models::ModelType::Dtmc)) {
141 } else if (model.isOfType(storm::models::ModelType::Ctmc)) {
142 components.rateTransitions = true;
143 components.markovianStates = storm::storage::BitVector(components.transitionMatrix.getRowGroupCount(), true);
145 } else {
146 STORM_LOG_THROW(false, storm::exceptions::InvalidOperationException,
147 "Cannot transform model of type " << model.getType() << " to a nondeterministic model.");
148 }
149}
150
156template<typename ValueType>
157std::shared_ptr<storm::models::sparse::Model<ValueType>> permuteModelStates(std::shared_ptr<storm::models::sparse::Model<ValueType>> const& model,
159 std::optional<uint64_t> seed = std::nullopt) {
160 std::vector<storm::utility::permutation::index_type> permutation;
161 if (order == storm::utility::permutation::OrderKind::Random && seed.has_value()) {
162 permutation = storm::utility::permutation::createRandomPermutation(model->getNumberOfStates(), seed.value());
163 } else {
164 permutation = storm::utility::permutation::createPermutation(order, model->getTransitionMatrix(), model->getInitialStates());
165 }
166 return storm::transformer::permuteStates(*model, permutation);
167}
168
169} // namespace api
170} // namespace storm
std::shared_ptr< Formula const > asSharedPointer()
Definition Formula.cpp:548
This class represents a continuous-time Markov chain.
Definition Ctmc.h:15
This class represents a Markov automaton.
Base class for all sparse models.
Definition Model.h:33
This class represents a continuous-time Markov chain.
Definition Ctmc.h:15
This class represents a discrete-time Markov chain.
Definition Dtmc.h:15
This class represents a discrete-time Markov decision process.
This class represents a discrete-time Markov decision process.
Definition Mdp.h:15
Base class for all symbolic models.
Definition Model.h:46
A bit vector that is internally represented as a vector of 64-bit values.
Definition BitVector.h:18
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:31
#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.
LabParser.cpp.
Definition cli.cpp:18
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