20template<
typename ValueType>
23 return NondeterministicSparseTransitionParser::parse(filename,
false, emptyMatrix);
26template<
typename ValueType>
27template<
typename MatrixValueType>
30 return NondeterministicSparseTransitionParser::parse(filename,
true, modelInformation);
33template<
typename ValueType>
34template<
typename MatrixValueType>
38 setlocale(LC_NUMERIC,
"C");
42 char const* buf = file.getData();
46 NondeterministicSparseTransitionParser::firstPass(file.getData(), isRewardFile, modelInformation);
50 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": erroneous file format.");
51 throw storm::exceptions::WrongFormatException() <<
"Error while parsing " << filename <<
": erroneous file format.";
58 if (buf[0] <
'0' || buf[0] >
'9') {
67 throw storm::exceptions::OutOfRangeException() <<
"Reward matrix size exceeds transition matrix size.";
69 STORM_LOG_ERROR(
"Reward matrix row count does not match transition matrix row count.");
70 throw storm::exceptions::OutOfRangeException() <<
"Reward matrix row count does not match transition matrix row count.";
72 STORM_LOG_ERROR(
"The reward matrix has more entries than the transition matrix. There must be a reward for a non existent transition");
73 throw storm::exceptions::OutOfRangeException() <<
"The reward matrix has more entries than the transition matrix.";
94 uint_fast64_t source = 0, target = 0, lastSource = 0, choice = 0, lastChoice = 0, curRow = 0;
96 bool dontFixDeadlocks = storm::settings::getModule<storm::settings::modules::BuildSettings>().isDontFixDeadlocksSet();
97 bool hadDeadlocks =
false;
103 while (buf[0] !=
'\0') {
111 if (source != lastSource) {
117 for (uint_fast64_t i = lastSource + 1;
i < source; ++
i) {
123 if (source != lastSource) {
129 if (source != lastSource) {
130 curRow += choice + 1;
131 }
else if (choice != lastChoice) {
132 curRow += choice - lastChoice;
137 if ((source != lastSource || choice != lastChoice)) {
144 for (uint_fast64_t node = lastSource + 1; node < source; node++) {
146 if (!dontFixDeadlocks) {
150 STORM_LOG_INFO(
"Warning while parsing " << filename <<
": node " << node <<
" has no outgoing transitions. A self-loop was inserted.");
152 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": node " << node <<
" has no outgoing transitions.");
155 if (source != lastSource) {
175 if (dontFixDeadlocks && hadDeadlocks && !isRewardFile)
176 throw storm::exceptions::WrongFormatException() <<
"Some of the states do not have outgoing transitions.";
180 for (uint_fast64_t node = lastSource + 1; node < modelInformation.
getRowGroupCount(); node++) {
190 if (isRewardFile && !resultMatrix.
isSubmatrixOf(modelInformation)) {
191 STORM_LOG_ERROR(
"There are rewards for non existent transitions given in the reward file.");
192 throw storm::exceptions::WrongFormatException() <<
"There are rewards for non existent transitions given in the reward file.";
198template<
typename ValueType>
199template<
typename MatrixValueType>
200typename NondeterministicSparseTransitionParser<ValueType>::FirstPassResult NondeterministicSparseTransitionParser<ValueType>::firstPass(
206 if (buf[0] <
'0' || buf[0] >
'9') {
212 uint_fast64_t source = 0, target = 0, choice = 0, lastChoice = 0, lastSource = 0, lastTarget = -1;
214 typename NondeterministicSparseTransitionParser<ValueType>::FirstPassResult result;
219 while (buf[0] !=
'\0') {
226 if (source < lastSource) {
227 STORM_LOG_ERROR(
"The current source state " << source <<
" is smaller than the last one " << lastSource <<
".");
228 throw storm::exceptions::InvalidArgumentException()
229 <<
"The current source state " << source <<
" is smaller than the last one " << lastSource <<
".";
233 if (source > result.highestStateIndex) {
234 result.highestStateIndex = source;
239 if (result.highestStateIndex > modelInformation.
getColumnCount() - 1) {
240 STORM_LOG_ERROR(
"State index " << result.highestStateIndex <<
" found. This exceeds the highest state index of the model, which is "
242 throw storm::exceptions::OutOfRangeException()
243 <<
"State index " << result.highestStateIndex <<
" found. This exceeds the highest state index of the model, which is "
249 if (source != lastSource) {
257 for (uint_fast64_t i = lastSource + 1;
i < source; ++
i) {
263 if (source != lastSource) {
264 result.choices += choice + 1;
265 }
else if (choice != lastChoice) {
266 result.choices += choice - lastChoice;
271 if (source > lastSource + 1) {
272 result.numberOfNonzeroEntries += source - lastSource - 1;
273 result.choices += source - lastSource - 1;
276 if (source != lastSource || choice != lastChoice) {
286 if (target > result.highestStateIndex) {
287 result.highestStateIndex = target;
291 if (target == lastTarget && choice == lastChoice && source == lastSource) {
292 STORM_LOG_ERROR(
"The same transition (" << source <<
", " << choice <<
", " << target <<
") is given twice.");
293 throw storm::exceptions::InvalidArgumentException() <<
"The same transition (" << source <<
", " << choice <<
", " << target <<
") is given twice.";
298 if (!isRewardFile && (val < 0.0 || val > 1.0)) {
299 STORM_LOG_ERROR(
"Expected a positive probability but got \"" << std::string(buf, 0, 16) <<
"\".");
300 NondeterministicSparseTransitionParser::FirstPassResult nullResult;
302 }
else if (val < 0.0) {
303 STORM_LOG_ERROR(
"Expected a positive reward value but got \"" << std::string(buf, 0, 16) <<
"\".");
304 NondeterministicSparseTransitionParser::FirstPassResult nullResult;
313 result.numberOfNonzeroEntries++;
328 for (uint_fast64_t i = lastSource + 1;
i < modelInformation.
getRowGroupIndices().size() - 1; ++
i) {
336template class NondeterministicSparseTransitionParser<double>;
342template class NondeterministicSparseTransitionParser<storm::Interval>;
Opens a file and maps it to memory providing a char* containing the file content.
A class providing the functionality to parse the transitions of a nondeterministic model.
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitions(std::string const &filename)
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
static storm::storage::SparseMatrix< ValueType > parseNondeterministicTransitionRewards(std::string const &filename, storm::storage::SparseMatrix< MatrixValueType > const &modelInformation)
Load a nondeterministic transition system from file and create a sparse adjacency matrix whose entrie...
A class that can be used to build a sparse matrix by adding value by value.
void addNextValue(index_type row, index_type column, value_type const &value)
Sets the matrix entry at the given row and column to the given value.
void newRowGroup(index_type startingRow)
Starts a new row group in the matrix.
SparseMatrix< value_type > build(index_type overriddenRowCount=0, index_type overriddenColumnCount=0, index_type overriddenRowGroupCount=0)
A class that holds a possibly non-square matrix in the compressed row storage format.
index_type getEntryCount() const
Returns the number of entries in the matrix.
index_type getRowGroupCount() const
Returns the number of row groups in the matrix.
bool isSubmatrixOf(SparseMatrix< OtherValueType > const &matrix) const
Checks if the current matrix is a submatrix of the given matrix, where a matrix A is called a submatr...
index_type getColumnCount() const
Returns the number of columns of the matrix.
std::vector< index_type > const & getRowGroupIndices() const
Returns the grouping of rows of this matrix.
index_type getRowCount() const
Returns the number of rows of the matrix.
#define STORM_LOG_INFO(message)
#define STORM_LOG_ERROR(message)
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...
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 * trimWhitespaces(char const *buf)
Skips spaces, tabs, newlines and carriage returns.
A structure representing the result of the first pass of this parser.
uint_fast64_t numberOfNonzeroEntries
The total number of non-zero entries of the model.
uint_fast64_t highestStateIndex
The highest state index that appears in the model.
uint_fast64_t choices
The total number of nondeterministic choices within the transition system.