From 8deb0f862b390fb818ce88b81b33e85b6a2ec77f Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 4 Apr 2017 08:35:19 +0200
Subject: [PATCH] normalize tree automata

---
 alib2data/src/automaton/TA/DFTA.h | 19 +++++++++++++++++++
 alib2data/src/automaton/TA/NFTA.h | 19 +++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/alib2data/src/automaton/TA/DFTA.h b/alib2data/src/automaton/TA/DFTA.h
index 5953efb7a0..0abd3e0758 100644
--- a/alib2data/src/automaton/TA/DFTA.h
+++ b/alib2data/src/automaton/TA/DFTA.h
@@ -23,6 +23,7 @@
 #include "../AutomatonBase.h"
 #include "../common/AutomatonFromXMLParser.h"
 #include "../common/AutomatonToXMLComposer.h"
+#include "../common/AutomatonNormalize.h"
 
 namespace automaton {
 
@@ -147,6 +148,24 @@ public:
 	void composeTransitions ( std::deque < sax::Token > & out ) const;
 
 	virtual alib::ObjectBase * inc ( ) &&;
+
+	virtual AutomatonBase * normalize ( ) && {
+		std::set < std::ranked_symbol < DefaultSymbolType > > alphabet = AutomatonNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) );
+		std::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) );
+		std::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) );
+
+		DFTA < > * res = new DFTA < > ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) );
+
+		for ( std::pair < std::pair < std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > >, StateType > && transition : std::make_moveable_map ( transitions ) ) {
+			std::ranked_symbol < DefaultSymbolType, DefaultRankType > input = AutomatonNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) );
+			std::vector < DefaultStateType > from = AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) );
+			DefaultStateType to = AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
+
+			res->addTransition ( std::move ( input ), std::move ( from ), std::move ( to ) );
+		}
+
+		return res;
+	}
 };
 
 } /* namespace automaton */
diff --git a/alib2data/src/automaton/TA/NFTA.h b/alib2data/src/automaton/TA/NFTA.h
index df2d4351dd..dda7c1b8f3 100644
--- a/alib2data/src/automaton/TA/NFTA.h
+++ b/alib2data/src/automaton/TA/NFTA.h
@@ -22,6 +22,7 @@
 #include "../AutomatonException.h"
 #include "../common/AutomatonFromXMLParser.h"
 #include "../common/AutomatonToXMLComposer.h"
+#include "../common/AutomatonNormalize.h"
 
 namespace automaton {
 
@@ -165,6 +166,24 @@ public:
 	void composeTransitions ( std::deque < sax::Token > & out ) const;
 
 	virtual alib::ObjectBase * inc ( ) &&;
+
+	virtual AutomatonBase * normalize ( ) && {
+		std::set < std::ranked_symbol < DefaultSymbolType > > alphabet = AutomatonNormalize::normalizeRankedAlphabet ( std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ) );
+		std::set < DefaultStateType > states = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < States > ( ).get ( ) ) );
+		std::set < DefaultStateType > finalStates = AutomatonNormalize::normalizeStates ( std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ) );
+
+		NFTA < > * res = new NFTA < > ( std::move ( states ), std::move ( alphabet ), std::move ( finalStates ) );
+
+		for ( std::pair < std::pair < std::ranked_symbol < SymbolType, RankType >, std::vector < StateType > >, std::set < StateType > > && transition : std::make_moveable_map ( transitions ) ) {
+			std::ranked_symbol < DefaultSymbolType, DefaultRankType > input = AutomatonNormalize::normalizeRankedSymbol ( std::move ( transition.first.first ) );
+			std::vector < DefaultStateType > from = AutomatonNormalize::normalizeStates ( std::move ( transition.first.second ) );
+			std::set < DefaultStateType > to = AutomatonNormalize::normalizeStates ( std::move ( transition.second ) );
+
+			res->addTransitions ( std::move ( input ), std::move ( from ), std::move ( to ) );
+		}
+
+		return res;
+	}
 };
 
 } /* namespace automaton */
-- 
GitLab