@ -44,12 +44,14 @@ namespace parser {
* @ param buf Data to scan . Is expected to be some char array .
* @ param buf Data to scan . Is expected to be some char array .
* @ param maxnode Is set to highest id of all nodes .
* @ param maxnode Is set to highest id of all nodes .
*/
*/
uint_fast64_t DeterministicSparseTransitionParser : : firstPass ( char * buf , int_fast64_t & maxnode ) {
uint_fast64_t DeterministicSparseTransitionParser : : firstPass ( char * buf , int_fast64_t & maxnode , bool rewardFile ) {
uint_fast64_t nonZeroEntryCount = 0 ;
uint_fast64_t nonZeroEntryCount = 0 ;
/*
/*
* Check file header and extract number of transitions .
* Check file header and extract number of transitions .
*/
*/
if ( ! rewardFile ) {
buf = strchr ( buf , ' \n ' ) + 1 ; // skip format hint
buf = strchr ( buf , ' \n ' ) + 1 ; // skip format hint
}
/*
/*
* Check all transitions for non - zero diagonal entries and deadlock states .
* Check all transitions for non - zero diagonal entries and deadlock states .
@ -66,6 +68,7 @@ uint_fast64_t DeterministicSparseTransitionParser::firstPass(char* buf, int_fast
row = checked_strtol ( buf , & buf ) ;
row = checked_strtol ( buf , & buf ) ;
col = checked_strtol ( buf , & buf ) ;
col = checked_strtol ( buf , & buf ) ;
if ( ! rewardFile ) {
if ( lastRow ! = row ) {
if ( lastRow ! = row ) {
if ( ( lastRow ! = - 1 ) & & ( ! rowHadDiagonalEntry ) ) {
if ( ( lastRow ! = - 1 ) & & ( ! rowHadDiagonalEntry ) ) {
+ + nonZeroEntryCount ;
+ + nonZeroEntryCount ;
@ -84,6 +87,7 @@ uint_fast64_t DeterministicSparseTransitionParser::firstPass(char* buf, int_fast
rowHadDiagonalEntry = true ;
rowHadDiagonalEntry = true ;
+ + nonZeroEntryCount ;
+ + nonZeroEntryCount ;
}
}
}
/*
/*
* Check if one is larger than the current maximum id .
* Check if one is larger than the current maximum id .
@ -105,7 +109,7 @@ uint_fast64_t DeterministicSparseTransitionParser::firstPass(char* buf, int_fast
buf = trimWhitespaces ( buf ) ;
buf = trimWhitespaces ( buf ) ;
}
}
if ( ! rowHadDiagonalEntry ) {
if ( ! rowHadDiagonalEntry & & ! rewardFile ) {
+ + nonZeroEntryCount ;
+ + nonZeroEntryCount ;
}
}
@ -122,7 +126,7 @@ uint_fast64_t DeterministicSparseTransitionParser::firstPass(char* buf, int_fast
* @ return a pointer to the created sparse matrix .
* @ return a pointer to the created sparse matrix .
*/
*/
DeterministicSparseTransitionParser : : DeterministicSparseTransitionParser ( std : : string const & filename , bool insertDiagonalEntriesIfMissing )
DeterministicSparseTransitionParser : : DeterministicSparseTransitionParser ( std : : string const & filename , bool insertDiagonalEntriesIfMissing , bool rewardFile )
: matrix ( nullptr ) {
: matrix ( nullptr ) {
/*
/*
* Enforce locale where decimal point is ' . ' .
* Enforce locale where decimal point is ' . ' .
@ -139,7 +143,7 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
* Perform first pass , i . e . count entries that are not zero .
* Perform first pass , i . e . count entries that are not zero .
*/
*/
int_fast64_t maxStateId ;
int_fast64_t maxStateId ;
uint_fast64_t nonZeroEntryCount = this - > firstPass ( file . data , maxStateId ) ;
uint_fast64_t nonZeroEntryCount = this - > firstPass ( file . data , maxStateId , rewardFile ) ;
LOG4CPLUS_INFO ( logger , " First pass on " < < filename < < " shows " < < nonZeroEntryCount < < " NonZeros. " ) ;
LOG4CPLUS_INFO ( logger , " First pass on " < < filename < < " shows " < < nonZeroEntryCount < < " NonZeros. " ) ;
@ -160,7 +164,9 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
/*
/*
* Read file header , extract number of states .
* Read file header , extract number of states .
*/
*/
if ( ! rewardFile ) {
buf = strchr ( buf , ' \n ' ) + 1 ; // skip format hint
buf = strchr ( buf , ' \n ' ) + 1 ; // skip format hint
}
/*
/*
* Creating matrix here .
* Creating matrix here .
@ -198,7 +204,7 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
if ( insertDiagonalEntriesIfMissing ) {
if ( insertDiagonalEntriesIfMissing ) {
this - > matrix - > addNextValue ( lastRow , lastRow , storm : : utility : : constGetZero < double > ( ) ) ;
this - > matrix - > addNextValue ( lastRow , lastRow , storm : : utility : : constGetZero < double > ( ) ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. Inserted a 0-transition. (1) " ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. Inserted a 0-transition. (1) " ) ;
} else {
} else if ( ! rewardFile ) {
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. " ) ;
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. " ) ;
}
}
// No increment for lastRow
// No increment for lastRow
@ -206,11 +212,11 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
}
}
for ( int_fast64_t skippedRow = lastRow + 1 ; skippedRow < row ; + + skippedRow ) {
for ( int_fast64_t skippedRow = lastRow + 1 ; skippedRow < row ; + + skippedRow ) {
hadDeadlocks = true ;
hadDeadlocks = true ;
if ( fixDeadlocks ) {
if ( fixDeadlocks & & ! rewardFile ) {
this - > matrix - > addNextValue ( skippedRow , skippedRow , storm : : utility : : constGetOne < double > ( ) ) ;
this - > matrix - > addNextValue ( skippedRow , skippedRow , storm : : utility : : constGetOne < double > ( ) ) ;
rowHadDiagonalEntry = true ;
rowHadDiagonalEntry = true ;
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < skippedRow < < " has no outgoing transitions. A self-loop was inserted. " ) ;
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < skippedRow < < " has no outgoing transitions. A self-loop was inserted. " ) ;
} else {
} else if ( ! rewardFile ) {
LOG4CPLUS_ERROR ( logger , " Error while parsing " < < filename < < " : state " < < skippedRow < < " has no outgoing transitions. " ) ;
LOG4CPLUS_ERROR ( logger , " Error while parsing " < < filename < < " : state " < < skippedRow < < " has no outgoing transitions. " ) ;
// FIXME Why no exception at this point? This will break the App.
// FIXME Why no exception at this point? This will break the App.
}
}
@ -223,10 +229,10 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
rowHadDiagonalEntry = true ;
rowHadDiagonalEntry = true ;
} else if ( col > row & & ! rowHadDiagonalEntry ) {
} else if ( col > row & & ! rowHadDiagonalEntry ) {
rowHadDiagonalEntry = true ;
rowHadDiagonalEntry = true ;
if ( insertDiagonalEntriesIfMissing ) {
if ( insertDiagonalEntriesIfMissing & & ! rewardFile ) {
this - > matrix - > addNextValue ( row , row , storm : : utility : : constGetZero < double > ( ) ) ;
this - > matrix - > addNextValue ( row , row , storm : : utility : : constGetZero < double > ( ) ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < row < < " has no transition to itself. Inserted a 0-transition. (2) " ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < row < < " has no transition to itself. Inserted a 0-transition. (2) " ) ;
} else {
} else if ( ! rewardFile ) {
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < row < < " has no transition to itself. " ) ;
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < row < < " has no transition to itself. " ) ;
}
}
}
}
@ -236,10 +242,10 @@ DeterministicSparseTransitionParser::DeterministicSparseTransitionParser(std::st
}
}
if ( ! rowHadDiagonalEntry ) {
if ( ! rowHadDiagonalEntry ) {
if ( insertDiagonalEntriesIfMissing ) {
if ( insertDiagonalEntriesIfMissing & & ! rewardFile ) {
this - > matrix - > addNextValue ( lastRow , lastRow , storm : : utility : : constGetZero < double > ( ) ) ;
this - > matrix - > addNextValue ( lastRow , lastRow , storm : : utility : : constGetZero < double > ( ) ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. Inserted a 0-transition. (3) " ) ;
LOG4CPLUS_DEBUG ( logger , " While parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. Inserted a 0-transition. (3) " ) ;
} else {
} else if ( ! rewardFile ) {
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. " ) ;
LOG4CPLUS_WARN ( logger , " Warning while parsing " < < filename < < " : state " < < lastRow < < " has no transition to itself. " ) ;
}
}
}
}