diff --git a/alib2data/src/automaton/TA/DFTA.h b/alib2data/src/automaton/TA/DFTA.h index 5953efb7a0999d5af818af9d889e370c3a2942d2..0abd3e07582a4c1de68f0a60cd9346add6704e51 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 df2d4351ddd556052d97017e34a150c3bbfd4163..dda7c1b8f3138981bc86ba22284867c9ae173a54 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 */