13using namespace storm::utility::cstring;
15template<
typename ValueType>
20 bool fixDeadlocks = options.fixDeadlocks;
24 if (buf[0] <
'0' || buf[0] >
'9') {
30 uint_fast64_t source, target = 0;
31 uint_fast64_t lastsource = 0;
32 bool encounteredEOF =
false;
33 bool stateHasMarkovianChoice =
false;
34 bool stateHasProbabilisticChoice =
false;
35 while (buf[0] !=
'\0' && !encounteredEOF) {
40 if (source > result.highestStateIndex) {
41 result.highestStateIndex = source;
45 if (source > lastsource + 1) {
47 result.numberOfNonzeroEntries += source - lastsource - 1;
48 result.numberOfChoices += source - lastsource - 1;
51 "Found deadlock states (e.g. " << lastsource + 1 <<
") during parsing. Please fix them or set the appropriate flag.");
53 }
else if (source < lastsource) {
55 "Illegal state choice order. A choice of state " << source <<
" appears at an illegal position.");
58 ++result.numberOfChoices;
61 if (source != lastsource) {
62 stateHasMarkovianChoice =
false;
63 stateHasProbabilisticChoice =
false;
72 bool isMarkovianChoice =
false;
73 if (buf[0] ==
'!' &&
skipWord(buf) - buf == 1) {
74 isMarkovianChoice =
true;
76 isMarkovianChoice =
false;
80 if (isMarkovianChoice) {
81 STORM_LOG_THROW(!stateHasMarkovianChoice, storm::exceptions::WrongFormatException,
"The state " << source <<
" has multiple Markovian choices.");
82 if (stateHasProbabilisticChoice) {
84 false, storm::exceptions::WrongFormatException,
85 "The state " << source
86 <<
" has a probabilistic choice preceding a Markovian choice. The Markovian choice must be the first choice listed.");
88 stateHasMarkovianChoice =
true;
90 stateHasProbabilisticChoice =
true;
98 bool hasSuccessorState =
false;
99 bool encounteredNewDistribution =
false;
100 uint_fast64_t lastSuccessorState = 0;
106 if (buf[0] ==
'\0') {
107 if (!hasSuccessorState) {
109 "Premature end-of-file. Expected at least one successor state for state " << source <<
".");
112 encounteredEOF =
true;
114 }
else if (buf[0] ==
'*') {
120 if (target > result.highestStateIndex) {
121 result.highestStateIndex = target;
123 STORM_LOG_THROW(!hasSuccessorState || target > lastSuccessorState, storm::exceptions::WrongFormatException,
124 "Illegal transition order for source state " << source <<
".");
129 "Illegal negative probability/rate value for transition from " << source <<
" to " << target <<
": " << val <<
".");
130 STORM_LOG_THROW(isMarkovianChoice || val <= 1.0, storm::exceptions::WrongFormatException,
131 "Illegal probability value for transition from " << source <<
" to " << target <<
": " << val <<
".");
134 hasSuccessorState =
true;
135 lastSuccessorState = target;
138 ++result.numberOfNonzeroEntries;
144 encounteredNewDistribution =
true;
146 }
while (!encounteredEOF && !encounteredNewDistribution);
152 result.numberOfNonzeroEntries += result.highestStateIndex - lastsource;
153 result.numberOfChoices += result.highestStateIndex - lastsource;
156 "Found deadlock states (e.g. " << lastsource + 1 <<
") during parsing. Please fix them or set the appropriate flag.");
162template<
typename ValueType>
165 Result result(firstPassResult);
167 bool fixDeadlocks = options.fixDeadlocks;
171 if (buf[0] <
'0' || buf[0] >
'9') {
177 uint_fast64_t source, target = 0;
178 uint_fast64_t lastsource = 0;
179 bool encounteredEOF =
false;
180 uint_fast64_t currentChoice = 0;
183 result.transitionMatrixBuilder.newRowGroup(0);
185 while (buf[0] !=
'\0' && !encounteredEOF) {
190 if (source > lastsource + 1) {
192 for (uint_fast64_t index = lastsource + 1; index < source; ++index) {
193 result.transitionMatrixBuilder.newRowGroup(currentChoice);
194 result.transitionMatrixBuilder.addNextValue(currentChoice, index, 1);
199 "Found deadlock states (e.g. " << lastsource + 1 <<
") during parsing. Please fix them or set the appropriate flag.");
203 if (source != lastsource) {
205 result.transitionMatrixBuilder.newRowGroup(currentChoice);
214 bool isMarkovianChoice =
false;
215 if (buf[0] ==
'!' &&
skipWord(buf) - buf == 1) {
216 isMarkovianChoice =
true;
219 result.markovianStates.set(source,
true);
221 isMarkovianChoice =
false;
229 bool encounteredNewDistribution =
false;
236 if (buf[0] ==
'\0') {
239 encounteredEOF =
true;
240 }
else if (buf[0] ==
'*') {
251 result.transitionMatrixBuilder.addNextValue(currentChoice, target, val);
252 if (isMarkovianChoice) {
253 result.exitRates[source] += val;
260 encounteredNewDistribution =
true;
262 }
while (!encounteredEOF && !encounteredNewDistribution);
270 for (uint_fast64_t index = lastsource + 1; index <= firstPassResult.highestStateIndex; ++index) {
271 result.markovianStates.set(index,
true);
273 result.transitionMatrixBuilder.newRowGroup(currentChoice);
279 "Found deadlock states (e.g. " << lastsource + 1 <<
") during parsing. Please fix them or set the appropriate flag.");
285template<
typename ValueType>
289 setlocale(LC_NUMERIC,
"C");
293 char const* buf = file.
getData();
295 return secondPass(buf, firstPass(buf, options), options);
Opens a file and maps it to memory providing a char* containing the file content.
char const * getData() const
Returns a pointer to the beginning of the mapped file data.
A class providing the functionality to parse the transitions of a Markov automaton.
static Result parseMarkovAutomatonTransitions(std::string const &filename, ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Parses the given file under the assumption that it contains a Markov automaton specified in the appro...
#define STORM_LOG_THROW(cond, exception, message)
Contains all file parsers and helper classes.
char const * forwardToLineEnd(char const *buffer)
Encapsulates the usage of function @strcspn to forward to the end of the line (next char is the newli...
char const * skipWord(char const *buf)
Skips all numbers, letters and special characters.
double checked_strtod(char const *str, char const **end)
Calls strtod() internally and checks if the new pointer is different from the original one,...
uint_fast64_t checked_strtol(char const *str, char const **end)
Calls strtol() internally and checks if the new pointer is different from the original one,...
char const * forwardToNextLine(char const *buffer)
Encapsulates the usage of function @strchr to forward to the next line.
char const * trimWhitespaces(char const *buf)
Skips spaces, tabs, newlines and carriage returns.
A structure representing the result of the first pass of this parser.
A structure representing the result of the parser.