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.

99 lines
5.1 KiB

  1. #ifndef STORM_PARSER_NONDETERMINISTICSPARSETRANSITIONPARSER_H_
  2. #define STORM_PARSER_NONDETERMINISTICSPARSETRANSITIONPARSER_H_
  3. #include "storm/storage/SparseMatrix.h"
  4. #include <vector>
  5. namespace storm {
  6. namespace parser {
  7. /*!
  8. * A class providing the functionality to parse the transitions of a nondeterministic model.
  9. *
  10. * The file is parsed in two passes.
  11. * The first pass tests the file format and collects statistical data needed for the second pass.
  12. * The second pass then collects the actual file data and compiles it into a Result.
  13. */
  14. template<typename ValueType = double>
  15. class NondeterministicSparseTransitionParser {
  16. public:
  17. /*!
  18. * A structure representing the result of the first pass of this parser.
  19. * It contains the number of non-zero entries in the model, the highest state index and the total number if nondeterministic choices.
  20. */
  21. struct FirstPassResult {
  22. /*!
  23. * The default constructor.
  24. * Constructs an empty FirstPassResult.
  25. */
  26. FirstPassResult() : numberOfNonzeroEntries(0), highestStateIndex(0), choices(0) {
  27. // Intentionally left empty.
  28. }
  29. //! The total number of non-zero entries of the model.
  30. uint_fast64_t numberOfNonzeroEntries;
  31. //! The highest state index that appears in the model.
  32. uint_fast64_t highestStateIndex;
  33. //! The total number of nondeterministic choices within the transition system.
  34. uint_fast64_t choices;
  35. };
  36. /*!
  37. * Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entries represent the weights of the edges
  38. *
  39. * @param filename The path and name of file to be parsed.
  40. */
  41. static storm::storage::SparseMatrix<ValueType> parseNondeterministicTransitions(std::string const& filename);
  42. /*!
  43. * Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entries represent the weights of the edges
  44. *
  45. * @param filename The path and name of file to be parsed.
  46. * @param modelInformation The information about the transition structure of nondeterministic model in which the transition rewards shall be used.
  47. * @return A struct containing the parsed file contents, i.e. the transition reward matrix and the mapping between its rows and the states of the model.
  48. */
  49. template<typename MatrixValueType>
  50. static storm::storage::SparseMatrix<ValueType> parseNondeterministicTransitionRewards(std::string const& filename, storm::storage::SparseMatrix<MatrixValueType> const& modelInformation);
  51. private:
  52. /*!
  53. * This method does the first pass through the buffer containing the content of some transition file.
  54. *
  55. * It computes the overall number of nondeterministic choices, i.e. the
  56. * number of rows in the matrix that should be created.
  57. * It also calculates the overall number of non-zero cells, i.e. the number
  58. * of elements the matrix has to hold, and the maximum node id, i.e. the
  59. * number of columns of the matrix.
  60. *
  61. * @param buffer Buffer containing the data to scan. This is expected to be some char array.
  62. * @param insertDiagonalEntriesIfMissing A flag set iff entries on the primary diagonal of the matrix should be added in case they are missing in the parsed file.
  63. * @return A structure representing the result of the first pass.
  64. */
  65. template<typename MatrixValueType>
  66. static FirstPassResult firstPass(char const* buffer, bool isRewardFile, storm::storage::SparseMatrix<MatrixValueType> const& modelInformation);
  67. /*!
  68. * The main parsing routine.
  69. * Opens the given file, calls the first pass and performs the second pass, parsing the content of the file into a SparseMatrix.
  70. *
  71. * @param filename The path and name of file to be parsed.
  72. * @param rewardFile A flag set iff the file to be parsed contains transition rewards.
  73. * @param insertDiagonalEntriesIfMissing A flag set iff entries on the primary diagonal of the matrix should be added in case they are missing in the parsed file.
  74. * @param modelInformation A struct containing information that is used to check if the transition reward matrix fits to the rest of the model.
  75. * @return A SparseMatrix containing the parsed file contents.
  76. */
  77. template<typename MatrixValueType>
  78. static storm::storage::SparseMatrix<ValueType> parse(std::string const& filename, bool isRewardFile, storm::storage::SparseMatrix<MatrixValueType> const& modelInformation);
  79. };
  80. } // namespace parser
  81. } // namespace storm
  82. #endif /* STORM_PARSER_NONDETERMINISTICSPARSETRANSITIONPARSER_H__H_ */