16using namespace storm::utility::cstring;
18template<
typename ValueType>
22 return NondeterministicSparseTransitionParser::parse(filename,
false, emptyMatrix, options);
25template<
typename ValueType>
26template<
typename MatrixValueType>
29 return NondeterministicSparseTransitionParser::parse(filename,
true, modelInformation);
32template<
typename ValueType>
33template<
typename MatrixValueType>
38 setlocale(LC_NUMERIC,
"C");
42 char const* buf = file.getData();
46 NondeterministicSparseTransitionParser::firstPass(file.getData(), isRewardFile, modelInformation);
50 "Error while parsing " << filename <<
": erroneous file format.");
56 if (buf[0] <
'0' || buf[0] >
'9') {
64 STORM_LOG_THROW(
false, storm::exceptions::OutOfRangeException,
"Reward matrix size exceeds transition matrix size.");
66 STORM_LOG_THROW(
false, storm::exceptions::OutOfRangeException,
"Reward matrix row count does not match transition matrix row count.");
68 STORM_LOG_ERROR(
"The reward matrix has more entries than the transition matrix. There must be a reward for a non existent transition");
69 STORM_LOG_THROW(
false, storm::exceptions::OutOfRangeException,
"The reward matrix has more entries than the transition matrix.");
80 storm::storage::SparseMatrixBuilder<ValueType> matrixBuilder;
90 uint_fast64_t source = 0, target = 0, lastSource = 0, choice = 0, lastChoice = 0, curRow = 0;
93 bool hadDeadlocks =
false;
99 while (buf[0] !=
'\0') {
107 if (source != lastSource) {
113 for (uint_fast64_t i = lastSource + 1;
i < source; ++
i) {
119 if (source != lastSource) {
125 if (source != lastSource) {
126 curRow += choice + 1;
127 }
else if (choice != lastChoice) {
128 curRow += choice - lastChoice;
133 if ((source != lastSource || choice != lastChoice)) {
140 for (uint_fast64_t node = lastSource + 1; node < source; node++) {
146 STORM_LOG_INFO(
"Warning while parsing " << filename <<
": node " << node <<
" has no outgoing transitions. A self-loop was inserted.");
148 STORM_LOG_ERROR(
"Error while parsing " << filename <<
": node " << node <<
" has no outgoing transitions.");
151 if (source != lastSource) {
171 STORM_LOG_THROW(fixDeadlocks || !hadDeadlocks || isRewardFile, storm::exceptions::WrongFormatException,
172 "Some of the states do not have outgoing transitions.");
176 for (uint_fast64_t node = lastSource + 1; node < modelInformation.
getRowGroupCount(); node++) {
182 storm::storage::SparseMatrix<ValueType> resultMatrix = matrixBuilder.
build();
187 "There are rewards for non existent transitions given in the reward file.");
192template<
typename ValueType>
193template<
typename MatrixValueType>
195 char const* buf,
bool isRewardFile, storm::storage::SparseMatrix<MatrixValueType>
const& modelInformation) {
200 if (buf[0] <
'0' || buf[0] >
'9') {
206 uint_fast64_t source = 0, target = 0, choice = 0, lastChoice = 0, lastSource = 0, lastTarget = -1;
213 while (buf[0] !=
'\0') {
220 STORM_LOG_THROW(source >= lastSource, storm::exceptions::InvalidArgumentException,
221 "The current source state " << source <<
" is smaller than the last one " << lastSource <<
".");
224 if (source > result.highestStateIndex) {
225 result.highestStateIndex = source;
231 "State index " << result.highestStateIndex <<
" found. This exceeds the highest state index of the model, which is "
236 if (source != lastSource) {
244 for (uint_fast64_t i = lastSource + 1;
i < source; ++
i) {
250 if (source != lastSource) {
251 result.choices += choice + 1;
252 }
else if (choice != lastChoice) {
253 result.choices += choice - lastChoice;
258 if (source > lastSource + 1) {
259 result.numberOfNonzeroEntries += source - lastSource - 1;
260 result.choices += source - lastSource - 1;
263 if (source != lastSource || choice != lastChoice) {
273 if (target > result.highestStateIndex) {
274 result.highestStateIndex = target;
278 STORM_LOG_THROW(target != lastTarget || choice != lastChoice || source != lastSource, storm::exceptions::InvalidArgumentException,
279 "The same transition (" << source <<
", " << choice <<
", " << target <<
") is given twice.");
283 if (!isRewardFile && (val < 0.0 || val > 1.0)) {
284 STORM_LOG_ERROR(
"Expected a positive probability but got \"" << std::string(buf, 0, 16) <<
"\".");
287 }
else if (val < 0.0) {
288 STORM_LOG_ERROR(
"Expected a positive reward value but got \"" << std::string(buf, 0, 16) <<
"\".");
298 result.numberOfNonzeroEntries++;
313 for (uint_fast64_t i = lastSource + 1;
i < modelInformation.
getRowGroupIndices().size() - 1; ++
i) {
323 std::string
const& filename, storm::storage::SparseMatrix<double>
const& modelInformation);
324template storm::storage::SparseMatrix<double> NondeterministicSparseTransitionParser<double>::parse(
325 std::string
const& filename,
bool isRewardFile, storm::storage::SparseMatrix<double>
const& modelInformation,
ExplicitModelParserOptions const& options);
330 std::string
const& filename, storm::storage::SparseMatrix<double>
const& modelInformation);
331template storm::storage::SparseMatrix<storm::Interval> NondeterministicSparseTransitionParser<storm::Interval>::parse<double>(
332 std::string
const& filename,
bool isRewardFile, storm::storage::SparseMatrix<double>
const& modelInformation,
ExplicitModelParserOptions const& options);
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, ExplicitModelParserOptions const &options=ExplicitModelParserOptions())
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...
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)
#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 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.