Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeterminizeZAutomataPart.hxx
Go to the documentation of this file.
1
6#include <ext/algorithm>
7
8#include <alib/deque>
9#include <alib/set>
10
11namespace automaton {
12
13namespace determinize {
14
15template < class SymbolType, class StateType >
18 res.setInputAlphabet ( automaton.getInputAlphabet ( ) );
19
20 for ( const SymbolType & input : automaton.getInputAlphabet ( ) ) {
21 auto range = automaton.getTransitions ( ).equal_range ( input );
22
24 for ( auto & transition : range )
25 dfaState.insert ( transition.second );
26
27 res.addState ( dfaState );
28
29 res.addTransition ( input, dfaState );
30 }
31
32 bool changed;
33 do {
34 changed = false;
35 for ( const ext::set < StateType > & dfaState1 : res.getStates ( ) ) {
36 for ( const ext::set < StateType > & dfaState2 : res.getStates ( ) ) {
38 for ( const StateType & nfaState1 : dfaState1 ) {
39 for ( const StateType & nfaState2 : dfaState2 ) {
40
41 auto range = automaton.getTransitions ( ).equal_range ( ext::make_pair ( nfaState1, nfaState2 ) );
42 for ( auto & transition : range )
43 dfaState.insert ( transition.second );
44 }
45 }
46
47 changed |= res.addState ( dfaState );
48
49 res.addTransition ( ext::make_pair ( dfaState1, dfaState2 ), std::move ( dfaState ) );
50 }
51 }
52 } while ( changed );
53
54 const ext::set < StateType > & finalLabels = automaton.getFinalStates();
55 for ( const ext::set < StateType > & dfaState : res.getStates ( ) )
56 if ( ! ext::excludes ( finalLabels.begin ( ), finalLabels.end ( ), dfaState.begin ( ), dfaState.end ( ) ) )
57 res.addFinalState ( dfaState );
58
59 return res;
60}
61
62} /* namespace determinize */
63
64} /* namespace automaton */
Deterministic Z-Automaton in Arc-Factored Normal Form. Computation model for unranked regular tree la...
Definition: ArcFactoredDeterministicZAutomaton.h:65
Nondeterministic Z-Automaton in Arc-Factored Normal Form. Computation model for unranked regular tree...
Definition: ArcFactoredNondeterministicZAutomaton.h:67
static automaton::DFA< SymbolType, StateType > determinize(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: Determinize.h:276
Definition: set.hpp:44
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
auto range(Container &&cont) -> decltype(std::forward< Container >(cont).range())
Definition: range.hpp:247
bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp)
Tests two sorted ranges wheter all elements from the second are not present in the first.
Definition: algorithm.hpp:46
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79