Storm 1.14.0.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, ExplicitModelParserOptions const& options) {
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, options))));
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, options))));
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, options))));
48 break;
49 }
51 model = std::shared_ptr<storm::models::sparse::Model<ValueType, storm::models::sparse::StandardRewardModel<RewardValueType>>>(
54 transitionsFilename, labelingFilename, stateRewardFilename, transitionRewardFilename, choiceLabelingFilename, options))));
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>
65storm::models::ModelType AutoParser<ValueType, RewardValueType>::analyzeHint(std::string const& filename) {
67
68 // Open the file.
69 MappedFile file(filename.c_str());
70
71 STORM_LOG_THROW(file.getDataSize() >= hintLength, storm::exceptions::WrongFormatException, "File too short to be readable.");
72 char const* fileData = file.getData();
73
74 char filehintBuffer[hintLength + 1];
75 memcpy(filehintBuffer, fileData, hintLength);
76 filehintBuffer[hintLength] = 0;
77
78 // Find and read in the hint.
79 char hint[hintLength + 1] = {};
80 static_assert(hintLength == 10, "sscanf format width must match the hint length");
81 constexpr const char* hintFormat = "%10s";
82 sscanf(filehintBuffer, hintFormat, 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
101 return hintType;
102}
103
104// Explicitly instantiate the parser.
105template class AutoParser<double, double>;
106
108
109} // namespace parser
110} // namespace storm
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:24
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="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Checks the given files and parses the model within these files.
static storm::models::sparse::Dtmc< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseDtmc(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parse a Dtmc.
static storm::models::sparse::Ctmc< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseCtmc(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parse a Ctmc.
Opens a file and maps it to memory providing a char* containing the file content.
Definition MappedFile.h:21
static storm::models::sparse::MarkovAutomaton< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseMarkovAutomaton(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parses the given Markov automaton and returns an object representing the automaton.
static storm::models::sparse::Mdp< ValueType, storm::models::sparse::StandardRewardModel< RewardValueType > > parseMdp(std::string const &transitionsFilename, std::string const &labelingFilename, std::string const &stateRewardFilename="", std::string const &transitionRewardFilename="", std::string const &choiceLabelingFilename="", ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parse a Mdp.
#define STORM_LOG_WARN(message)
Definition logging.h:28
#define STORM_LOG_THROW(cond, exception, message)
Definition macros.h:28
Contains all file parsers and helper classes.