- More tests.
- Changed SparseStateRewardParser to a static class
- Added comments here and there
- Some reformatting.
- Fixed some warnings.
- Eliminated some unnecessary includes.
- ...
Former-commit-id: efe1c96fee
LOG4CPLUS_ERROR(logger,"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.");
throwstorm::exceptions::WrongFormatException()<<"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.";
}
}elseif(source<lastsource){
LOG4CPLUS_ERROR(logger,"Illegal state choice order. A choice of state "<<source<<" appears at an illegal position.");
throwstorm::exceptions::WrongFormatException()<<"Illegal state choice order. A choice of state "<<source<<" appears at an illegal position.";
}
++result.numberOfChoices;
// If we have moved to the next state, we need to clear the flag that stores whether or not the source has a Markovian or probabilistic choice.
if(source!=lastsource){
stateHasMarkovianChoice=false;
stateHasProbabilisticChoice=false;
}
// Record that the current source was the last source.
lastsource=source;
buf=trimWhitespaces(buf);
// Depending on the action name, the choice is either a probabilitic one or a markovian one.
boolisMarkovianChoice=false;
if(buf[0]=='!'&&skipWord(buf)-buf==1){
isMarkovianChoice=true;
}else{
isMarkovianChoice=false;
}
buf=skipWord(buf);
if(isMarkovianChoice){
if(stateHasMarkovianChoice){
LOG4CPLUS_ERROR(logger,"The state "<<source<<" has multiple Markovian choices.");
throwstorm::exceptions::WrongFormatException()<<"The state "<<source<<" has multiple Markovian choices.";
}
if(stateHasProbabilisticChoice){
LOG4CPLUS_ERROR(logger,"The state "<<source<<" has a probabilistic choice preceding a Markovian choice. The Markovian choice must be the first choice listed.");
throwstorm::exceptions::WrongFormatException()<<"The state "<<source<<" has a probabilistic choice preceding a Markovian choice. The Markovian choice must be the first choice listed.";
}
stateHasMarkovianChoice=true;
}else{
stateHasProbabilisticChoice=true;
}
buf=forwardToNextLine(buf,lineEndings);
// Now that we have the source state and the information whether or not the current choice is probabilistic or Markovian, we need to read the list of successors and the probabilities/rates.
boolhasSuccessorState=false;
boolencounteredNewDistribution=false;
uint_fast64_tlastSuccessorState=0;
// At this point, we need to check whether there is an additional successor or we have reached the next choice for the same or a different state.
do{
buf=trimWhitespaces(buf);
// If the end of the file was reached, we need to abort and check whether we are in a legal state.
if(buf[0]=='\0'){
if(!hasSuccessorState){
LOG4CPLUS_ERROR(logger,"Premature end-of-file. Expected at least one successor state for state "<<source<<".");
throwstorm::exceptions::WrongFormatException()<<"Premature end-of-file. Expected at least one successor state for state "<<source<<".";
}else{
// If there was at least one successor for the current choice, this is legal and we need to move on.
encounteredEOF=true;
}
}elseif(buf[0]=='*'){
// As we have encountered a "*", we know that there is an additional successor state for the current choice.
buf=skipWord(buf);
// Now we need to read the successor state and check if we already saw a higher state index.
LOG4CPLUS_ERROR(logger,"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.");
throwstorm::exceptions::WrongFormatException()<<"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.";
}
}
if(source!=lastsource){
// If we skipped to a new state we need to record the beginning of the choices in the nondeterministic choice indices.
// Record that the current source was the last source.
lastsource=source;
buf=trimWhitespaces(buf);
// Depending on the action name, the choice is either a probabilitic one or a markovian one.
boolisMarkovianChoice=false;
if(buf[0]=='!'&&skipWord(buf)-buf==1){
isMarkovianChoice=true;
// Mark the current state as a Markovian one.
result.markovianStates.set(source,true);
}else{
isMarkovianChoice=false;
}
buf=forwardToNextLine(buf,lineEndings);
// Now that we have the source state and the information whether or not the current choice is probabilistic or Markovian, we need to read the list of successors and the probabilities/rates.
boolhasSuccessorState=false;
boolencounteredNewDistribution=false;
// At this point, we need to check whether there is an additional successor or we have reached the next choice for the same or a different state.
do{
buf=trimWhitespaces(buf);
// If the end of the file was reached, we need to abort and check whether we are in a legal state.
if(buf[0]=='\0'){
// Under the assumption that the currently open choice has at least one successor (which is given after the first run)
// we may legally stop reading here.
encounteredEOF=true;
}elseif(buf[0]=='*'){
// We need to record that we found at least one successor state for the current choice.
hasSuccessorState=true;
// As we have encountered a "*", we know that there is an additional successor state for the current choice.
buf=skipWord(buf);
// Now we need to read the successor state and check if we already saw a higher state index.
target=checked_strtol(buf,&buf);
// And the corresponding probability/rate.
doubleval=checked_strtod(buf,&buf);
// Record the value as well as the exit rate in case of a Markovian choice.
LOG4CPLUS_ERROR(logger,"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.");
throwstorm::exceptions::WrongFormatException()<<"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.";
}
}elseif(source<lastsource){
LOG4CPLUS_ERROR(logger,"Illegal state choice order. A choice of state "<<source<<" appears at an illegal position.");
throwstorm::exceptions::WrongFormatException()<<"Illegal state choice order. A choice of state "<<source<<" appears at an illegal position.";
}
++result.numberOfChoices;
// If we have moved to the next state, we need to clear the flag that stores whether or not the source has a Markovian or probabilistic choice.
if(source!=lastsource){
stateHasMarkovianChoice=false;
stateHasProbabilisticChoice=false;
}
// Record that the current source was the last source.
lastsource=source;
buf=trimWhitespaces(buf);
// Depending on the action name, the choice is either a probabilitic one or a markovian one.
boolisMarkovianChoice=false;
if(buf[0]=='!'&&skipWord(buf)-buf==1){
isMarkovianChoice=true;
}else{
isMarkovianChoice=false;
}
buf=skipWord(buf);
if(isMarkovianChoice){
if(stateHasMarkovianChoice){
LOG4CPLUS_ERROR(logger,"The state "<<source<<" has multiple Markovian choices.");
throwstorm::exceptions::WrongFormatException()<<"The state "<<source<<" has multiple Markovian choices.";
}
if(stateHasProbabilisticChoice){
LOG4CPLUS_ERROR(logger,"The state "<<source<<" has a probabilistic choice preceding a Markovian choice. The Markovian choice must be the first choice listed.");
throwstorm::exceptions::WrongFormatException()<<"The state "<<source<<" has a probabilistic choice preceding a Markovian choice. The Markovian choice must be the first choice listed.";
}
stateHasMarkovianChoice=true;
}else{
stateHasProbabilisticChoice=true;
}
buf=forwardToNextLine(buf,lineEndings);
// Now that we have the source state and the information whether or not the current choice is probabilistic or Markovian, we need to read the list of successors and the probabilities/rates.
boolhasSuccessorState=false;
boolencounteredNewDistribution=false;
uint_fast64_tlastSuccessorState=0;
// At this point, we need to check whether there is an additional successor or we have reached the next choice for the same or a different state.
do{
buf=trimWhitespaces(buf);
// If the end of the file was reached, we need to abort and check whether we are in a legal state.
if(buf[0]=='\0'){
if(!hasSuccessorState){
LOG4CPLUS_ERROR(logger,"Premature end-of-file. Expected at least one successor state for state "<<source<<".");
throwstorm::exceptions::WrongFormatException()<<"Premature end-of-file. Expected at least one successor state for state "<<source<<".";
}else{
// If there was at least one successor for the current choice, this is legal and we need to move on.
encounteredEOF=true;
}
}elseif(buf[0]=='*'){
// As we have encountered a "*", we know that there is an additional successor state for the current choice.
buf=skipWord(buf);
// Now we need to read the successor state and check if we already saw a higher state index.
LOG4CPLUS_ERROR(logger,"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.");
throwstorm::exceptions::WrongFormatException()<<"Found deadlock states (e.g. "<<lastsource+1<<") during parsing. Please fix them or set the appropriate flag.";
}
}
if(source!=lastsource){
// If we skipped to a new state we need to record the beginning of the choices in the nondeterministic choice indices.
// Record that the current source was the last source.
lastsource=source;
buf=trimWhitespaces(buf);
// Depending on the action name, the choice is either a probabilitic one or a markovian one.
boolisMarkovianChoice=false;
if(buf[0]=='!'&&skipWord(buf)-buf==1){
isMarkovianChoice=true;
// Mark the current state as a Markovian one.
result.markovianStates.set(source,true);
}else{
isMarkovianChoice=false;
}
buf=forwardToNextLine(buf,lineEndings);
// Now that we have the source state and the information whether or not the current choice is probabilistic or Markovian, we need to read the list of successors and the probabilities/rates.
boolencounteredNewDistribution=false;
// At this point, we need to check whether there is an additional successor or we have reached the next choice for the same or a different state.
do{
buf=trimWhitespaces(buf);
// If the end of the file was reached, we need to abort and check whether we are in a legal state.
if(buf[0]=='\0'){
// Under the assumption that the currently open choice has at least one successor (which is given after the first run)
// we may legally stop reading here.
encounteredEOF=true;
}elseif(buf[0]=='*'){
// As we have encountered a "*", we know that there is an additional successor state for the current choice.
buf=skipWord(buf);
// Now we need to read the successor state and check if we already saw a higher state index.
target=checked_strtol(buf,&buf);
// And the corresponding probability/rate.
doubleval=checked_strtod(buf,&buf);
// Record the value as well as the exit rate in case of a Markovian choice.