317 lines
11 KiB

  1. #pragma once
  2. #include <memory>
  3. #include "src/storage/jani/Action.h"
  4. #include "src/storage/jani/ModelType.h"
  5. #include "src/storage/jani/Automaton.h"
  6. #include "src/storage/jani/Constant.h"
  7. #include "src/storage/jani/Composition.h"
  8. namespace storm {
  9. namespace expressions {
  10. class ExpressionManager;
  11. }
  12. namespace jani {
  13. class Exporter;
  14. class Model {
  15. public:
  16. friend class Exporter;
  17. /*!
  18. * Creates an uninitialized model.
  19. */
  20. Model();
  21. /*!
  22. * Creates an empty model with the given type.
  23. */
  24. Model(std::string const& name, ModelType const& modelType, uint64_t version = 1, boost::optional<std::shared_ptr<storm::expressions::ExpressionManager>> const& expressionManager = boost::none);
  25. /*!
  26. * Retrieves the JANI-version of the model.
  27. */
  28. uint64_t getJaniVersion() const;
  29. /*!
  30. * Retrieves the type of the model.
  31. */
  32. ModelType const& getModelType() const;
  33. /*!
  34. * Retrievest the name of the model.
  35. */
  36. std::string const& getName() const;
  37. /**
  38. * Checks whether the model has an action with the given name.
  39. *
  40. * @param name The name to look for.
  41. */
  42. bool hasAction(std::string const& name) const;
  43. /**
  44. * Get the index of the action
  45. * @param the name of the model
  46. * @return the index of the (unique) action with the given name, undefined if no such action is present.
  47. */
  48. uint64_t getActionIndex(std::string const& name) const;
  49. /**
  50. * Adds an action to the model.
  51. *
  52. * @return the index for this action.
  53. */
  54. uint64_t addAction(Action const& action);
  55. /*!
  56. * Retrieves the action with the given index.
  57. */
  58. Action const& getAction(uint64_t index) const;
  59. /*!
  60. * Retrieves the actions of the model.
  61. */
  62. std::vector<Action> const& getActions() const;
  63. /*!
  64. * Adds the given constant to the model.
  65. */
  66. uint64_t addConstant(Constant const& constant);
  67. /*!
  68. * Retrieves whether the model has a constant with the given name.
  69. */
  70. bool hasConstant(std::string const& name) const;
  71. /*!
  72. * Retrieves the constants of the model.
  73. */
  74. std::vector<Constant> const& getConstants() const;
  75. /*!
  76. * Retrieves the constants of the model.
  77. */
  78. std::vector<Constant>& getConstants();
  79. /*!
  80. * Retrieves the constant with the given name (if any).
  81. */
  82. Constant const& getConstant(std::string const& name) const;
  83. /*!
  84. * Adds the given boolean variable to this model.
  85. */
  86. void addBooleanVariable(BooleanVariable const& variable);
  87. /*!
  88. * Adds the given bounded integer variable to this model.
  89. */
  90. void addBoundedIntegerVariable(BoundedIntegerVariable const& variable);
  91. /*!
  92. * Adds the given unbounded integer variable to this model.
  93. */
  94. void addUnboundedIntegerVariable(UnboundedIntegerVariable const& variable);
  95. /*!
  96. * Retrieves the variables of this automaton.
  97. */
  98. VariableSet& getGlobalVariables();
  99. /*!
  100. * Retrieves the variables of this automaton.
  101. */
  102. VariableSet const& getGlobalVariables() const;
  103. /*!
  104. * Retrieves the manager responsible for the expressions in the JANI model.
  105. */
  106. storm::expressions::ExpressionManager& getExpressionManager();
  107. /*!
  108. * Retrieves the manager responsible for the expressions in the JANI model.
  109. */
  110. storm::expressions::ExpressionManager const& getExpressionManager() const;
  111. /*!
  112. * Adds the given automaton to the automata of this model.
  113. */
  114. uint64_t addAutomaton(Automaton const& automaton);
  115. /*!
  116. * Retrieves the automata of the model.
  117. */
  118. std::vector<Automaton>& getAutomata();
  119. /*!
  120. * Retrieves the automata of the model.
  121. */
  122. std::vector<Automaton> const& getAutomata() const;
  123. /*!
  124. * Retrieves the automaton with the given name.
  125. */
  126. Automaton& getAutomaton(std::string const& name);
  127. /*!
  128. * Retrieves the automaton with the given name.
  129. */
  130. Automaton const& getAutomaton(std::string const& name) const;
  131. /*!
  132. * Retrieves the number of automata in this model.
  133. */
  134. std::size_t getNumberOfAutomata() const;
  135. /*!
  136. * Sets the system composition expression of the JANI model.
  137. */
  138. void setSystemComposition(std::shared_ptr<Composition> const& composition);
  139. /*!
  140. * Gets the system composition as the standard, fully-synchronizing parallel composition.
  141. */
  142. std::shared_ptr<Composition> getStandardSystemComposition() const;
  143. /*!
  144. * Retrieves the system composition expression.
  145. */
  146. Composition const& getSystemComposition() const;
  147. /*!
  148. * Retrieves the set of action names.
  149. */
  150. std::set<std::string> getActionNames(bool includeSilent = true) const;
  151. /*!
  152. * Retrieves the name of the silent action.
  153. */
  154. std::string const& getSilentActionName() const;
  155. /*!
  156. * Retrieves the index of the silent action.
  157. */
  158. uint64_t getSilentActionIndex() const;
  159. /*!
  160. * Defines the undefined constants of the model by the given expressions. The original model is not modified,
  161. * but instead a new model is created.
  162. */
  163. Model defineUndefinedConstants(std::map<storm::expressions::Variable, storm::expressions::Expression> const& constantDefinitions) const;
  164. /*!
  165. * Retrieves whether the model still has undefined constants.
  166. */
  167. bool hasUndefinedConstants() const;
  168. /*!
  169. * Retrieves all undefined constants of the model.
  170. */
  171. std::vector<std::reference_wrapper<Constant const>> getUndefinedConstants() const;
  172. /*!
  173. * Substitutes all constants in all expressions of the model. The original model is not modified, but
  174. * instead a new model is created.
  175. */
  176. Model substituteConstants() const;
  177. /*!
  178. * Retrieves a mapping from expression variables associated with defined constants of the model to their
  179. * (the constants') defining expression.
  180. */
  181. std::map<storm::expressions::Variable, storm::expressions::Expression> getConstantsSubstitution() const;
  182. /*!
  183. * Retrieves whether there is an expression defining the legal initial values of the global variables.
  184. */
  185. bool hasInitialStatesExpression() const;
  186. /*!
  187. * Retrieves the expression defining the legal initial values of the variables.
  188. *
  189. * @param includeAutomataInitialStatesExpressions If set to true, the expression defines the legal initial
  190. * states not only for the global variables but also for the variables of each automaton.
  191. */
  192. storm::expressions::Expression getInitialStatesExpression(bool includeAutomataInitialStatesExpressions = false) const;
  193. /*!
  194. * Sets the expression defining the legal initial values of the global variables.
  195. */
  196. void setInitialStatesExpression(storm::expressions::Expression const& initialStatesExpression);
  197. /*!
  198. * Determines whether this model is a deterministic one in the sense that each state only has one choice.
  199. */
  200. bool isDeterministicModel() const;
  201. /*!
  202. * Determines whether this model is a discrete-time model.
  203. */
  204. bool isDiscreteTimeModel() const;
  205. /*!
  206. * Retrieves a list of expressions that characterize the legal values of the variables in this model.
  207. */
  208. std::vector<storm::expressions::Expression> getAllRangeExpressions() const;
  209. /*!
  210. * Retrieves whether this model has the default composition, that is it composes all automata in parallel
  211. * and synchronizes over all common actions.
  212. */
  213. bool hasDefaultComposition() const;
  214. /*!
  215. * Checks if the model is valid JANI, which should be verified before any further operations are applied to a model.
  216. */
  217. bool checkValidity(bool logdbg = true) const;
  218. private:
  219. /// The model name.
  220. std::string name;
  221. /// The type of the model.
  222. ModelType modelType;
  223. /// The JANI-version used to specify the model.
  224. uint64_t version;
  225. /// The manager responsible for the expressions in this model.
  226. std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
  227. /// The list of actions.
  228. std::vector<Action> actions;
  229. /// A mapping from names to action indices.
  230. std::unordered_map<std::string, uint64_t> actionToIndex;
  231. /// The index of the silent action.
  232. uint64_t silentActionIndex;
  233. /// The constants defined by the model.
  234. std::vector<Constant> constants;
  235. /// A mapping from names to constants.
  236. std::unordered_map<std::string, uint64_t> constantToIndex;
  237. /// The global variables of the model.
  238. VariableSet globalVariables;
  239. /// The list of automata.
  240. std::vector<Automaton> automata;
  241. /// A mapping from names to automata indices.
  242. std::unordered_map<std::string, size_t> automatonToIndex;
  243. /// An expression describing how the system is composed of the automata.
  244. std::shared_ptr<Composition> composition;
  245. // The expression characterizing the legal initial values of the global variables.
  246. storm::expressions::Expression initialStatesExpression;
  247. };
  248. }
  249. }