19using namespace storm::utility::cstring;
21template<
typename ValueType>
24 return DeterministicSparseTransitionParser<ValueType>::parse(filename,
false, emptyMatrix);
27template<
typename ValueType>
28template<
typename MatrixValueType>
31 return DeterministicSparseTransitionParser<ValueType>::parse(filename,
true, transitionMatrix);
34template<
typename ValueType>
35template<
typename MatrixValueType>
39 setlocale(LC_NUMERIC,
"C");
43 char const* buf = file.getData();
47 DeterministicSparseTransitionParser<ValueType>::firstPass(file.getData(), !isRewardFile);
53 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": empty or erroneous file format.");
54 throw storm::exceptions::WrongFormatException();
61 if (buf[0] <
'0' || buf[0] >
'9') {
69 STORM_LOG_ERROR(
"Reward matrix has more rows or columns than transition matrix.");
70 throw storm::exceptions::WrongFormatException() <<
"Reward matrix has more rows or columns than transition matrix.";
82 uint_fast64_t row, col, lastRow = 0;
85 bool hadDeadlocks =
false;
93 while (buf[0] !=
'\0') {
99 resultMatrix.addNextValue(row, col, val);
108 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
110 if (!dontFixDeadlocks) {
112 STORM_LOG_WARN(
"Warning while parsing " << filename <<
": state " << skippedRow
113 <<
" has no outgoing transitions. A self-loop was inserted.");
115 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
121 while (buf[0] !=
'\0') {
129 if (lastRow != row) {
130 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
132 if (!dontFixDeadlocks) {
134 STORM_LOG_INFO(
"Warning while parsing " << filename <<
": state " << skippedRow
135 <<
" has no outgoing transitions. A self-loop was inserted.");
137 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
144 resultMatrix.addNextValue(row, col, val);
149 if (dontFixDeadlocks && hadDeadlocks)
150 throw storm::exceptions::WrongFormatException() <<
"Some of the states do not have outgoing transitions.";
154 storm::storage::SparseMatrix<ValueType> result = resultMatrix.build();
158 if (isRewardFile && !result.
isSubmatrixOf(transitionMatrix)) {
159 STORM_LOG_ERROR(
"There are rewards for non existent transitions given in the reward file.");
160 throw storm::exceptions::WrongFormatException() <<
"There are rewards for non existent transitions given in the reward file.";
166template<
typename ValueType>
168 char const* buf,
bool reserveDiagonalElements) {
173 if (buf[0] <
'0' || buf[0] >
'9') {
179 uint_fast64_t row, col, lastRow = 0, lastCol = -1;
184 if (row > 0 && reserveDiagonalElements) {
185 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
186 ++result.numberOfNonzeroEntries;
190 while (buf[0] !=
'\0') {
197 if (lastRow != row && reserveDiagonalElements) {
199 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
200 ++result.numberOfNonzeroEntries;
205 if (row > result.highestStateIndex)
206 result.highestStateIndex = row;
207 if (col > result.highestStateIndex)
208 result.highestStateIndex = col;
210 ++result.numberOfNonzeroEntries;
213 if (row == lastRow && col == lastCol) {
214 STORM_LOG_ERROR(
"The same transition (" << row <<
", " << col <<
") is given twice.");
215 throw storm::exceptions::InvalidArgumentException() <<
"The same transition (" << row <<
", " << col <<
") is given twice.";
224 if (reserveDiagonalElements) {
225 for (uint_fast64_t skippedRow = (uint_fast64_t)(lastRow + 1); skippedRow <= result.highestStateIndex; ++skippedRow) {
226 ++result.numberOfNonzeroEntries;
235 std::string
const& filename, storm::storage::SparseMatrix<double>
const& transitionMatrix);
236template storm::storage::SparseMatrix<double> DeterministicSparseTransitionParser<double>::parse(std::string
const& filename,
bool isRewardFile,
237 storm::storage::SparseMatrix<double>
const& transitionMatrix);
242 std::string
const& filename, storm::storage::SparseMatrix<double>
const& transitionMatrix);
243template storm::storage::SparseMatrix<storm::Interval> DeterministicSparseTransitionParser<storm::Interval>::parse(
244 std::string
const& filename,
bool isRewardFile, storm::storage::SparseMatrix<double>
const& transitionMatrix);
This class can be used to parse a file containing either transitions or transition rewards of a deter...
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...
static storm::storage::SparseMatrix< ValueType > parseDeterministicTransitions(std::string const &filename)
Load a deterministic transition system from file and create a sparse adjacency matrix whose entries r...
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)
Contains all file parsers and helper classes.
SettingsType const & getModule()
Get module.
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.