Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AutoParser.cpp
Go to the documentation of this file.
2
4
6
12
14
17
18namespace storm {
19namespace parser {
20
21using namespace storm::utility::cstring;
22
23template<typename ValueType, typename RewardValueType>
24std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>
25AutoParser<ValueType, RewardValueType>::parseModel(std::string const& transitionsFilename, std::string const& labelingFilename,
26 std::string const& stateRewardFilename, std::string const& transitionRewardFilename,
27 std::string const& choiceLabelingFilename) {
28 // Find and parse the model type hint.
29 storm::models::ModelType type = AutoParser::analyzeHint(transitionsFilename);
30
31 // Do the actual parsing.
32 std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>> model;
33 switch (type) {
35 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
37 std::move(DeterministicModelParser<ValueType, RewardValueType>::parseDtmc(transitionsFilename, labelingFilename, stateRewardFilename,
38 transitionRewardFilename, choiceLabelingFilename))));
39 break;
40 }
42 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
44 std::move(DeterministicModelParser<ValueType, RewardValueType>::parseCtmc(transitionsFilename, labelingFilename, stateRewardFilename,
45 transitionRewardFilename, choiceLabelingFilename))));
46 break;
47 }
49 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
51 std::move(NondeterministicModelParser<ValueType, RewardValueType>::parseMdp(transitionsFilename, labelingFilename, stateRewardFilename,
52 transitionRewardFilename, choiceLabelingFilename))));
53 break;
54 }
56 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
59 transitionsFilename, labelingFilename, stateRewardFilename, transitionRewardFilename, choiceLabelingFilename))));
60 break;
61 }
62 default:
63 STORM_LOG_WARN("Unknown/Unhandled Model Type which cannot be parsed."); // Unknown
64 }
65
66 return model;
67}
68
69template<typename ValueType, typename RewardValueType>
72
73 // Open the file.
74 MappedFile file(filename.c_str());
75
76 STORM_LOG_THROW(file.getDataSize() >= STORM_PARSER_AUTOPARSER_HINT_LENGTH, storm::exceptions::WrongFormatException, "File too short to be readable.");
77 char const* fileData = file.getData();
78
79 char filehintBuffer[STORM_PARSER_AUTOPARSER_HINT_LENGTH + 1];
80 memcpy(filehintBuffer, fileData, STORM_PARSER_AUTOPARSER_HINT_LENGTH);
81 filehintBuffer[STORM_PARSER_AUTOPARSER_HINT_LENGTH] = 0;
82
83 // Find and read in the hint.
84 std::string formatString = "%" + std::to_string(STORM_PARSER_AUTOPARSER_HINT_LENGTH) + "s";
86#ifdef WINDOWS
87 sscanf_s(filehintBuffer, formatString.c_str(), hint, STORM_PARSER_AUTOPARSER_HINT_LENGTH + 1);
88#else
89 sscanf(filehintBuffer, formatString.c_str(), hint);
90#endif
91 for (char* c = hint; *c != '\0'; c++) *c = toupper(*c);
92
93 // Check if the hint value is known and store the appropriate enum value.
94 if (strcmp(hint, "DTMC") == 0)
96 else if (strcmp(hint, "CTMC") == 0)
98 else if (strcmp(hint, "MDP") == 0)
100 else if (strcmp(hint, "MA") == 0)
102 else
103 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Unable to find model hint in explicit input.");
104
105 return hintType;
106}
107
108// Explicitly instantiate the parser.
109template class AutoParser<double, double>;
110
111#ifdef STORM_HAVE_CARL
112template class AutoParser<double, storm::Interval>;
113#endif
114
115} // namespace parser
116} // namespace storm
#define STORM_PARSER_AUTOPARSER_HINT_LENGTH
Definition AutoParser.h:8
This class represents a continuous-time Markov chain.
Definition Ctmc.h:15
This class represents a discrete-time Markov chain.
Definition Dtmc.h:14
This class represents a Markov automaton.
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:14
This class automatically chooses the correct parser for the given files and returns the corresponding...
Definition AutoParser.h:26
static std::shared_ptr< storm::models::sparse::Model< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > > parseModel(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="")
Checks the given files and parses the model within these files.
Loads a deterministic model (Dtmc or Ctmc) from files.
Opens a file and maps it to memory providing a char* containing the file content.
Definition MappedFile.h:33
Loads a labeled Markov automaton from files.
Loads a nondeterministic model (Mdp or Ctmdp) from files.
#define STORM_LOG_WARN(message)
Definition logging.h:30
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30
LabParser.cpp.
Definition cli.cpp:18