Storm 1.14.0.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
5#include "Composition.h"
18
19namespace storm {
20namespace expressions {
22}
23
24namespace jani {
25
26class Variable;
27class Automaton;
28class Exporter;
31class Property;
33
34class Model {
35 public:
36 friend class Exporter;
37
41 Model();
42
46 Model(std::string const& name, ModelType const& modelType, uint64_t version = 1,
47 boost::optional<std::shared_ptr<storm::expressions::ExpressionManager>> const& expressionManager = boost::none);
48
52 Model(Model const& other);
53
57 Model& operator=(Model const& other);
58
59 Model(Model&& other);
61
66
70 uint64_t getJaniVersion() const;
71
75 ModelType const& getModelType() const;
76
81 void setModelType(ModelType const&);
82
86 ModelFeatures const& getModelFeatures() const;
87
92
96 std::string const& getName() const;
97
101 void setName(std::string const& newName);
102
110 std::shared_ptr<storm::utility::solver::SmtSolverFactory> const& smtSolverFactory = std::make_shared<storm::utility::solver::SmtSolverFactory>()) const;
111
117 bool hasAction(std::string const& name) const;
118
124 uint64_t getActionIndex(std::string const& name) const;
125
129 std::unordered_map<std::string, uint64_t> const& getActionToIndexMap() const;
130
136 uint64_t addAction(Action const& action);
137
141 Action const& getAction(uint64_t index) const;
142
146 std::vector<Action> const& getActions() const;
147
151 std::map<uint64_t, std::string> getActionIndexToNameMap() const;
152
157
161 void addConstant(Constant const& constant);
162
166 bool hasConstant(std::string const& name) const;
167
171 void removeConstant(std::string const& name);
172
176 std::vector<Constant> const& getConstants() const;
177
181 std::vector<Constant>& getConstants();
182
187 Constant const& getConstant(std::string const& name) const;
188
192 Variable const& addVariable(Variable const& variable);
193
198
202 VariableSet const& getGlobalVariables() const;
203
210 std::set<storm::expressions::Variable> getAllExpressionVariables(bool includeLocationExpressionVariables = false) const;
211
217 std::set<storm::expressions::Variable> getAllLocationExpressionVariables() const;
218
222 bool hasGlobalVariable(std::string const& name) const;
223
227 Variable const& getGlobalVariable(std::string const& name) const;
228
233
237 FunctionDefinition const& addFunctionDefinition(FunctionDefinition const& functionDefinition);
238
242 std::unordered_map<std::string, FunctionDefinition> const& getGlobalFunctionDefinitions() const;
243
247 std::unordered_map<std::string, FunctionDefinition>& getGlobalFunctionDefinitions();
248
253
258
263 bool isNonTrivialRewardModelExpression(std::string const& identifier) const;
264
270 bool addNonTrivialRewardExpression(std::string const& identifier, storm::expressions::Expression const& rewardExpression);
271
275 storm::expressions::Expression getRewardModelExpression(std::string const& identifier) const;
276
281 std::vector<std::pair<std::string, storm::expressions::Expression>> getAllRewardModelExpressions() const;
282
286 std::unordered_map<std::string, storm::expressions::Expression> const& getNonTrivialRewardExpressions() const;
287
291 std::unordered_map<std::string, storm::expressions::Expression>& getNonTrivialRewardExpressions();
292
296 uint64_t addAutomaton(Automaton const& automaton);
297
301 std::vector<Automaton>& getAutomata();
302
306 std::vector<Automaton> const& getAutomata() const;
307
313 void replaceAutomaton(uint64_t index, Automaton const& newAutomaton);
314
320 bool hasAutomaton(std::string const& name) const;
324 Automaton& getAutomaton(std::string const& name);
325
329 Automaton& getAutomaton(uint64_t index);
330
334 Automaton const& getAutomaton(uint64_t index) const;
335
339 Automaton const& getAutomaton(std::string const& name) const;
340
344 uint64_t getAutomatonIndex(std::string const& name) const;
345
349 std::size_t getNumberOfAutomata() const;
350
354 std::size_t getNumberOfEdges() const;
355
359 std::size_t getTotalNumberOfNonTransientVariables() const;
360
365
369 void setSystemComposition(std::shared_ptr<Composition> const& composition);
370
376
380 std::shared_ptr<Composition> getStandardSystemComposition() const;
381
385 Composition const& getSystemComposition() const;
386
392 void simplifyComposition();
393
397 std::set<std::string> getActionNames(bool includeSilent = true) const;
398
403 Model defineUndefinedConstants(std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantDefinitions) const;
404
408 bool hasUndefinedConstants() const;
409
413 std::vector<std::reference_wrapper<Constant const>> getUndefinedConstants() const;
414
419
423 Model& substituteConstantsInPlace(bool const substituteTranscendentalNumbers);
424
430
437 Model preprocess(std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantDefinitions) const;
438
446 Model preprocess(std::string const& constantDefinitionString = "") const;
447
452 std::map<storm::expressions::Variable, storm::expressions::Expression> getConstantsSubstitution() const;
453
458 void substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution, bool const substituteTranscendentalNumbers);
459
464 void substituteFunctions();
465 void substituteFunctions(std::vector<Property>& properties);
466
475
479 bool containsArrayVariables() const;
480
486 ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess = false);
487
492 void eliminateArrays(std::vector<Property>& properties);
493
498 ModelFeatures restrictToFeatures(ModelFeatures const& modelFeatures);
499
504 ModelFeatures restrictToFeatures(ModelFeatures const& modelFeatures, std::vector<Property>& properties);
505
509 bool hasInitialStatesRestriction() const;
510
514 bool hasNonTrivialInitialStates() const;
515
519 void setInitialStatesRestriction(storm::expressions::Expression const& initialStatesRestriction);
520
525
530
536
542 storm::expressions::Expression getInitialStatesExpression(std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& automata) const;
543
547 bool isDeterministicModel() const;
548
552 bool isDiscreteTimeModel() const;
553
559 std::vector<storm::expressions::Expression> getAllRangeExpressions(
560 std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& automata = {}) const;
561
566 bool hasStandardComposition() const;
567
572
578 void finalize();
579
583 void checkValid() const;
584
590 std::vector<std::reference_wrapper<Automaton const>> const& automata) const;
591
596 storm::expressions::Expression getLabelExpression(Variable const& transientVariable) const;
597
604
609 void liftTransientEdgeDestinationAssignments(int64_t maxLevel = 0);
610
615
620 bool usesAssignmentLevels(bool onlyTransient = false) const;
621
626 bool isLinear() const;
627
629
630 // Pushes all edge assignments to their destination
632
638 bool reusesActionsInComposition() const;
639
643 static uint64_t encodeAutomatonAndEdgeIndices(uint64_t automatonIndex, uint64_t edgeIndex);
644 static std::pair<uint64_t, uint64_t> decodeAutomatonAndEdgeIndices(uint64_t index);
645
650 Model restrictEdges(storm::storage::FlatSet<uint_fast64_t> const& automataAndEdgeIndices) const;
651
652 void writeDotToStream(std::ostream& outStream = std::cout) const;
653
655 static const std::string SILENT_ACTION_NAME;
656
658 static const uint64_t SILENT_ACTION_INDEX;
659
660 private:
664 Model createModelFromAutomaton(Automaton const& automaton) const;
665
667 std::string name;
668
670 ModelType modelType;
671
673 uint64_t version;
674
676 ModelFeatures modelFeatures;
677
679 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
680
682 std::vector<Action> actions;
683
685 std::unordered_map<std::string, uint64_t> actionToIndex;
686
689 std::unordered_map<std::string, storm::expressions::Expression> nonTrivialRewardModels;
690
692 storm::storage::FlatSet<uint64_t> nonsilentActionIndices;
693
695 std::vector<Constant> constants;
696
698 std::unordered_map<std::string, uint64_t> constantToIndex;
699
701 VariableSet globalVariables;
702
705 std::unordered_map<std::string, FunctionDefinition> globalFunctions;
706
708 std::vector<Automaton> automata;
709
711 std::unordered_map<std::string, size_t> automatonToIndex;
712
714 std::shared_ptr<Composition> composition;
715
716 // The expression restricting the legal initial values of the global variables.
717 storm::expressions::Expression initialStatesRestriction;
718};
719
720std::ostream& operator<<(std::ostream& out, Model const& model);
721} // namespace jani
722} // namespace storm
This class is responsible for managing a set of typed variables and all expressions using these varia...
void setInitialStatesRestriction(storm::expressions::Expression const &initialStatesRestriction)
Sets the expression restricting the legal initial values of the global variables.
Definition Model.cpp:1291
bool hasUndefinedConstants() const
Retrieves whether the model still has undefined constants.
Definition Model.cpp:1079
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
Definition Model.cpp:109
std::set< std::string > getActionNames(bool includeSilent=true) const
Retrieves the set of action names.
Definition Model.cpp:1022
std::size_t getNumberOfEdges() const
Retrieves the total number of edges in this model.
Definition Model.cpp:693
Model preprocess(std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions) const
Preprocesses the model by defining the given constant definitions and substituting constants.
Definition Model.cpp:1155
Model & replaceUnassignedVariablesWithConstants()
Replaces each variable to which we never assign a value with a constant.
Definition Model.cpp:1100
storm::storage::FlatSet< uint64_t > const & getNonsilentActionIndices() const
Retrieves all non-silent action indices of the model.
Definition Model.cpp:646
bool hasAction(std::string const &name) const
Checks whether the model has an action with the given name.
Definition Model.cpp:628
Variable const & getGlobalVariable(std::string const &name) const
Retrieves the global variable with the given name if one exists.
Definition Model.cpp:757
std::vector< storm::expressions::Expression > getAllRangeExpressions(std::vector< std::reference_wrapper< storm::jani::Automaton const > > const &automata={}) const
Retrieves a list of expressions that characterize the legal values of the variables in this model.
Definition Model.cpp:1388
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:717
Model()
Creates an uninitialized model.
Definition Model.cpp:43
storm::expressions::ExpressionManager & getExpressionManager() const
Retrieves the manager responsible for the expressions in the JANI model.
Definition Model.cpp:785
std::unordered_map< std::string, storm::expressions::Expression > const & getNonTrivialRewardExpressions() const
Retrieves all available non-trivial reward model names and expressions of the model.
Definition Model.cpp:851
bool hasInitialStatesRestriction() const
Retrieves whether there is an expression restricting the legal initial values of the global variables...
Definition Model.cpp:1295
Model & substituteConstantsInPlace(bool const substituteTranscendentalNumbers)
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1105
bool addNonTrivialRewardExpression(std::string const &identifier, storm::expressions::Expression const &rewardExpression)
Adds a reward expression, i.e., a reward model that does not consist of a single, global,...
Definition Model.cpp:797
friend class Exporter
Definition Model.h:36
storm::expressions::Expression getRewardModelExpression(std::string const &identifier) const
Retrieves the defining reward expression of the reward model with the given identifier.
Definition Model.cpp:809
bool reusesActionsInComposition() const
Checks whether in the composition, actions are reused: That is, if the model is put in parallel compo...
Definition Model.cpp:1593
void setSystemComposition(std::shared_ptr< Composition > const &composition)
Sets the system composition expression of the JANI model.
Definition Model.cpp:1014
static uint64_t encodeAutomatonAndEdgeIndices(uint64_t automatonIndex, uint64_t edgeIndex)
Encode and decode a tuple of automaton and edge index in one 64-bit index.
Definition Model.cpp:1600
Composition const & getSystemComposition() const
Retrieves the system composition expression.
Definition Model.cpp:945
bool hasTransientEdgeDestinationAssignments() const
Retrieves whether there is any transient edge destination assignment in the model.
Definition Model.cpp:1562
storm::expressions::Expression const & getInitialStatesRestriction() const
Gets the expression restricting the legal initial values of the global variables.
Definition Model.cpp:1299
void liftTransientEdgeDestinationAssignments(int64_t maxLevel=0)
Lifts the common edge destination assignments of transient variables to edge assignments.
Definition Model.cpp:1556
void replaceAutomaton(uint64_t index, Automaton const &newAutomaton)
Replaces the automaton at index with a new automaton.
Definition Model.cpp:880
std::shared_ptr< Composition > getStandardSystemComposition() const
Gets the system composition as the standard, fully-synchronizing parallel composition.
Definition Model.cpp:914
InformationObject getModelInformation() const
Returns various information of this model.
Definition Model.cpp:709
std::set< storm::expressions::Variable > getAllExpressionVariables(bool includeLocationExpressionVariables=false) const
Retrieves all expression variables used by this model.
Definition Model.cpp:725
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
Definition Model.cpp:1323
bool hasStandardComposition() const
Retrieves whether this model has the standard composition, that is it composes all automata in parall...
Definition Model.cpp:1474
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
Definition Model.h:658
std::vector< Automaton > & getAutomata()
Retrieves the automata of the model.
Definition Model.cpp:868
ModelType const & getModelType() const
Retrieves the type of the model.
Definition Model.cpp:117
bool hasNonTrivialRewardExpression() const
Returns true iff there is a non-trivial reward model, i.e., a reward model that does not consist of a...
Definition Model.cpp:789
std::vector< Constant > const & getConstants() const
Retrieves the constants of the model.
Definition Model.cpp:685
std::vector< Action > const & getActions() const
Retrieves the actions of the model.
Definition Model.cpp:642
bool undefinedConstantsAreGraphPreserving() const
Checks that undefined constants (parameters) of the model preserve the graph of the underlying model.
Definition Model.cpp:1497
void pushEdgeAssignmentsToDestinations()
Definition Model.cpp:1550
Model substituteConstants() const
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1140
std::size_t getTotalNumberOfNonTransientVariables() const
Number of global and local variables.
Definition Model.cpp:701
storm::expressions::Expression getLabelExpression(Variable const &transientVariable, std::vector< std::reference_wrapper< Automaton const > > const &automata) const
Creates the expression that characterizes all states in which the provided transient boolean variable...
Definition Model.cpp:1431
void addConstant(Constant const &constant)
Adds the given constant to the model.
Definition Model.cpp:650
void substitute(std::map< storm::expressions::Variable, storm::expressions::Expression > const &substitution, bool const substituteTranscendentalNumbers)
Substitutes all expression variables in all expressions of the model.
Definition Model.cpp:1177
uint64_t getJaniVersion() const
Retrieves the JANI-version of the model.
Definition Model.cpp:113
void substituteFunctions()
Substitutes all function calls with the corresponding function definition.
Definition Model.cpp:1216
Model(Model &&other)
void setStandardSystemComposition()
Sets the system composition to be the fully-synchronizing parallel composition of all automat.
Definition Model.cpp:1018
Variable const & addVariable(Variable const &variable)
Adds the given variable to this model.
Definition Model.cpp:713
Action const & getAction(uint64_t index) const
Retrieves the action with the given index.
Definition Model.cpp:624
std::vector< std::pair< std::string, storm::expressions::Expression > > getAllRewardModelExpressions() const
Retrieves all available reward model names and expressions of the model.
Definition Model.cpp:837
void checkValid() const
Checks if the model is valid JANI, which should be verified before any further operations are applied...
Definition Model.cpp:1416
std::string const & getName() const
Retrieves the name of the model.
Definition Model.cpp:133
bool hasConstant(std::string const &name) const
Retrieves whether the model has a constant with the given name.
Definition Model.cpp:659
void removeConstant(std::string const &name)
Removes (without checks) a constant from the model.
Definition Model.cpp:663
bool isNonTrivialRewardModelExpression(std::string const &identifier) const
Returns true iff the given identifier corresponds to a non-trivial reward expression i....
Definition Model.cpp:793
bool isDeterministicModel() const
Determines whether this model is a deterministic one in the sense that each state only has one choice...
Definition Model.cpp:1380
bool hasNonGlobalTransientVariable() const
Retrieves whether this model has a non-global transient variable.
Definition Model.cpp:761
void simplifyComposition()
Attempts to simplify the composition.
Definition Model.cpp:981
Model flattenComposition(std::shared_ptr< storm::utility::solver::SmtSolverFactory > const &smtSolverFactory=std::make_shared< storm::utility::solver::SmtSolverFactory >()) const
Flatten the composition to obtain an equivalent model that contains exactly one automaton that has th...
Definition Model.cpp:438
void writeDotToStream(std::ostream &outStream=std::cout) const
Definition Model.cpp:1649
FunctionDefinition const & addFunctionDefinition(FunctionDefinition const &functionDefinition)
Adds the given function definition.
Definition Model.cpp:770
Model defineUndefinedConstants(std::map< storm::expressions::Variable, storm::expressions::Expression > const &constantDefinitions) const
Defines the undefined constants of the model by the given expressions.
Definition Model.cpp:1042
static const std::string SILENT_ACTION_NAME
The name of the silent action.
Definition Model.h:655
bool containsArrayVariables() const
Returns true if at least one array variable occurs in the model.
Definition Model.cpp:1225
Constant const & getConstant(std::string const &name) const
Retrieves the constant with the given name (if any).
Definition Model.cpp:679
std::unordered_map< std::string, uint64_t > const & getActionToIndexMap() const
Retrieves the mapping from action names to their indices.
Definition Model.cpp:638
uint64_t addAction(Action const &action)
Adds an action to the model.
Definition Model.cpp:613
void makeStandardJaniCompliant()
Definition Model.cpp:1539
std::size_t getNumberOfAutomata() const
Retrieves the number of automata in this model.
Definition Model.cpp:910
bool isDiscreteTimeModel() const
Determines whether this model is a discrete-time model.
Definition Model.cpp:1384
bool hasGlobalVariable(std::string const &name) const
Retrieves whether this model has a global variable with the given name.
Definition Model.cpp:753
ModelFeatures const & getModelFeatures() const
Retrieves the enabled model features.
Definition Model.cpp:125
std::map< storm::expressions::Variable, storm::expressions::Expression > getConstantsSubstitution() const
Retrieves a mapping from expression variables associated with defined constants of the model to their...
Definition Model.cpp:1165
bool hasAutomaton(std::string const &name) const
Rerieves whether there exists an automaton with the given name.
Definition Model.cpp:876
Model restrictEdges(storm::storage::FlatSet< uint_fast64_t > const &automataAndEdgeIndices) const
Creates a new model that only contains the selected edges.
Definition Model.cpp:1608
uint64_t addAutomaton(Automaton const &automaton)
Adds the given automaton to the automata of this model.
Definition Model.cpp:859
Automaton & getAutomaton(std::string const &name)
Retrieves the automaton with the given name.
Definition Model.cpp:884
bool hasNonTrivialInitialStates() const
Retrieves whether there are non-trivial initial states in the model or any of the contained automata.
Definition Model.cpp:1303
void setModelType(ModelType const &)
Changes (only) the type declaration of the model.
Definition Model.cpp:121
bool isLinear() const
Checks the model for linearity.
Definition Model.cpp:1580
void setName(std::string const &newName)
Sets the name of the model.
Definition Model.cpp:137
std::map< uint64_t, std::string > getActionIndexToNameMap() const
Builds a map with action indices mapped to their names.
Definition Model.cpp:1032
uint64_t getActionIndex(std::string const &name) const
Get the index of the action.
Definition Model.cpp:632
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the model uses an assignment level other than zero.
Definition Model.cpp:1571
void finalize()
After adding all components to the model, this method has to be called.
Definition Model.cpp:1410
std::set< storm::expressions::Variable > getAllLocationExpressionVariables() const
Retrieves all location expression variables used by this model.
Definition Model.cpp:745
bool hasStandardCompliantComposition() const
Checks whether the composition has no nesting.
Definition Model.cpp:1488
uint64_t getAutomatonIndex(std::string const &name) const
Retrieves the index of the given automaton.
Definition Model.cpp:904
Model & operator=(Model &&other)
ModelFeatures restrictToFeatures(ModelFeatures const &modelFeatures)
Attempts to eliminate all features of this model that are not in the given set of features.
Definition Model.cpp:1249
bool hasTrivialInitialStatesExpression() const
Retrieves whether the initial states expression is trivial in the sense that no automaton has an init...
Definition Model.cpp:1331
Model & operator=(Model const &other)
Copy-assigns the given model.
Definition Model.cpp:69
std::unordered_map< std::string, FunctionDefinition > const & getGlobalFunctionDefinitions() const
Retrieves all global function definitions.
Definition Model.cpp:777
ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess=false)
Eliminates occurring array variables and expressions by replacing array variables by multiple basic v...
Definition Model.cpp:1237
Model substituteConstantsFunctionsTranscendentals() const
Definition Model.cpp:1147
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves all undefined constants of the model.
Definition Model.cpp:1088
static std::pair< uint64_t, uint64_t > decodeAutomatonAndEdgeIndices(uint64_t index)
Definition Model.cpp:1604
std::ostream & operator<<(std::ostream &stream, Assignment const &assignment)
boost::container::flat_set< Key, std::less< Key >, boost::container::new_allocator< Key > > FlatSet
Redefinition of flat_set was needed, because from Boost 1.70 on the default allocator is set to void.
Definition BoostTypes.h:13