/* Name: validate * Purpose: To find if the all of the transtions are valid. * Operation: This method it checks that each transition is based on the class States, Tape_Alphabet, and moves R or L. */ void Transition_Function::validate(const Tape_Alphabet &tape_alphabet, States states, bool & valid){ // Prevent two transitions from having the same source_state and Read_Character for (unsigned int i = 0; i < transitions.size(); i++){ for(unsigned int z = i + 1; z < transitions.size(); z++){ if(transitions[i].Source_State() == transitions[z].Source_State() && transitions[i].Read_Character() == transitions[z].Read_Character()){ valid = false; cout << "Error: Two transitions have the same source state '" << transitions[i].Source_State() << "' and read character '" << transitions[i].Read_Character() << "'.\n"; } } } // Validate the the tape alphabet elements. for (unsigned int i = 0; i < transitions.size(); i++){ // The read character is not contained within the tape alphabet. if (!tape_alphabet.is_element(transitions[i].Read_Character())){ cout << "Error: Transition read character '" << transitions[i].Read_Character() << "' is not in tape alphabet.\n"; valid = false; } // The write character is not contained within the tape alphabet. if (!tape_alphabet.is_element(transitions[i].Write_Character())){ cout << "Error: Transition write character '" << transitions[i].Write_Character() << "' is not in tape alphabet.\n"; valid = false; } } // Validate that all of the states are in the list of states. for (unsigned int i = 0; i < transitions.size(); i++){ // The source state is not in the list of states. if (!states.is_element(transitions[i].Source_State())){ cout << "Error: Transition source state '" << transitions[i].Source_State() << "' is not in states.\n"; valid = false; } // The destination state is not in the list of states. if (!states.is_element(transitions[i].Destination_State())){ cout << "Error: Transition destination state '" << transitions[i].Destination_State() << "' is not in states.\n"; valid = false; } } }