Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
NondeterministicApproximateSuffixEpsilonAutomatonForHammingDistance.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <automaton/FSM/NFA.h>
10#include <string/LinearString.h>
11
12namespace stringology::indexing {
13
15public:
20 template < class SymbolType >
22};
23
24template < class SymbolType >
26 auto initial_state = ext::make_pair ( 0, 0 );
27
29 result.setInputAlphabet( pattern.getAlphabet ( ) );
30
31 for ( unsigned int j = 0; j < k + 1; j ++ ) {
32 for ( unsigned int i = j ; i < pattern.getContent ( ).size ( ) + 1 ; i++ ) {
33 result.addState ( ext::make_pair ( i, j ) );
34 if ( i == pattern.getContent ( ).size ( ) ) {
35 result.addFinalState ( ext::make_pair ( i, j ) );
36 }
37 }
38 }
39
40 for ( unsigned int j = 0 ; j < k + 1 ; j ++ ) {
41 for ( unsigned int i = j; i < pattern.getContent ( ).size ( ); i ++ ) {
42 auto from = ext::make_pair ( i, j );
43 auto to = ext::make_pair ( i + 1, j );
44 result.addTransition ( from, pattern.getContent ( ) [ i ], to );
45 }
46 }
47
48 for ( unsigned int j = 0 ; j < k ; j ++ ) {
49 for ( unsigned int i = j ; i < pattern.getContent ( ).size ( ); i ++ ) {
50 auto from = ext::make_pair ( i, j );
51 auto to = ext::make_pair ( i + 1, j + 1 );
52
53 for ( const SymbolType & symbol : pattern.getAlphabet ( ) ) {
54 if ( symbol != pattern.getContent ( ) [ i ] ) {
55 result.addTransition ( from, symbol, to );
56 }
57 }
58 }
59 }
60
61 //epsilon transitions
62 for ( unsigned int j = 1 ; j <= pattern.getContent ( ).size ( ); j ++ ) {
63 auto from = ext::make_pair ( 0, 0 );
64 auto to = ext::make_pair ( j, 0 );
65 result.addTransition ( from, to );
66 }
67
68 return result;
69}
70
71} /* namespace stringology::indexing */
72
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Definition: NondeterministicApproximateSuffixEpsilonAutomatonForHammingDistance.h:14
static automaton::EpsilonNFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int k)
Definition: NondeterministicApproximateSuffixEpsilonAutomatonForHammingDistance.h:25
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: BitParallelIndexConstruction.h:14