Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Accept.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <string/LinearString.h>
10
11#include "Run.h"
12#include <automaton/FSM/DFA.h>
13#include <automaton/FSM/NFA.h>
14#include <automaton/TA/DFTA.h>
15#include <automaton/TA/NFTA.h>
19#include <automaton/PDA/DPDA.h>
20#include <automaton/PDA/NPDTA.h>
21
22#include <ext/algorithm>
23
24#include <alib/deque>
25#include <alib/vector>
26
27namespace automaton {
28
29namespace run {
30
35class Accept {
36public:
48 template < class SymbolType, class StateType >
50
62 template < class SymbolType, class StateType >
64
76 template < class SymbolType, class StateType >
78
91 template < class SymbolType, class StateType >
93
94 template < class SymbolType, class StateType >
96
109 template < class SymbolType, class StateType >
111
124 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
126
139 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
141
154 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
156
169 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
171
184 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
186
200 template < class InputSymbolType, class OutputSymbolType, class PushdownStoreSymbolType, class StateType >
202
203};
204
205template < class SymbolType, class StateType >
207 ext::tuple < bool, StateType, ext::set < unsigned > > res = Run::calculateState ( automaton, string );
208
209 return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) );
210}
211
212template < class SymbolType, class StateType >
215
216 return std::get < 0 > ( res ) && std::any_of ( std::get < 1 > ( res ).begin ( ), std::get < 1 > ( res ).end ( ), [&] ( const StateType & state ) {
217 return automaton.getFinalStates ( ).count ( state );
218 } );
219}
220
221template < class SymbolType, class StateType >
224
225 return std::get < 0 > ( res ) && std::any_of ( std::get < 1 > ( res ).begin ( ), std::get < 1 > ( res ).end ( ), [&] ( const StateType & state ) {
226 return automaton.getFinalStates ( ).count ( state );
227 } );
228}
229
230template < class SymbolType, class StateType >
233
234 return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) );
235}
236
237template < class SymbolType, class StateType >
240
241 return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) );
242}
243
244template < class SymbolType, class StateType >
247
248 return std::get < 0 > ( res ) && std::any_of ( std::get < 1 > ( res ).begin ( ), std::get < 1 > ( res ).end ( ), [&] ( const StateType & state ) {
249 return automaton.getFinalStates ( ).count ( state );
250 } );
251}
252
253template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
256
257 return std::get < 0 > ( res ) && ( automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ) || ( automaton.getFinalStates ( ).empty ( ) && std::get < 3 > ( res ).empty ( ) ) );
258}
259
260template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
263
264 return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) );
265}
266
267template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
270
271 return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) );
272}
273
274template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
277
278 return std::get < 0 > ( res ) && ( automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ) || ( automaton.getFinalStates ( ).empty ( ) && std::get < 3 > ( res ).empty ( ) ) );
279}
280
281template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
284
286 if ( automaton.getFinalStates ( ).contains ( std::get < 0 > ( finalConfiguration ) ) || ( automaton.getFinalStates ( ).empty ( ) && std::get < 2 > ( finalConfiguration ).empty ( ) ) )
287 return true;
288
289 return false;
290}
291
292template < class InputSymbolType, class OutputSymbolType, class PushdownStoreSymbolType, class StateType >
295
297 if ( automaton.getFinalStates ( ).contains ( std::get < 0 > ( finalConfiguration ) ) || ( automaton.getFinalStates ( ).empty ( ) && std::get < 2 > ( finalConfiguration ).empty ( ) ) )
298 return true;
299
300 return false;
301}
302
303} /* namespace run */
304
305} /* namespace automaton */
306
Deterministic Z-Automaton in Arc-Factored Normal Form. Computation model for unranked regular tree la...
Definition: ArcFactoredDeterministicZAutomaton.h:65
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: DFTA.h:74
Deterministic pushdown automaton. Accepts subset of context free languages.
Definition: DPDA.h:78
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Deterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenDPDA.h:79
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
Definition: NPDA.h:74
Definition: NPDTA.h:75
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
Deterministic visibly pushdown automaton. Accepts subset of context free languages.
Definition: VisiblyPushdownDPDA.h:86
Implementation of test whether automaton accepts its input.
Definition: Accept.h:35
static bool accept(const automaton::DFA< SymbolType, StateType > &automaton, const string::LinearString< SymbolType > &string)
Definition: Accept.h:206
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Definition: set.hpp:44
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
Linear string.
Definition: LinearString.h:57
Tree structure represented in its natural representation. The representation is so called ranked,...
Definition: RankedTree.h:72
Tree represented in its natural representation. The representation is so called unranked,...
Definition: UnrankedTree.h:69
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
any_of(T &&...) -> any_of< T... >
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void end()
Definition: measurements.cpp:19
Definition: BackwardOccurrenceTest.h:17