Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeterminizeRHDPDAPart.hxx
Go to the documentation of this file.
1
7
9#include <alib/set>
10#include <global/GlobalData.h>
11
12namespace automaton {
13
14namespace determinize {
15
16template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
19
20 for(const auto& transition : npda.getReturnTransitions())
21 if ( dSubSet.contains ( std::get < 0 > ( transition.first ) ) )
22 ret.insert(std::get<1>(transition.first));
23
24 return ret;
25}
26
27template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
30
31 for(const auto& transition : npda.getCallTransitions())
32 if ( dSubSet.contains ( transition.first.first ) )
33 call.insert(transition.first.second);
34
35 return call;
36}
37
38template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
41
42 for(const auto& transition : npda.getLocalTransitions())
43 if ( dSubSet.contains ( transition.first.first ) )
44 local.insert(transition.first.second);
45
46 return local;
47}
48
49template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
51 using DeterministicStateType = ext::set < ext::pair < StateType, StateType > >;
53
54 DeterministicStateType initialLabel = createIdentity(npda.getInitialStates());
55 DeterministicPushdownStoreSymbolType bottom = ext::make_pair ( DeterministicStateType { }, common::symbol_or_epsilon < InputSymbolType > ( alphabet::BottomOfTheStackSymbol::instance < InputSymbolType > ( ) ) );
56
58 dpda.setInputAlphabet ( npda.getInputAlphabet ( ) );
59
62
63 std::queue < DeterministicStateType > dirtyStates;
64 dirtyStates.push ( initialLabel );
65
66 std::queue < ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType> > dirtyStateSymbols;
67 dirtyStateSymbols.push ( ext::make_pair ( initialLabel, bottom ) );
68
69 while ( ! dirtyStateSymbols.empty ( ) || ! dirtyStates.empty ( ) ) {
70 if ( ! dirtyStateSymbols.empty ( ) ) {
71 DeterministicStateType state = std::move ( dirtyStateSymbols.front ( ).first );
72 DeterministicPushdownStoreSymbolType pdaSymbol = std::move ( dirtyStateSymbols.front ( ).second );
73
74 dirtyStateSymbols.pop ( );
75
77 common::Streams::log << "Dirty state: " << state << " symbol: " << pdaSymbol << std::endl;
78
80
82 DeterministicStateType to;
83
84 if ( pdaSymbol == dpda.getBottomOfTheStackSymbol ( ) )
85 to = retInitial ( state, input, npda );
86 else
87 to = ret ( state, pdaSymbol, input, npda );
88
89 if ( to.empty ( ) )
90 continue;
91
92 if ( dpda.addState ( to ) )
93 dirtyStates.push ( to );
94
95 localClosure [ pdaSymbol.first ].insert ( to );
96
97 updateTopSymbols ( localClosure, topSymbols, dirtyStateSymbols, to, topSymbols [ pdaSymbol.first ] );
98
99 dpda.addReturnTransition ( state, std::move ( input ), pdaSymbol, std::move ( to ) );
100 }
101 } else { // ! dirtyStates.empty ( )
102 DeterministicStateType state = std::move ( dirtyStates.front ( ) );
103 dirtyStates.pop ( );
104
106 common::Streams::log << "Dirty state: " << state << std::endl;
107
111
112 for ( common::symbol_or_epsilon < InputSymbolType > && input : ext::make_mover ( localPart ) ) {
113 DeterministicStateType to = local ( state, input, npda );
114
115 if ( to.empty ( ) )
116 continue;
117
118 if ( dpda.addState ( to ) )
119 dirtyStates.push ( to );
120
121 localClosure [ state ].insert ( to );
122
123 updateTopSymbols ( localClosure, topSymbols, dirtyStateSymbols, to, topSymbols [ state ] );
124
125 dpda.addLocalTransition ( state, std::move ( input ), std::move ( to ) );
126 }
127 for ( common::symbol_or_epsilon < InputSymbolType > && input : ext::make_mover ( callPart ) ) {
128 DeterministicStateType to = call ( state, input, npda );
129
130 if ( to.empty ( ) )
131 continue;
132
134
135 if ( dpda.addState ( to ) )
136 dirtyStates.push ( to );
137
138 updateTopSymbols ( localClosure, topSymbols, dirtyStateSymbols, to, { pdaSymbol } );
139
140 dpda.addPushdownStoreSymbol ( pdaSymbol );
141 dpda.addCallTransition ( state, std::move ( input ), std::move ( to ), std::move ( pdaSymbol ) );
142 }
143 }
144 }
145
146 const ext::set<StateType>& finalLabels = npda.getFinalStates();
147 for(const DeterministicStateType & state : dpda.getStates()) {
148 ext::set<StateType> labels = retrieveDSubSet(state);
149
150 if(!ext::excludes(finalLabels.begin(), finalLabels.end(), labels.begin(), labels.end()))
151 dpda.addFinalState(state);
152 }
153
154 return dpda;
155}
156
157} /* namespace determinize */
158
159} /* namespace automaton */
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
Nondeterministic real time height deterministic pushdown automaton. Accepts subset of context free la...
Definition: RealTimeHeightDeterministicNPDA.h:76
const ext::set< StateType > & getInitialStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:175
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:1004
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:984
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:224
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:994
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: RealTimeHeightDeterministicNPDA.h:360
static automaton::DFA< SymbolType, StateType > determinize(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: Determinize.h:276
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
static ext::reference_wrapper< ext::ostream > log
Standard loging stream. Mapped to descriptor 4.
Definition: GlobalData.h:78
Definition: symbol_or_epsilon.hpp:24
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
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
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
void updateTopSymbols(ext::map< DeterministicStateType, ext::set< DeterministicStateType > > &localClosure, ext::map< DeterministicStateType, ext::set< DeterministicPushdownStoreSymbolType > > &topSymbols, std::queue< ext::pair< DeterministicStateType, DeterministicPushdownStoreSymbolType > > &dirtyStateSymbols, const DeterministicStateType &state, const ext::set< DeterministicPushdownStoreSymbolType > &newSymbols)
Definition: RHDPDACommon.h:126
ext::set< common::symbol_or_epsilon< InputSymbolType > > getCallPartitioning(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &npda, const ext::set< StateType > &dSubSet)
Definition: DeterminizeRHDPDAPart.hxx:28
ext::set< ext::pair< StateType, StateType > > call(const ext::set< ext::pair< StateType, StateType > > &S, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:94
ext::set< ext::pair< StateType, StateType > > ret(const ext::set< ext::pair< StateType, StateType > > &S, const DeterministicPushdownStoreSymbolType &pdaSymbol, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:57
ext::set< ext::pair< StateType, StateType > > createIdentity(const ext::set< StateType > &states)
Definition: RHDPDACommon.h:30
ext::set< StateType > retrieveDSubSet(const ext::set< ext::pair< StateType, StateType > > &localOperation)
Definition: RHDPDACommon.h:21
ext::set< ext::pair< StateType, StateType > > retInitial(const ext::set< ext::pair< StateType, StateType > > &S, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:39
ext::set< common::symbol_or_epsilon< InputSymbolType > > getLocalPartitioning(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &npda, const ext::set< StateType > &dSubSet)
Definition: DeterminizeRHDPDAPart.hxx:39
ext::set< common::symbol_or_epsilon< InputSymbolType > > getRetPartitioning(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &npda, const ext::set< StateType > &dSubSet)
Definition: DeterminizeRHDPDAPart.hxx:17
Definition: ToGrammar.h:31
reference_mover< T > make_mover(T &param)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
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