26template<
typename ValueType>
32template<
typename ValueType>
33template<
typename MatrixValueType>
39template<
typename ValueType>
40template<
typename MatrixValueType>
44 setlocale(LC_NUMERIC,
"C");
48 char const* buf = file.getData();
58 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": empty or erroneous file format.");
59 throw storm::exceptions::WrongFormatException();
66 if (buf[0] <
'0' || buf[0] >
'9') {
74 STORM_LOG_ERROR(
"Reward matrix has more rows or columns than transition matrix.");
75 throw storm::exceptions::WrongFormatException() <<
"Reward matrix has more rows or columns than transition matrix.";
87 uint_fast64_t row, col, lastRow = 0;
90 bool hadDeadlocks =
false;
98 while (buf[0] !=
'\0') {
104 resultMatrix.addNextValue(row, col, val);
113 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
115 if (!dontFixDeadlocks) {
116 resultMatrix.addNextValue(skippedRow, skippedRow, storm::utility::one<ValueType>());
117 STORM_LOG_WARN(
"Warning while parsing " << filename <<
": state " << skippedRow
118 <<
" has no outgoing transitions. A self-loop was inserted.");
120 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
126 while (buf[0] !=
'\0') {
134 if (lastRow != row) {
135 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
137 if (!dontFixDeadlocks) {
138 resultMatrix.addNextValue(skippedRow, skippedRow, storm::utility::one<ValueType>());
139 STORM_LOG_INFO(
"Warning while parsing " << filename <<
": state " << skippedRow
140 <<
" has no outgoing transitions. A self-loop was inserted.");
142 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": state " << skippedRow <<
" has no outgoing transitions.");
149 resultMatrix.addNextValue(row, col, val);
154 if (dontFixDeadlocks && hadDeadlocks)
155 throw storm::exceptions::WrongFormatException() <<
"Some of the states do not have outgoing transitions.";
163 if (isRewardFile && !result.
isSubmatrixOf(transitionMatrix)) {
164 STORM_LOG_ERROR(
"There are rewards for non existent transitions given in the reward file.");
165 throw storm::exceptions::WrongFormatException() <<
"There are rewards for non existent transitions given in the reward file.";
171template<
typename ValueType>
172typename DeterministicSparseTransitionParser<ValueType>::FirstPassResult DeterministicSparseTransitionParser<ValueType>::firstPass(
173 char const* buf,
bool reserveDiagonalElements) {
174 DeterministicSparseTransitionParser<ValueType>::FirstPassResult result;
178 if (buf[0] <
'0' || buf[0] >
'9') {
184 uint_fast64_t row, col, lastRow = 0, lastCol = -1;
189 if (row > 0 && reserveDiagonalElements) {
190 for (uint_fast64_t skippedRow = 0; skippedRow < row; ++skippedRow) {
191 ++result.numberOfNonzeroEntries;
195 while (buf[0] !=
'\0') {
202 if (lastRow != row && reserveDiagonalElements) {
204 for (uint_fast64_t skippedRow = lastRow + 1; skippedRow < row; ++skippedRow) {
205 ++result.numberOfNonzeroEntries;
210 if (row > result.highestStateIndex)
211 result.highestStateIndex = row;
212 if (col > result.highestStateIndex)
213 result.highestStateIndex = col;
215 ++result.numberOfNonzeroEntries;
218 if (row == lastRow && col == lastCol) {
219 STORM_LOG_ERROR(
"The same transition (" << row <<
", " << col <<
") is given twice.");
220 throw storm::exceptions::InvalidArgumentException() <<
"The same transition (" << row <<
", " << col <<
") is given twice.";
229 if (reserveDiagonalElements) {
230 for (uint_fast64_t skippedRow = (uint_fast64_t)(lastRow + 1); skippedRow <= result.highestStateIndex; ++skippedRow) {
231 ++result.numberOfNonzeroEntries;
238template class DeterministicSparseTransitionParser<double>;
244#ifdef STORM_HAVE_CARL
245template class DeterministicSparseTransitionParser<storm::Interval>;
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)
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 can be used to build a sparse matrix by adding value by value.
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)
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.