Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RelaxedApproximateEnhancedCoversComputation.h
Go to the documentation of this file.
1
6#pragma once
7
9
10namespace stringology::cover {
11
17public:
27 template < class SymbolType >
29
30private:
44 template < class SymbolType >
45 static void processState ( const string::LinearString < SymbolType > & x, unsigned k, const State & previousState, ext::set < ext::pair < unsigned, unsigned > > & covers, unsigned & h );
46};
47
48template < class SymbolType >
50 // found relaxed approximate enhanced covers are not stored directly but
51 // rather as a set of lfactors
53 unsigned h = 0;
54
55 if ( x.getContent ( ).size ( ) < 2 )
57
58 for ( const auto & symbol : x.getAlphabet ( ) ) {
59 State firstState = constrFirstState ( x, k, symbol );
60
61 // check if the first character is a border (makes sense only for k = 0)
62 if ( isBorder ( firstState, x, k ) )
63 updateEnhCov ( firstState, result, h );
64
65 processState ( x, k, firstState, result, h );
66 }
67
68 // in the end the set of actual strings is computed from the set of lfactors
69 return getFactors ( x, result );
70}
71
72template < class SymbolType >
73void RelaxedApproximateEnhancedCoversComputation::processState ( const string::LinearString < SymbolType > & x, unsigned k, const State & previousState, ext::set < ext::pair < unsigned, unsigned > > & covers, unsigned & h ) {
74 for ( const auto & symbol : x.getAlphabet ( ) ) {
75 State currState = constrNextState ( x, previousState, k, symbol );
76 bool isFactor = false;
77
78 for ( const Element & element : currState.elements )
79 if ( element.level == 0 ) {
80 currState.lfactor = ext::pair < unsigned, unsigned > ( element.depth, currState.depth );
81 isFactor = true;
82 }
83
84 if ( ( currState.elements.size ( ) > 1 ) && ( ( currState.elements[0].depth == currState.depth ) && isFactor ) ) {
85 if ( ( currState.elements[currState.elements.size ( ) - 1].depth == x.getContent ( ).size ( ) ) && ( currState.depth > k ) )
86 updateEnhCov ( currState, covers, h );
87
88 processState ( x, k, currState, covers, h );
89 }
90 }
91}
92
93} // namespace stringology::cover
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
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: ApproximateEnhancedCoversCommon.h:20
static bool isBorder(const State &state, const string::LinearString< SymbolType > &x, unsigned k)
Definition: ApproximateEnhancedCoversCommon.h:171
static State constrNextState(const string::LinearString< SymbolType > &x, const State &previousState, unsigned k, const SymbolType &symbol)
Definition: ApproximateEnhancedCoversCommon.h:142
static ext::set< string::LinearString< SymbolType > > getFactors(const string::LinearString< SymbolType > &x, ext::set< ext::pair< unsigned int, unsigned int > > &enhCovers)
Definition: ApproximateEnhancedCoversCommon.h:189
static State constrFirstState(const string::LinearString< SymbolType > &x, unsigned k, const SymbolType &symbol)
Definition: ApproximateEnhancedCoversCommon.h:115
static void updateEnhCov(const State &state, ext::set< ext::pair< unsigned, unsigned > > &enhCovers, unsigned &h)
Definition: ApproximateEnhancedCoversCommon.h:92
Definition: RelaxedApproximateEnhancedCoversComputation.h:16
static ext::set< string::LinearString< SymbolType > > compute(const string::LinearString< SymbolType > &x, unsigned k)
Definition: RelaxedApproximateEnhancedCoversComputation.h:49
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
State
Definition: FordFulkerson.cpp:16
Definition: ApproximateCoversComputation.cpp:9
Definition: ApproximateEnhancedCoversCommon.h:41