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.";
}
// Check if we encountered a state index that is bigger than all previously seen ones and record it if necessary.
if(source>result.highestStateIndex){
result.highestStateIndex=source;
}
++result.numberOfChoices;
// If we have skipped some states, we need to reserve the space for the self-loop insertion in the second pass.
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.";
}
// 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;
}
++result.numberOfChoices;
// Record that the current source was the last source.
lastsource=source;
// 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;
}
buf=trimWhitespaces(buf);
// Record that the current source was the last source.
lastsource=source;
// 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);
buf=trimWhitespaces(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;
}
// 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);
// Go to the next line where the transitions start.
buf=forwardToNextLine(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.";
// 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.
// 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.
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.";
}
}
// We need to record that we found at least one successor state for the current choice.
hasSuccessorState=true;
lastSuccessorState=target;
// As we found a new successor, we need to increase the number of nonzero entries.
++result.numberOfNonzeroEntries;
buf=forwardToNextLine(buf);
}else{
// If it was not a "*", we have to assume that we encountered the beginning of a new choice definition. In this case, we don't move the pointer
// to the buffer, because we still need to read the new source state.
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;
// Record that the current source was the last source.
lastsource=source;
buf=trimWhitespaces(buf);
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;
// 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;
}
// Mark the current state as a Markovian one.
result.markovianStates.set(source,true);
}else{
isMarkovianChoice=false;
}
// Go to the next line where the transitions start.
buf=forwardToNextLine(buf);
// Go to the next line where the transitions start.
buf=forwardToNextLine(buf);
// 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;
// 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);
// 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]=='*'){
// 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);
// 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);
// 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);
// 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.