You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
6.8 KiB

  1. #ifndef STORM_PARSER_DETERMINISTICMODELPARSER_H_
  2. #define STORM_PARSER_DETERMINISTICMODELPARSER_H_
  3. #include "src/models/sparse/Dtmc.h"
  4. #include "src/models/sparse/Ctmc.h"
  5. namespace storm {
  6. namespace parser {
  7. /*!
  8. * Loads a deterministic model (Dtmc or Ctmc) from files.
  9. *
  10. * Given the file paths of the files holding the transitions, the atomic propositions and optionally the state- and transition rewards
  11. * it loads the files, parses them and returns the desired model.
  12. */
  13. template<typename ValueType = double, typename RewardValueType = double>
  14. class DeterministicModelParser {
  15. public:
  16. /*!
  17. * A structure containing the parsed components of a deterministic model.
  18. */
  19. struct Result {
  20. /*!
  21. * The copy constructor.
  22. *
  23. * @param transitionSystem The transition system to be contained in the Result.
  24. * @param labeling The the labeling of the transition system to be contained in the Result.
  25. */
  26. Result(storm::storage::SparseMatrix<ValueType>& transitionSystem, storm::models::sparse::StateLabeling& labeling) : transitionSystem(transitionSystem), labeling(labeling) {
  27. // Intentionally left empty.
  28. }
  29. /*!
  30. * The move constructor.
  31. *
  32. * @param transitionSystem The transition system to be contained in the Result.
  33. * @param labeling The the labeling of the transition system to be contained in the Result.
  34. */
  35. Result(storm::storage::SparseMatrix<ValueType>&& transitionSystem, storm::models::sparse::StateLabeling&& labeling) : transitionSystem(std::move(transitionSystem)), labeling(std::move(labeling)) {
  36. // Intentionally left empty.
  37. }
  38. //! A matrix representing the transitions of the model
  39. storm::storage::SparseMatrix<ValueType> transitionSystem;
  40. //! The labels of each state.
  41. storm::models::sparse::StateLabeling labeling;
  42. //! Optional rewards for each state.
  43. boost::optional<std::vector<RewardValueType>> stateRewards;
  44. //! Optional rewards for each transition.
  45. boost::optional<storm::storage::SparseMatrix<RewardValueType>> transitionRewards;
  46. };
  47. /*!
  48. * Parse a Dtmc.
  49. *
  50. * This method is an adapter to the actual parsing function.
  51. * I.e. it uses @parseDeterministicModel internally to parse the given input files, takes its result and compiles it into a Dtmc.
  52. *
  53. * @note The number of states of the model is determined by the transitions file.
  54. * The labeling file may therefore not contain labels of states that are not contained in the transitions file.
  55. *
  56. * @param transitionsFilename The path and name of the file containing the transitions of the model.
  57. * @param labelingFilename The path and name of the file containing the labels for the states of the model.
  58. * @param stateRewardFilename The path and name of the file containing the state reward of the model. This file is optional.
  59. * @param transitionRewardFilename The path and name of the file containing the transition rewards of the model. This file is optional.
  60. * @return The parsed Dtmc.
  61. */
  62. static storm::models::sparse::Dtmc<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>> parseDtmc(std::string const& transitionsFilename,
  63. std::string const & labelingFilename,
  64. std::string const & stateRewardFilename = "",
  65. std::string const & transitionRewardFilename = "");
  66. /*!
  67. * Parse a Ctmc.
  68. *
  69. * This method is an adapter to the actual parsing function.
  70. * I.e. it uses @parseDeterministicModel internally to parse the given input files, takes its result and compiles it into a Ctmc.
  71. *
  72. * @note The number of states of the model is determined by the transitions file.
  73. * The labeling file may therefore not contain labels of states that are not contained in the transitions file.
  74. *
  75. * @param transitionsFilename The path and name of the file containing the transitions of the model.
  76. * @param labelingFilename The path and name of the file containing the labels for the states of the model.
  77. * @param stateRewardFilename The path and name of the file containing the state reward of the model. This file is optional.
  78. * @param transitionRewardFilename The path and name of the file containing the transition rewards of the model. This file is optional.
  79. * @return The parsed Ctmc.
  80. */
  81. static storm::models::sparse::Ctmc<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>> parseCtmc(std::string const& transitionsFilename,
  82. std::string const & labelingFilename,
  83. std::string const & stateRewardFilename = "",
  84. std::string const & transitionRewardFilename = "");
  85. private:
  86. /*!
  87. * Parses a deterministic model from the given files.
  88. * Calls sub-parsers on the given files and fills the container with the results.
  89. *
  90. * @note The number of states of the model is determined by the transitions file.
  91. * The labeling file may therefore not contain labels of states that are not contained in the transitions file.
  92. *
  93. * @param transitionsFilename The path and name of the file containing the transitions of the model.
  94. * @param labelingFilename The path and name of the file containing the labels for the states of the model.
  95. * @param stateRewardFilename The path and name of the file containing the state reward of the model. This file is optional.
  96. * @param transitionRewardFilename The path and name of the file containing the transition rewards of the model. This file is optional.
  97. * @return The parsed model encapsulated in a Result structure.
  98. */
  99. static Result parseDeterministicModel(std::string const& transitionsFilename,
  100. std::string const& labelingFilename,
  101. std::string const& stateRewardFilename = "",
  102. std::string const& transitionRewardFilename = "");
  103. };
  104. } /* namespace parser */
  105. } /* namespace storm */
  106. #endif /* STORM_PARSER_DETERMINISTICMODELPARSER_H_ */