Storm 1.11.1.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
AutoParser.cpp
Go to the documentation of this file.
2
12
13namespace storm {
14namespace parser {
15
16using namespace storm::utility::cstring;
17
18template<typename ValueType, typename RewardValueType>
19std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>
20AutoParser<ValueType, RewardValueType>::parseModel(std::string const& transitionsFilename, std::string const& labelingFilename,
21 std::string const& stateRewardFilename, std::string const& transitionRewardFilename,
22 std::string const& choiceLabelingFilename) {
23 // Find and parse the model type hint.
24 storm::models::ModelType type = AutoParser::analyzeHint(transitionsFilename);
25
26 // Do the actual parsing.
27 std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>> model;
28 switch (type) {
30 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
32 std::move(DeterministicModelParser<ValueType, RewardValueType>::parseDtmc(transitionsFilename, labelingFilename, stateRewardFilename,
33 transitionRewardFilename, choiceLabelingFilename))));
34 break;
35 }
37 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
39 std::move(DeterministicModelParser<ValueType, RewardValueType>::parseCtmc(transitionsFilename, labelingFilename, stateRewardFilename,
40 transitionRewardFilename, choiceLabelingFilename))));
41 break;
42 }
44 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
46 std::move(NondeterministicModelParser<ValueType, RewardValueType>::parseMdp(transitionsFilename, labelingFilename, stateRewardFilename,
47 transitionRewardFilename, choiceLabelingFilename))));
48 break;
49 }
51 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
54 transitionsFilename, labelingFilename, stateRewardFilename, transitionRewardFilename, choiceLabelingFilename))));
55 break;
56 }
57 default:
58 STORM_LOG_WARN("Unknown/Unhandled Model Type which cannot be parsed."); // Unknown
59 }
60
61 return model;
62}
63
64template<typename ValueType, typename RewardValueType>
67
68 // Open the file.
69 MappedFile file(filename.c_str());
70
71 STORM_LOG_THROW(file.getDataSize() >= STORM_PARSER_AUTOPARSER_HINT_LENGTH, storm::exceptions::WrongFormatException, "File too short to be readable.");
72 char const* fileData = file.getData();
73
74 char filehintBuffer[STORM_PARSER_AUTOPARSER_HINT_LENGTH + 1];
75 memcpy(filehintBuffer, fileData, STORM_PARSER_AUTOPARSER_HINT_LENGTH);
76 filehintBuffer[STORM_PARSER_AUTOPARSER_HINT_LENGTH] = 0;
77
78 // Find and read in the hint.
79 std::string formatString = "%" + std::to_string(STORM_PARSER_AUTOPARSER_HINT_LENGTH) + "s";
81
82 sscanf(filehintBuffer, formatString.c_str(), hint);
83
84 for (char* c = hint; *c != '\0'; c++) {
85 *c = toupper(*c);
86 }
87
88 // Check if the hint value is known and store the appropriate enum value.
89 if (strcmp(hint, "DTMC") == 0)
91 else if (strcmp(hint, "CTMC") == 0)
93 else if (strcmp(hint, "MDP") == 0)
95 else if (strcmp(hint, "MA") == 0)
97 else
98 STORM_LOG_THROW(false, storm::exceptions::WrongFormatException, "Unable to find model hint in explicit input.");
99
100 return hintType;
101}
102
103// Explicitly instantiate the parser.
104template class AutoParser<double, double>;
105
106template class AutoParser<double, storm::Interval>;
107
108} // namespace parser
109} // namespace storm
#define STORM_PARSER_AUTOPARSER_HINT_LENGTH
Definition AutoParser.h:8
This class represents a continuous-time Markov chain.
Definition Ctmc.h:13
This class represents a discrete-time Markov chain.
Definition Dtmc.h:13
This class represents a Markov automaton.
This class represents a (discrete-time) Markov decision process.
Definition Mdp.h:13
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:21
Loads a labeled Markov automaton from files.
Loads a nondeterministic model (Mdp or Ctmdp) from files.
#define STORM_LOG_WARN(message)
Definition logging.h:25
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:30