Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
Model.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <set>
5#include <unordered_map>
6
15
16namespace storm {
17namespace dd {
18
19template<storm::dd::DdType Type>
20class Dd;
21
22template<storm::dd::DdType Type>
23class DdManager;
24
25} // namespace dd
26
27namespace adapters {
28template<storm::dd::DdType Type, typename ValueType>
29class AddExpressionAdapter;
30}
31
32namespace models {
33namespace symbolic {
34
35template<storm::dd::DdType Type, typename ValueType>
36class StandardRewardModel;
37
41template<storm::dd::DdType Type, typename CValueType = double>
42class Model : public storm::models::Model<CValueType> {
43 public:
44 typedef CValueType ValueType;
45
46 static const storm::dd::DdType DdType = Type;
48
50
51 Model(Model<Type, ValueType> const& other) = default;
52 Model& operator=(Model<Type, ValueType> const& other) = default;
53
54 Model(Model<Type, ValueType>&& other) = default;
56
74 Model(storm::models::ModelType const& modelType, std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates,
76 std::set<storm::expressions::Variable> const& rowVariables,
77 std::shared_ptr<storm::adapters::AddExpressionAdapter<Type, ValueType>> rowExpressionAdapter,
78 std::set<storm::expressions::Variable> const& columnVariables,
79 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
80 std::map<std::string, storm::expressions::Expression> labelToExpressionMap = std::map<std::string, storm::expressions::Expression>(),
81 std::unordered_map<std::string, RewardModelType> const& rewardModels = std::unordered_map<std::string, RewardModelType>());
82
98 Model(storm::models::ModelType const& modelType, std::shared_ptr<storm::dd::DdManager<Type>> manager, storm::dd::Bdd<Type> reachableStates,
100 std::set<storm::expressions::Variable> const& rowVariables, std::set<storm::expressions::Variable> const& columnVariables,
101 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& rowColumnMetaVariablePairs,
102 std::map<std::string, storm::dd::Bdd<Type>> labelToBddMap = std::map<std::string, storm::dd::Bdd<Type>>(),
103 std::unordered_map<std::string, RewardModelType> const& rewardModels = std::unordered_map<std::string, RewardModelType>());
104
105 virtual uint_fast64_t getNumberOfStates() const override;
106
107 virtual uint_fast64_t getNumberOfTransitions() const override;
108
109 virtual uint_fast64_t getNumberOfChoices() const override;
110
117
123 std::shared_ptr<storm::dd::DdManager<Type>> const& getManagerAsSharedPointer() const;
124
131
138
139 /*
140 * Retrieves the deadlock states of the model.
141 */
143
150 virtual storm::dd::Bdd<Type> getStates(std::string const& label) const;
151
158 virtual storm::expressions::Expression getExpression(std::string const& label) const;
159
166 virtual storm::dd::Bdd<Type> getStates(storm::expressions::Expression const& expression) const;
167
174 virtual bool hasLabel(std::string const& label) const;
175
182
189
197 virtual storm::dd::Bdd<Type> getQualitativeTransitionMatrix(bool keepNondeterminism = true) const;
198
204 std::set<storm::expressions::Variable> const& getRowVariables() const;
205
211 std::set<storm::expressions::Variable> const& getColumnVariables() const;
212
218 std::set<storm::expressions::Variable> getRowAndNondeterminismVariables() const;
219
225 std::set<storm::expressions::Variable> getColumnAndNondeterminismVariables() const;
226
232 virtual std::set<storm::expressions::Variable> const& getNondeterminismVariables() const;
233
239 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> const& getRowColumnMetaVariablePairs() const;
240
247
253 virtual bool hasRewardModel(std::string const& rewardModelName) const override;
254
260 RewardModelType const& getRewardModel(std::string const& rewardModelName) const;
261
268
274 virtual std::string const& getUniqueRewardModelName() const override;
275
282
288 virtual bool hasUniqueRewardModel() const override;
289
295 bool hasRewardModel() const;
296
297 std::unordered_map<std::string, RewardModelType>& getRewardModels();
298 std::unordered_map<std::string, RewardModelType> const& getRewardModels() const;
299
305 uint_fast64_t getNumberOfRewardModels() const;
306
307 virtual void printModelInformationToStream(std::ostream& out) const override;
308
309 virtual bool isSymbolicModel() const override;
310
311 virtual std::optional<storm::dd::DdType> getDdType() const override;
312
313 virtual bool isExact() const override;
314
315 virtual bool supportsParameters() const override;
316
323 virtual bool hasParameters() const override;
324
325 std::vector<std::string> getLabels() const;
326
327 void addParameters(std::set<storm::RationalFunctionVariable> const& parameters);
328
329 std::set<storm::RationalFunctionVariable> const& getParameters() const;
330
331 template<typename NewValueType>
332 typename std::enable_if<!std::is_same<ValueType, NewValueType>::value, std::shared_ptr<Model<Type, NewValueType>>>::type toValueType() const;
333
334 template<typename NewValueType>
335 typename std::enable_if<std::is_same<ValueType, NewValueType>::value, std::shared_ptr<Model<Type, NewValueType>>>::type toValueType() const;
336
337 void writeDotToFile(std::string const& filename) const;
338
339 protected:
345 std::map<std::string, storm::expressions::Expression> const& getLabelToExpressionMap() const;
346
352 std::map<std::string, storm::dd::Bdd<Type>> const& getLabelToBddMap() const;
353
359 void printModelInformationHeaderToStream(std::ostream& out) const;
360
367 void printModelInformationFooterToStream(std::ostream& out) const;
368
374 void printRewardModelsInformationToStream(std::ostream& out) const;
375
381 virtual void printDdVariableInformationToStream(std::ostream& out) const;
382
383 protected:
389 std::shared_ptr<storm::adapters::AddExpressionAdapter<Type, ValueType>> const& getRowExpressionAdapter() const;
390
391 private:
392 // The manager responsible for the decision diagrams.
393 std::shared_ptr<storm::dd::DdManager<Type>> manager;
394
395 // A vector representing the reachable states of the model.
396 storm::dd::Bdd<Type> reachableStates;
397
398 protected:
399 // A matrix representing transition relation.
401
402 private:
403 // The meta variables used to encode the rows of the transition matrix.
404 std::set<storm::expressions::Variable> rowVariables;
405
406 // An adapter that can translate expressions to DDs over the row meta variables.
407 std::shared_ptr<storm::adapters::AddExpressionAdapter<Type, ValueType>> rowExpressionAdapter;
408
409 // The meta variables used to encode the columns of the transition matrix.
410 std::set<storm::expressions::Variable> columnVariables;
411
412 // A vector holding all pairs of row and column meta variable pairs. This is used to swap the variables
413 // in the DDs from row to column variables and vice versa.
414 std::vector<std::pair<storm::expressions::Variable, storm::expressions::Variable>> rowColumnMetaVariablePairs;
415
416 // A mapping from labels to expressions defining them.
417 std::map<std::string, storm::expressions::Expression> labelToExpressionMap;
418
419 // A mapping from labels to BDDs characterizing the labeled states.
420 std::map<std::string, storm::dd::Bdd<Type>> labelToBddMap;
421
422 // The reward models associated with the model.
423 std::unordered_map<std::string, RewardModelType> rewardModels;
424
425 // The parameters. Only meaningful for models over rational functions.
426 std::set<storm::RationalFunctionVariable> parameters;
427
428 // An empty variable set that can be used when references to non-existing sets need to be returned.
429 std::set<storm::expressions::Variable> emptyVariableSet;
430};
431
432} // namespace symbolic
433} // namespace models
434} // namespace storm
Definition DdTest.cpp:38
Base class for all symbolic models.
Definition Model.h:42
virtual bool hasParameters() const override
Checks whether the model has parameters.
Definition Model.cpp:407
storm::dd::DdManager< Type > & getManager() const
Retrieves the manager responsible for the DDs that represent this model.
Definition Model.cpp:87
RewardModelType const & getRewardModel(std::string const &rewardModelName) const
Retrieves the reward model with the given name, if one exists.
Definition Model.cpp:244
void addParameters(std::set< storm::RationalFunctionVariable > const &parameters)
Definition Model.cpp:422
storm::dd::Add< Type, ValueType > const & getTransitionMatrix() const
Retrieves the matrix representing the transitions of the model.
Definition Model.cpp:172
storm::dd::Bdd< Type > const & getDeadlockStates() const
Definition Model.cpp:107
virtual void printModelInformationToStream(std::ostream &out) const override
Prints information about the model to the specified stream.
Definition Model.cpp:303
virtual storm::expressions::Expression getExpression(std::string const &label) const
Returns the expression for the given label.
Definition Model.cpp:127
std::shared_ptr< storm::adapters::AddExpressionAdapter< Type, ValueType > > const & getRowExpressionAdapter() const
Retrieves the expression adapter of this model.
Definition Model.cpp:373
void writeDotToFile(std::string const &filename) const
Definition Model.cpp:398
Model & operator=(Model< Type, ValueType > &&other)=default
RewardModelType const & getUniqueRewardModel() const
Retrieves the unique reward model, if there exists exactly one.
Definition Model.cpp:262
virtual bool isSymbolicModel() const override
Checks whether the model is a symbolic model.
Definition Model.cpp:378
virtual void printDdVariableInformationToStream(std::ostream &out) const
Prints information about the DD variables to the specified stream.
Definition Model.cpp:358
virtual std::string const & getUniqueRewardModelName() const override
Retrieves the name of the unique reward model, if there exists exactly one.
Definition Model.cpp:269
virtual storm::dd::Bdd< Type > getQualitativeTransitionMatrix(bool keepNondeterminism=true) const
Retrieves the matrix qualitatively (i.e.
Definition Model.cpp:182
std::set< storm::expressions::Variable > const & getColumnVariables() const
Retrieves the meta variables used to encode the columns of the transition matrix and the vector indic...
Definition Model.cpp:192
std::shared_ptr< storm::dd::DdManager< Type > > const & getManagerAsSharedPointer() const
Retrieves the manager responsible for the DDs that represent this model.
Definition Model.cpp:92
Model(Model< Type, ValueType > &&other)=default
Model & operator=(Model< Type, ValueType > const &other)=default
uint_fast64_t getNumberOfRewardModels() const
Retrieves the number of reward models associated with this model.
Model(Model< Type, ValueType > const &other)=default
std::enable_if<!std::is_same< ValueType, NewValueType >::value, std::shared_ptr< Model< Type, NewValueType > > >::type toValueType() const
Definition Model.cpp:443
std::vector< std::string > getLabels() const
Definition Model.cpp:309
storm::dd::Add< Type, ValueType > getRowColumnIdentity() const
Retrieves an ADD that represents the diagonal of the transition matrix.
Definition Model.cpp:233
static const storm::models::ModelRepresentation Representation
Definition Model.h:49
void printRewardModelsInformationToStream(std::ostream &out) const
Prints information about the reward models to the specified stream.
Definition Model.cpp:340
virtual bool isExact() const override
Checks whether the model is exact.
Definition Model.cpp:388
virtual bool supportsParameters() const override
Checks whether the model supports parameters.
Definition Model.cpp:393
std::map< std::string, storm::dd::Bdd< Type > > const & getLabelToBddMap() const
Retrieves the mapping of labels to their defining expressions.
Definition Model.cpp:228
std::set< storm::RationalFunctionVariable > const & getParameters() const
Definition Model.cpp:427
storm::dd::Bdd< Type > const & getInitialStates() const
Retrieves the initial states of the model.
Definition Model.cpp:102
storm::dd::Add< Type, ValueType > transitionMatrix
Definition Model.h:400
virtual std::set< storm::expressions::Variable > const & getNondeterminismVariables() const
Retrieves all meta variables used to encode the nondeterminism.
Definition Model.cpp:213
void printModelInformationFooterToStream(std::ostream &out) const
Prints the information footer (reward models, labels) of the model to the specified stream.
Definition Model.cpp:326
std::vector< std::pair< storm::expressions::Variable, storm::expressions::Variable > > const & getRowColumnMetaVariablePairs() const
Retrieves the pairs of row and column meta variables.
Definition Model.cpp:218
std::set< storm::expressions::Variable > const & getRowVariables() const
Retrieves the meta variables used to encode the rows of the transition matrix and the vector indices.
Definition Model.cpp:187
static const storm::dd::DdType DdType
Definition Model.h:46
virtual bool hasLabel(std::string const &label) const
Retrieves whether the given label is a valid label in this model.
Definition Model.cpp:157
std::map< std::string, storm::expressions::Expression > const & getLabelToExpressionMap() const
Retrieves the mapping of labels to their defining expressions.
Definition Model.cpp:223
void printModelInformationHeaderToStream(std::ostream &out) const
Prints the information header (number of states and transitions) of the model to the specified stream...
Definition Model.cpp:318
std::unordered_map< std::string, RewardModelType > & getRewardModels()
Definition Model.cpp:293
virtual uint_fast64_t getNumberOfChoices() const override
Returns the number of choices ine the model.
Definition Model.cpp:82
std::set< storm::expressions::Variable > getRowAndNondeterminismVariables() const
Retrieves all meta variables used to encode rows and nondetermism.
Definition Model.cpp:197
std::set< storm::expressions::Variable > getColumnAndNondeterminismVariables() const
Retrieves all meta variables used to encode columns and nondetermism.
Definition Model.cpp:205
virtual storm::dd::Bdd< Type > getStates(std::string const &label) const
Returns the sets of states labeled with the given label.
Definition Model.cpp:112
virtual uint_fast64_t getNumberOfTransitions() const override
Returns the number of (non-zero) transitions of the model.
Definition Model.cpp:77
std::enable_if< std::is_same< ValueType, NewValueType >::value, std::shared_ptr< Model< Type, NewValueType > > >::type toValueType() const
StandardRewardModel< Type, ValueType > RewardModelType
Definition Model.h:47
bool hasRewardModel() const
Retrieves whether the model has at least one reward model.
Definition Model.cpp:288
virtual bool hasUniqueRewardModel() const override
Retrieves whether the model has a unique reward model.
Definition Model.cpp:283
storm::dd::Bdd< Type > const & getReachableStates() const
Retrieves the reachable states of the model.
Definition Model.cpp:97
virtual uint_fast64_t getNumberOfStates() const override
Returns the number of states of the model.
Definition Model.cpp:72
virtual std::optional< storm::dd::DdType > getDdType() const override
Definition Model.cpp:383