diff --git a/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.cpp b/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.cpp index 7e09e47c3eb59fff8be7772c43e3e12e7c3fd64b..d35fb97b568c9236d85eb6b4563f0e216521b6d8 100644 --- a/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.cpp +++ b/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.cpp @@ -6,42 +6,13 @@ */ #include "ExactSubtreeAutomaton.h" -#include <tree/ranked/PrefixRankedTree.h> -#include <automaton/PDA/InputDrivenNPDA.h> -#include <alphabet/RankedSymbol.h> - -#include <alib/deque> #include <registration/AlgoRegistration.hpp> namespace arbology { namespace exact { -automaton::InputDrivenNPDA < > ExactSubtreeAutomaton::construct ( const tree::PrefixRankedTree < > & tree ) { - DefaultSymbolType S = DefaultSymbolType ( 'S' ); - automaton::InputDrivenNPDA < > res ( DefaultStateType ( 0 ), S ); - - for ( const common::ranked_symbol < > & rankedSymbol : tree.getAlphabet ( ) ) { - DefaultSymbolType symbol ( alphabet::RankedSymbol < > { rankedSymbol } ); - res.addInputSymbol ( symbol ); - res.setPushdownStoreOperation ( symbol, ext::vector < DefaultSymbolType > ( 1, S ), ext::vector < DefaultSymbolType > ( ( size_t ) rankedSymbol.getRank ( ), S ) ); - } - - int i = 1; - - for ( const common::ranked_symbol < > & rankedSymbol : tree.getContent ( ) ) { - DefaultSymbolType symbol ( alphabet::RankedSymbol < > { rankedSymbol } ); - - res.addState ( DefaultStateType ( i ) ); - res.addTransition ( DefaultStateType ( i - 1 ), symbol, DefaultStateType ( i ) ); - res.addTransition ( DefaultStateType ( 0 ), std::move ( symbol ), DefaultStateType ( i ) ); - i++; - } - - return res; -} - -auto ExactSubtreeAutomatonPrefixRankedTree = registration::AbstractRegister < ExactSubtreeAutomaton, automaton::InputDrivenNPDA < >, const tree::PrefixRankedTree < > & > ( ExactSubtreeAutomaton::construct ); +auto ExactSubtreeAutomatonPrefixRankedTree = registration::AbstractRegister < ExactSubtreeAutomaton, automaton::InputDrivenNPDA < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, char, unsigned >, const tree::PrefixRankedTree < > & > ( ExactSubtreeAutomaton::construct ); } /* namespace exact */ diff --git a/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.h b/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.h index 7024e6ba4fb2584037e17e85f5deadec2f3aa62a..4014f550357035b8180ea7663301a68f56d90608 100644 --- a/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.h +++ b/alib2algo/src/arbology/exact/ExactSubtreeAutomaton.h @@ -8,8 +8,8 @@ #ifndef _EXACT_SUBTREE_AUTOMATON_H__ #define _EXACT_SUBTREE_AUTOMATON_H__ -#include <automaton/AutomatonFeatures.h> -#include <tree/TreeFeatures.h> +#include <tree/ranked/PrefixRankedTree.h> +#include <automaton/PDA/InputDrivenNPDA.h> namespace arbology { @@ -21,10 +21,32 @@ public: * Performs conversion. * @return left regular grammar equivalent to source automaton. */ - static automaton::InputDrivenNPDA < > construct ( const tree::PrefixRankedTree < > & tree ); + template < class SymbolType, class RankType > + static automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > construct ( const tree::PrefixRankedTree < SymbolType, RankType > & tree ); }; +template < class SymbolType, class RankType > +automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > ExactSubtreeAutomaton::construct ( const tree::PrefixRankedTree < SymbolType, RankType > & tree ) { + automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > res ( 0, 'S' ); + + for ( const common::ranked_symbol < SymbolType, RankType > & symbol : tree.getAlphabet ( ) ) { + res.addInputSymbol ( symbol ); + res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, 'S' ), ext::vector < char > ( ( size_t ) symbol.getRank ( ), 'S' ) ); + } + + unsigned i = 1; + + for ( const common::ranked_symbol < SymbolType, RankType > & symbol : tree.getContent ( ) ) { + res.addState ( i ); + res.addTransition ( i - 1, symbol, i ); + res.addTransition ( 0, std::move ( symbol ), i ); + i++; + } + + return res; +} + } /* namespace exact */ } /* namespace arbology */