From 963feec7a5e363c1ffdf8eb7b2127d9bdfa4594c Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 6 Apr 2018 10:30:05 +0200
Subject: [PATCH] detect transitions from final state of turing machine

---
 alib2data/src/automaton/TM/OneTapeDTM.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/alib2data/src/automaton/TM/OneTapeDTM.h b/alib2data/src/automaton/TM/OneTapeDTM.h
index c97acb36b3..2440ac075c 100644
--- a/alib2data/src/automaton/TM/OneTapeDTM.h
+++ b/alib2data/src/automaton/TM/OneTapeDTM.h
@@ -244,6 +244,9 @@ bool OneTapeDTM<SymbolType, StateType>::addTransition(StateType from, SymbolType
 		throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
 	}
 
+	if ( getFinalStates().count ( from ) )
+		throw AutomatonException("From state \"" + ext::to_string ( from ) + "\" is final..");
+
 	if (!getTapeAlphabet().count(input)) {
 		throw AutomatonException("Tape symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
 	}
@@ -495,8 +498,16 @@ public:
 		return automaton.getStates ( ).count ( state );
 	}
 
-	static void valid ( const automaton::OneTapeDTM<SymbolType, StateType> &, const StateType & ) {
-		//TODO final state and outgoing transitions
+	/**
+	 * All states are valid as a final state of the automaton.
+	 *
+	 * \param automaton the tested automaton
+	 * \param state the tested state
+	 */
+	static void valid ( const automaton::OneTapeDTM<SymbolType, StateType> & automaton, const StateType & state ) {
+		for ( const std::pair<const ext::pair<StateType, SymbolType>, ext::tuple<StateType, SymbolType, automaton::Shift> >& transition : automaton.getTransitions ( ) )
+			if ( state == transition.first.first )
+				throw automaton::AutomatonException("State \"" + ext::to_string ( state ) + "\" cannot be marked as final as it is source of a transition.");
 	}
 };
 
-- 
GitLab