17using namespace storm::utility::cstring;
19template<
typename ValueType>
23 return DeterministicSparseTransitionParser<ValueType>::parse(filename,
false, emptyMatrix, options);
26template<
typename ValueType>
27template<
typename MatrixValueType>
30 return DeterministicSparseTransitionParser<ValueType>::parse(filename,
true, transitionMatrix);
33template<
typename ValueType>
34template<
typename MatrixValueType>
39 setlocale(LC_NUMERIC,
"C");
43 char const* buf = file.getData();
47 DeterministicSparseTransitionParser<ValueType>::firstPass(file.getData(), !isRewardFile);
53 "Error while parsing " << filename <<
": empty or erroneous file format.");
59 if (buf[0] <
'0' || buf[0] >
'9') {
67 STORM_LOG_THROW(
false, storm::exceptions::WrongFormatException,
"Reward matrix has more rows or columns than transition matrix.");
79 uint_fast64_t row, col, lastRow = 0;
82 bool hadDeadlocks =
false;
90 while (buf[0] !=
'\0') {
96 resultMatrix.addNextValue(row, col, val);
105 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
109 STORM_LOG_WARN(
"Warning while parsing " << filename <<
": state " << skippedRow
110 <<
" has no outgoing transitions. A self-loop was inserted.");
112 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
118 while (buf[0] !=
'\0') {
126 if (lastRow != row) {
127 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
131 STORM_LOG_INFO(
"Warning while parsing " << filename <<
": state " << skippedRow
132 <<
" has no outgoing transitions. A self-loop was inserted.");
134 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
141 resultMatrix.addNextValue(row, col, val);
146 STORM_LOG_THROW(fixDeadlocks || !hadDeadlocks, storm::exceptions::WrongFormatException,
"Some of the states do not have outgoing transitions.");
150 storm::storage::SparseMatrix<ValueType> result = resultMatrix.build();
155 "There are rewards for non existent transitions given in the reward file.");
160template<
typename ValueType>
162 char const* buf,
bool reserveDiagonalElements) {
167 if (buf[0] <
'0' || buf[0] >
'9') {
173 uint_fast64_t row, col, lastRow = 0, lastCol = -1;
178 if (row > 0 && reserveDiagonalElements) {
179 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
180 ++result.numberOfNonzeroEntries;
184 while (buf[0] !=
'\0') {
191 if (lastRow != row && reserveDiagonalElements) {
193 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
194 ++result.numberOfNonzeroEntries;
199 if (row > result.highestStateIndex) {
200 result.highestStateIndex = row;
202 if (col > result.highestStateIndex) {
203 result.highestStateIndex = col;
206 ++result.numberOfNonzeroEntries;
209 STORM_LOG_THROW(row != lastRow || col != lastCol, storm::exceptions::InvalidArgumentException,
210 "The same transition (" << row <<
", " << col <<
") is given twice.");
218 if (reserveDiagonalElements) {
219 for (uint_fast64_t skippedRow = (uint_fast64_t)(lastRow + 1); skippedRow <= result.highestStateIndex; ++skippedRow) {
220 ++result.numberOfNonzeroEntries;
229 std::string
const& filename, storm::storage::SparseMatrix<double>
const& transitionMatrix);
230template storm::storage::SparseMatrix<double> DeterministicSparseTransitionParser<double>::parse(std::string
const& filename,
bool isRewardFile,
231 storm::storage::SparseMatrix<double>
const& transitionMatrix,
237 std::string
const& filename, storm::storage::SparseMatrix<double>
const& transitionMatrix);
238template storm::storage::SparseMatrix<storm::Interval> DeterministicSparseTransitionParser<storm::Interval>::parse(
239 std::string
const& filename,
bool isRewardFile, storm::storage::SparseMatrix<double>
const& transitionMatrix,
ExplicitModelParserOptions const& options);
This class can be used to parse a file containing either transitions or transition rewards of a deter...
static storm::storage::SparseMatrix< ValueType > parseDeterministicTransitions(std::string const &filename, ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
Load a deterministic transition system from file and create a sparse adjacency matrix whose entries r...
static storm::storage::SparseMatrix< ValueType > parseDeterministicTransitionRewards(std::string const &filename, storm::storage::SparseMatrix< MatrixValueType > const &transitionMatrix)
Load the transition rewards for a deterministic transition system from file and create a sparse adjac...
Opens a file and maps it to memory providing a char* containing the file content.
A class that holds a possibly non-square matrix in the compressed row storage format.
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.
index_type getRowCount() const
Returns the number of rows of the matrix.
#define STORM_LOG_INFO(message)
#define STORM_LOG_WARN(message)
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ERROR(message)
#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...
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 highestStateIndex
The highest state index that appears in the model.
uint_fast64_t numberOfNonzeroEntries
The total number of non-zero entries of the model.