Storm
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"
16
19
20namespace storm {
21namespace expressions {
22class ExpressionManager;
23}
24
25namespace jani {
26
27class Variable;
28class Automaton;
29class Exporter;
30class SynchronizationVector;
31struct ArrayEliminatorData;
32class Property;
33struct InformationObject;
34
35class Model {
36 public:
37 friend class Exporter;
38
42 Model();
43
47 Model(std::string const& name, ModelType const& modelType, uint64_t version = 1,
48 boost::optional<std::shared_ptr<storm::expressions::ExpressionManager>> const& expressionManager = boost::none);
49
53 Model(Model const& other);
54
58 Model& operator=(Model const& other);
59
60 Model(Model&& other);
62
67
71 uint64_t getJaniVersion() const;
72
76 ModelType const& getModelType() const;
77
82 void setModelType(ModelType const&);
83
87 ModelFeatures const& getModelFeatures() const;
88
93
97 std::string const& getName() const;
98
102 void setName(std::string const& newName);
103
111 std::shared_ptr<storm::utility::solver::SmtSolverFactory> const& smtSolverFactory = std::make_shared<storm::utility::solver::SmtSolverFactory>()) const;
112
118 bool hasAction(std::string const& name) const;
119
125 uint64_t getActionIndex(std::string const& name) const;
126
130 std::unordered_map<std::string, uint64_t> const& getActionToIndexMap() const;
131
137 uint64_t addAction(Action const& action);
138
142 Action const& getAction(uint64_t index) const;
143
147 std::vector<Action> const& getActions() const;
148
152 std::map<uint64_t, std::string> getActionIndexToNameMap() const;
153
158
162 void addConstant(Constant const& constant);
163
167 bool hasConstant(std::string const& name) const;
168
172 void removeConstant(std::string const& name);
173
177 std::vector<Constant> const& getConstants() const;
178
182 std::vector<Constant>& getConstants();
183
188 Constant const& getConstant(std::string const& name) const;
189
193 Variable const& addVariable(Variable const& variable);
194
199
203 VariableSet const& getGlobalVariables() const;
204
211 std::set<storm::expressions::Variable> getAllExpressionVariables(bool includeLocationExpressionVariables = false) const;
212
218 std::set<storm::expressions::Variable> getAllLocationExpressionVariables() const;
219
223 bool hasGlobalVariable(std::string const& name) const;
224
228 Variable const& getGlobalVariable(std::string const& name) const;
229
234
238 FunctionDefinition const& addFunctionDefinition(FunctionDefinition const& functionDefinition);
239
243 std::unordered_map<std::string, FunctionDefinition> const& getGlobalFunctionDefinitions() const;
244
248 std::unordered_map<std::string, FunctionDefinition>& getGlobalFunctionDefinitions();
249
254
259
264 bool isNonTrivialRewardModelExpression(std::string const& identifier) const;
265
271 bool addNonTrivialRewardExpression(std::string const& identifier, storm::expressions::Expression const& rewardExpression);
272
276 storm::expressions::Expression getRewardModelExpression(std::string const& identifier) const;
277
282 std::vector<std::pair<std::string, storm::expressions::Expression>> getAllRewardModelExpressions() const;
283
287 std::unordered_map<std::string, storm::expressions::Expression> const& getNonTrivialRewardExpressions() const;
288
292 std::unordered_map<std::string, storm::expressions::Expression>& getNonTrivialRewardExpressions();
293
297 uint64_t addAutomaton(Automaton const& automaton);
298
302 std::vector<Automaton>& getAutomata();
303
307 std::vector<Automaton> const& getAutomata() const;
308
314 void replaceAutomaton(uint64_t index, Automaton const& newAutomaton);
315
321 bool hasAutomaton(std::string const& name) const;
325 Automaton& getAutomaton(std::string const& name);
326
330 Automaton& getAutomaton(uint64_t index);
331
335 Automaton const& getAutomaton(uint64_t index) const;
336
340 Automaton const& getAutomaton(std::string const& name) const;
341
345 uint64_t getAutomatonIndex(std::string const& name) const;
346
350 std::size_t getNumberOfAutomata() const;
351
355 std::size_t getNumberOfEdges() const;
356
360 std::size_t getTotalNumberOfNonTransientVariables() const;
361
366
370 void setSystemComposition(std::shared_ptr<Composition> const& composition);
371
377
381 std::shared_ptr<Composition> getStandardSystemComposition() const;
382
386 Composition const& getSystemComposition() const;
387
393 void simplifyComposition();
394
398 std::set<std::string> getActionNames(bool includeSilent = true) const;
399
404 Model defineUndefinedConstants(std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantDefinitions) const;
405
409 bool hasUndefinedConstants() const;
410
414 std::vector<std::reference_wrapper<Constant const>> getUndefinedConstants() const;
415
420
424 Model& substituteConstantsInPlace(bool const substituteTranscendentalNumbers);
425
431
436 std::map<storm::expressions::Variable, storm::expressions::Expression> getConstantsSubstitution() const;
437
442 void substitute(std::map<storm::expressions::Variable, storm::expressions::Expression> const& substitution, bool const substituteTranscendentalNumbers);
443
448 void substituteFunctions();
449 void substituteFunctions(std::vector<Property>& properties);
450
459
463 bool containsArrayVariables() const;
464
470 ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess = false);
471
476 void eliminateArrays(std::vector<Property>& properties);
477
482 ModelFeatures restrictToFeatures(ModelFeatures const& modelFeatures);
483
488 ModelFeatures restrictToFeatures(ModelFeatures const& modelFeatures, std::vector<Property>& properties);
489
493 bool hasInitialStatesRestriction() const;
494
498 bool hasNonTrivialInitialStates() const;
499
503 void setInitialStatesRestriction(storm::expressions::Expression const& initialStatesRestriction);
504
509
514
520
526 storm::expressions::Expression getInitialStatesExpression(std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& automata) const;
527
531 bool isDeterministicModel() const;
532
536 bool isDiscreteTimeModel() const;
537
543 std::vector<storm::expressions::Expression> getAllRangeExpressions(
544 std::vector<std::reference_wrapper<storm::jani::Automaton const>> const& automata = {}) const;
545
550 bool hasStandardComposition() const;
551
556
562 void finalize();
563
567 void checkValid() const;
568
574 std::vector<std::reference_wrapper<Automaton const>> const& automata) const;
575
580 storm::expressions::Expression getLabelExpression(Variable const& transientVariable) const;
581
588
593 void liftTransientEdgeDestinationAssignments(int64_t maxLevel = 0);
594
599
604 bool usesAssignmentLevels(bool onlyTransient = false) const;
605
610 bool isLinear() const;
611
613
614 // Pushes all edge assignments to their destination
616
622 bool reusesActionsInComposition() const;
623
627 static uint64_t encodeAutomatonAndEdgeIndices(uint64_t automatonIndex, uint64_t edgeIndex);
628 static std::pair<uint64_t, uint64_t> decodeAutomatonAndEdgeIndices(uint64_t index);
629
634 Model restrictEdges(storm::storage::FlatSet<uint_fast64_t> const& automataAndEdgeIndices) const;
635
636 void writeDotToStream(std::ostream& outStream = std::cout) const;
637
639 static const std::string SILENT_ACTION_NAME;
640
642 static const uint64_t SILENT_ACTION_INDEX;
643
644 private:
648 Model createModelFromAutomaton(Automaton const& automaton) const;
649
651 std::string name;
652
654 ModelType modelType;
655
657 uint64_t version;
658
660 ModelFeatures modelFeatures;
661
663 std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
664
666 std::vector<Action> actions;
667
669 std::unordered_map<std::string, uint64_t> actionToIndex;
670
673 std::unordered_map<std::string, storm::expressions::Expression> nonTrivialRewardModels;
674
676 storm::storage::FlatSet<uint64_t> nonsilentActionIndices;
677
679 std::vector<Constant> constants;
680
682 std::unordered_map<std::string, uint64_t> constantToIndex;
683
685 VariableSet globalVariables;
686
689 std::unordered_map<std::string, FunctionDefinition> globalFunctions;
690
692 std::vector<Automaton> automata;
693
695 std::unordered_map<std::string, size_t> automatonToIndex;
696
698 std::shared_ptr<Composition> composition;
699
700 // The expression restricting the legal initial values of the global variables.
701 storm::expressions::Expression initialStatesRestriction;
702};
703
704std::ostream& operator<<(std::ostream& out, Model const& model);
705} // namespace jani
706} // 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:1280
bool hasUndefinedConstants() const
Retrieves whether the model still has undefined constants.
Definition Model.cpp:1083
storm::expressions::ExpressionManager & getManager() const
Retrieves the expression manager responsible for the expressions in the model.
Definition Model.cpp:113
std::set< std::string > getActionNames(bool includeSilent=true) const
Retrieves the set of action names.
Definition Model.cpp:1026
std::size_t getNumberOfEdges() const
Retrieves the total number of edges in this model.
Definition Model.cpp:697
Model & replaceUnassignedVariablesWithConstants()
Replaces each variable to which we never assign a value with a constant.
Definition Model.cpp:1104
storm::storage::FlatSet< uint64_t > const & getNonsilentActionIndices() const
Retrieves all non-silent action indices of the model.
Definition Model.cpp:650
bool hasAction(std::string const &name) const
Checks whether the model has an action with the given name.
Definition Model.cpp:632
Variable const & getGlobalVariable(std::string const &name) const
Retrieves the global variable with the given name if one exists.
Definition Model.cpp:761
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:1377
VariableSet & getGlobalVariables()
Retrieves the variables of this automaton.
Definition Model.cpp:721
Model()
Creates an uninitialized model.
Definition Model.cpp:47
storm::expressions::ExpressionManager & getExpressionManager() const
Retrieves the manager responsible for the expressions in the JANI model.
Definition Model.cpp:789
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:855
bool hasInitialStatesRestriction() const
Retrieves whether there is an expression restricting the legal initial values of the global variables...
Definition Model.cpp:1284
Model & substituteConstantsInPlace(bool const substituteTranscendentalNumbers)
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1109
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:801
friend class Exporter
Definition Model.h:37
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:813
bool reusesActionsInComposition() const
Checks whether in the composition, actions are reused: That is, if the model is put in parallel compo...
Definition Model.cpp:1582
void setSystemComposition(std::shared_ptr< Composition > const &composition)
Sets the system composition expression of the JANI model.
Definition Model.cpp:1018
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:1589
Composition const & getSystemComposition() const
Retrieves the system composition expression.
Definition Model.cpp:949
bool hasTransientEdgeDestinationAssignments() const
Retrieves whether there is any transient edge destination assignment in the model.
Definition Model.cpp:1551
storm::expressions::Expression const & getInitialStatesRestriction() const
Gets the expression restricting the legal initial values of the global variables.
Definition Model.cpp:1288
void liftTransientEdgeDestinationAssignments(int64_t maxLevel=0)
Lifts the common edge destination assignments of transient variables to edge assignments.
Definition Model.cpp:1545
void replaceAutomaton(uint64_t index, Automaton const &newAutomaton)
Replaces the automaton at index with a new automaton.
Definition Model.cpp:884
std::shared_ptr< Composition > getStandardSystemComposition() const
Gets the system composition as the standard, fully-synchronizing parallel composition.
Definition Model.cpp:918
InformationObject getModelInformation() const
Returns various information of this model.
Definition Model.cpp:713
std::set< storm::expressions::Variable > getAllExpressionVariables(bool includeLocationExpressionVariables=false) const
Retrieves all expression variables used by this model.
Definition Model.cpp:729
storm::expressions::Expression getInitialStatesExpression() const
Retrieves the expression defining the legal initial values of the variables.
Definition Model.cpp:1312
bool hasStandardComposition() const
Retrieves whether this model has the standard composition, that is it composes all automata in parall...
Definition Model.cpp:1463
static const uint64_t SILENT_ACTION_INDEX
The index of the silent action.
Definition Model.h:642
std::vector< Automaton > & getAutomata()
Retrieves the automata of the model.
Definition Model.cpp:872
ModelType const & getModelType() const
Retrieves the type of the model.
Definition Model.cpp:121
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:793
std::vector< Constant > const & getConstants() const
Retrieves the constants of the model.
Definition Model.cpp:689
std::vector< Action > const & getActions() const
Retrieves the actions of the model.
Definition Model.cpp:646
bool undefinedConstantsAreGraphPreserving() const
Checks that undefined constants (parameters) of the model preserve the graph of the underlying model.
Definition Model.cpp:1486
void pushEdgeAssignmentsToDestinations()
Definition Model.cpp:1539
Model substituteConstants() const
Substitutes all constants in all expressions of the model.
Definition Model.cpp:1144
std::size_t getTotalNumberOfNonTransientVariables() const
Number of global and local variables.
Definition Model.cpp:705
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:1420
void addConstant(Constant const &constant)
Adds the given constant to the model.
Definition Model.cpp:654
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:1171
uint64_t getJaniVersion() const
Retrieves the JANI-version of the model.
Definition Model.cpp:117
void substituteFunctions()
Substitutes all function calls with the corresponding function definition.
Definition Model.cpp:1210
Model(Model &&other)
void setStandardSystemComposition()
Sets the system composition to be the fully-synchronizing parallel composition of all automat.
Definition Model.cpp:1022
Variable const & addVariable(Variable const &variable)
Adds the given variable to this model.
Definition Model.cpp:717
Action const & getAction(uint64_t index) const
Retrieves the action with the given index.
Definition Model.cpp:628
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:841
void checkValid() const
Checks if the model is valid JANI, which should be verified before any further operations are applied...
Definition Model.cpp:1405
std::string const & getName() const
Retrieves the name of the model.
Definition Model.cpp:137
bool hasConstant(std::string const &name) const
Retrieves whether the model has a constant with the given name.
Definition Model.cpp:663
void removeConstant(std::string const &name)
Removes (without checks) a constant from the model.
Definition Model.cpp:667
bool isNonTrivialRewardModelExpression(std::string const &identifier) const
Returns true iff the given identifier corresponds to a non-trivial reward expression i....
Definition Model.cpp:797
bool isDeterministicModel() const
Determines whether this model is a deterministic one in the sense that each state only has one choice...
Definition Model.cpp:1369
bool hasNonGlobalTransientVariable() const
Retrieves whether this model has a non-global transient variable.
Definition Model.cpp:765
void simplifyComposition()
Attempts to simplify the composition.
Definition Model.cpp:985
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:442
void writeDotToStream(std::ostream &outStream=std::cout) const
Definition Model.cpp:1638
FunctionDefinition const & addFunctionDefinition(FunctionDefinition const &functionDefinition)
Adds the given function definition.
Definition Model.cpp:774
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:1046
static const std::string SILENT_ACTION_NAME
The name of the silent action.
Definition Model.h:639
bool containsArrayVariables() const
Returns true if at least one array variable occurs in the model.
Definition Model.cpp:1219
Constant const & getConstant(std::string const &name) const
Retrieves the constant with the given name (if any).
Definition Model.cpp:683
std::unordered_map< std::string, uint64_t > const & getActionToIndexMap() const
Retrieves the mapping from action names to their indices.
Definition Model.cpp:642
uint64_t addAction(Action const &action)
Adds an action to the model.
Definition Model.cpp:617
void makeStandardJaniCompliant()
Definition Model.cpp:1528
std::size_t getNumberOfAutomata() const
Retrieves the number of automata in this model.
Definition Model.cpp:914
bool isDiscreteTimeModel() const
Determines whether this model is a discrete-time model.
Definition Model.cpp:1373
bool hasGlobalVariable(std::string const &name) const
Retrieves whether this model has a global variable with the given name.
Definition Model.cpp:757
ModelFeatures const & getModelFeatures() const
Retrieves the enabled model features.
Definition Model.cpp:129
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:1159
bool hasAutomaton(std::string const &name) const
Rerieves whether there exists an automaton with the given name.
Definition Model.cpp:880
Model restrictEdges(storm::storage::FlatSet< uint_fast64_t > const &automataAndEdgeIndices) const
Creates a new model that only contains the selected edges.
Definition Model.cpp:1597
uint64_t addAutomaton(Automaton const &automaton)
Adds the given automaton to the automata of this model.
Definition Model.cpp:863
Automaton & getAutomaton(std::string const &name)
Retrieves the automaton with the given name.
Definition Model.cpp:888
bool hasNonTrivialInitialStates() const
Retrieves whether there are non-trivial initial states in the model or any of the contained automata.
Definition Model.cpp:1292
void setModelType(ModelType const &)
Changes (only) the type declaration of the model.
Definition Model.cpp:125
bool isLinear() const
Checks the model for linearity.
Definition Model.cpp:1569
void setName(std::string const &newName)
Sets the name of the model.
Definition Model.cpp:141
std::map< uint64_t, std::string > getActionIndexToNameMap() const
Builds a map with action indices mapped to their names.
Definition Model.cpp:1036
uint64_t getActionIndex(std::string const &name) const
Get the index of the action.
Definition Model.cpp:636
bool usesAssignmentLevels(bool onlyTransient=false) const
Retrieves whether the model uses an assignment level other than zero.
Definition Model.cpp:1560
void finalize()
After adding all components to the model, this method has to be called.
Definition Model.cpp:1399
std::set< storm::expressions::Variable > getAllLocationExpressionVariables() const
Retrieves all location expression variables used by this model.
Definition Model.cpp:749
bool hasStandardCompliantComposition() const
Checks whether the composition has no nesting.
Definition Model.cpp:1477
uint64_t getAutomatonIndex(std::string const &name) const
Retrieves the index of the given automaton.
Definition Model.cpp:908
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:1243
bool hasTrivialInitialStatesExpression() const
Retrieves whether the initial states expression is trivial in the sense that no automaton has an init...
Definition Model.cpp:1320
Model & operator=(Model const &other)
Copy-assigns the given model.
Definition Model.cpp:73
std::unordered_map< std::string, FunctionDefinition > const & getGlobalFunctionDefinitions() const
Retrieves all global function definitions.
Definition Model.cpp:781
ArrayEliminatorData eliminateArrays(bool keepNonTrivialArrayAccess=false)
Eliminates occurring array variables and expressions by replacing array variables by multiple basic v...
Definition Model.cpp:1231
Model substituteConstantsFunctionsTranscendentals() const
Definition Model.cpp:1151
std::vector< std::reference_wrapper< Constant const > > getUndefinedConstants() const
Retrieves all undefined constants of the model.
Definition Model.cpp:1092
static std::pair< uint64_t, uint64_t > decodeAutomatonAndEdgeIndices(uint64_t index)
Definition Model.cpp:1593
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
LabParser.cpp.
Definition cli.cpp:18