Skip to content
Snippets Groups Projects
Commit 2884a772 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

template exact subtree automaton construction algorithm

parent ded124a9
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
 
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment