Skip to content
Snippets Groups Projects
Commit ccd7e4df authored by Jan Trávníček's avatar Jan Trávníček
Browse files

some simplifications of PDA determinisation

parent e033da54
No related branches found
No related tags found
No related merge requests found
......@@ -25,7 +25,7 @@ void addRetTransition(const ext::set < ext::pair < StateType, StateType > > & fr
}
 
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
void retInitial(const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > & pdaSymbol, const ext::variant < EpsilonType, InputSymbolType>& input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::map < ext::tuple < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > >, ext::set < ext::pair < StateType, StateType > > > & rubbishReturnTransitions ) {
void retInitial(const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > & pdaSymbol, const ext::variant < EpsilonType, InputSymbolType>& input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::set < ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > > > & rubbishReturnTransitions ) {
const ext::set<ext::pair<StateType, StateType>> & S = state;
 
ext::set<ext::pair<StateType, StateType>> S1;
......@@ -45,14 +45,14 @@ void retInitial(const ext::set < ext::pair < StateType, StateType > > & state, c
}
}
 
if ( S1.empty ( ) )
rubbishReturnTransitions.insert ( std::make_pair ( ext::make_tuple ( state, input, pdaSymbol ), std::move ( S1 ) ) );
else
if ( ! S1.empty ( ) )
addRetTransition ( state, input, pdaSymbol, std::move ( S1 ), deterministic );
else
rubbishReturnTransitions.insert(ext::make_pair(state, pdaSymbol ) );
}
 
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > & pdaSymbol, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::map < ext::tuple < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > >, ext::set < ext::pair < StateType, StateType > > > & rubbishReturnTransitions) {
void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > & pdaSymbol, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::set < ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > > > & rubbishReturnTransitions) {
const ext::set<ext::pair<StateType, StateType>> & S = state;
const ext::set<ext::pair<StateType, StateType>>& S1 = pdaSymbol.first;
 
......@@ -98,10 +98,10 @@ void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ex
}
}
 
if ( S2.empty ( ) )
rubbishReturnTransitions.insert(std::make_pair(ext::make_tuple(state, input, pdaSymbol), std::move ( S2 ) ) );
else
if ( ! S2.empty ( ) )
addRetTransition(state, input, pdaSymbol, std::move ( S2 ), deterministic);
else
rubbishReturnTransitions.insert(ext::make_pair(state, pdaSymbol ) );
}
 
template < class InputSymbolType, class EpsilonType, class StateType >
......@@ -114,7 +114,7 @@ void addCallTransition(const ext::set < ext::pair < StateType, StateType > > & f
}
 
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
void call(const ext::set < ext::pair < StateType, StateType > > & state, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::map < ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > > > & rubbishCallTransitions) {
void call(const ext::set < ext::pair < StateType, StateType > > & state, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic ) {
const ext::set < ext::pair < StateType, StateType > > & S = state;
 
ext::set < StateType > R = retrieveDSubSet(S);
......@@ -133,9 +133,7 @@ void call(const ext::set < ext::pair < StateType, StateType > > & state, const e
}
}
 
if ( R1.empty ( ) )
rubbishCallTransitions.insert(std::make_pair(ext::make_pair(state, input), ext::make_pair( createIdentity ( std::move ( R1 ) ), ext::make_pair(state, input))));
else
if ( ! R1.empty ( ) )
addCallTransition ( state, input, createIdentity ( std::move ( R1 ) ), ext::make_pair ( state, input ), deterministic);
}
 
......@@ -148,7 +146,7 @@ void addLocalTransition ( const ext::set < ext::pair < StateType, StateType > >
}
 
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
void local(const ext::set < ext::pair < StateType, StateType > > & state, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic, ext::map < ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & rubbishLocalTransitions ) {
void local(const ext::set < ext::pair < StateType, StateType > > & state, const ext::variant < EpsilonType, InputSymbolType > & input, const automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > >, ext::set < ext::pair < StateType, StateType > > > & deterministic ) {
const ext::set<ext::pair<StateType, StateType>> & S = state;
ext::set<ext::pair<StateType, StateType>> S1;
 
......@@ -167,9 +165,7 @@ void local(const ext::set < ext::pair < StateType, StateType > > & state, const
}
}
 
if ( S1.empty ( ) )
rubbishLocalTransitions.insert ( std::make_pair ( ext::make_pair ( state, input ), std::move ( S1 ) ) );
else
if ( ! S1.empty ( ) )
addLocalTransition ( state, input, std::move ( S1 ), deterministic );
}
 
......@@ -210,14 +206,11 @@ automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::
automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, DeterministicPushdownStoreSymbolType, DeterministicStateType > d ( initialLabel, bottom );
d.setInputAlphabet ( n.getInputAlphabet ( ) );
 
ext::set < DeterministicStateType > rubbishStates = { DeterministicStateType { } };
ext::map < ext::tuple < DeterministicStateType, ext::variant<EpsilonType, InputSymbolType>, DeterministicPushdownStoreSymbolType >, DeterministicStateType > rubbishReturnTransitions;
ext::map < ext::pair < DeterministicStateType, ext::variant<EpsilonType, InputSymbolType>>, ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > rubbishCallTransitions;
ext::map < ext::pair < DeterministicStateType, ext::variant<EpsilonType, InputSymbolType>>, DeterministicStateType > rubbishLocalTransitions;
ext::set < ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > rubbishReturnTransitions;
 
for(;;) {
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> stateSymbols = existsDirtyStateSymbol(d, rubbishStates, rubbishCallTransitions, rubbishReturnTransitions, n);
ext::set<DeterministicStateType> states = existsDirtyState(d, rubbishStates, rubbishCallTransitions, rubbishLocalTransitions, n);
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> stateSymbols = existsDirtyStateSymbol(d, rubbishReturnTransitions, n);
ext::set<DeterministicStateType> states = existsDirtyState(d, n);
 
if(stateSymbols.empty() && states.empty()) break;
 
......@@ -247,10 +240,10 @@ automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::
ext::set<ext::variant<EpsilonType, InputSymbolType>>& callPart = std::get<1>(partitioning);
 
for(const auto& symbol : localPart) {
local(state, symbol, n, d, rubbishLocalTransitions);
local(state, symbol, n, d);
}
for(const auto& symbol : callPart) {
call(state, symbol, n, d, rubbishCallTransitions);
call(state, symbol, n, d);
}
}
}
......@@ -265,10 +258,7 @@ automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::
}
 
if ( common::GlobalData::verbose ) {
common::Streams::log << "Rubbish states: " << rubbishStates << std::endl;
common::Streams::log << "Rubbish return transitions: " << rubbishReturnTransitions << std::endl;
common::Streams::log << "Rubbish call transitions: " << rubbishCallTransitions << std::endl;
common::Streams::log << "Rubbish local transitions:" << rubbishLocalTransitions << std::endl;
}
 
return d;
......
......@@ -175,14 +175,11 @@ automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pa
d.setLocalInputAlphabet(n.getLocalInputAlphabet());
d.setReturnInputAlphabet(n.getReturnInputAlphabet());
 
ext::set < DeterministicStateType > rubbishStates = { DeterministicStateType { } };
ext::map < ext::tuple < DeterministicStateType, InputSymbolType, DeterministicPushdownStoreSymbolType >, DeterministicStateType > rubbishReturnTransitions;
ext::map < ext::pair < DeterministicStateType, InputSymbolType>, ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > rubbishCallTransitions;
ext::map < ext::pair < DeterministicStateType, InputSymbolType>, DeterministicStateType > rubbishLocalTransitions;
ext::set < ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > rubbishReturnTransitions;
 
for(;;) {
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> stateSymbols = existsDirtyStateSymbol(d, rubbishStates, rubbishCallTransitions, rubbishReturnTransitions, n);
ext::set<DeterministicStateType> states = existsDirtyState(d, rubbishStates, rubbishCallTransitions, rubbishLocalTransitions, n);
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> stateSymbols = existsDirtyStateSymbol(d, rubbishReturnTransitions, n);
ext::set<DeterministicStateType> states = existsDirtyState(d, n);
 
if(stateSymbols.empty() && states.empty()) break;
 
......
......@@ -32,21 +32,12 @@ ext::set<ext::pair<StateType, StateType>> createIdentity(const ext::set<StateTyp
return id;
}
 
template<class T, class StateType, class InputSymbolType, class DeterministicPushdownStoreSymbolType, class R>
ext::set<ext::set<ext::pair<StateType,StateType>>> existsDirtyState(const T& d, const ext::set<ext::set<ext::pair<StateType,StateType>>>& rubbishStates, const ext::map<ext::pair< ext::set<ext::pair<StateType, StateType>>, InputSymbolType>, DeterministicPushdownStoreSymbolType >& rubbishCallTransitions, const ext::map<ext::pair<ext::set<ext::pair<StateType,StateType>>, InputSymbolType>, ext::set<ext::pair<StateType,StateType>>>& rubbishLocalTransitions, const R& n) {
ext::set<ext::set<ext::pair<StateType,StateType>>> dirtyStates;
template<class T, class R>
ext::set < typename T::StateType_t > existsDirtyState(const T& d, const R& n) {
ext::set < typename T::StateType_t > dirtyStates;
 
ext::set<ext::set<ext::pair<StateType,StateType>>> states = d.getStates();
states.insert(rubbishStates.begin(), rubbishStates.end());
auto callTransitions = d.getCallTransitions();
callTransitions.insert(rubbishCallTransitions.begin(), rubbishCallTransitions.end());
auto localTransitions = d.getLocalTransitions();
localTransitions.insert(rubbishLocalTransitions.begin(), rubbishLocalTransitions.end());
for(const ext::set<ext::pair<StateType,StateType>>& state : states) {
const ext::set<StateType> dSubSet = retrieveDSubSet(state);
for(const typename T::StateType_t & state : d.getStates ( ) ) {
auto dSubSet = retrieveDSubSet(state);
 
bool originalCallsLocals = false;
for(const auto& transition : n.getCallTransitions()) {
......@@ -65,13 +56,13 @@ ext::set<ext::set<ext::pair<StateType,StateType>>> existsDirtyState(const T& d,
if(!originalCallsLocals) continue;
bool deterministicCallLocals = false;
 
for(const auto& transition : callTransitions) {
for(const auto& transition : d.getCallTransitions ( ) ) {
if(state == transition.first.first) {
deterministicCallLocals = true;
break;
}
}
if(deterministicCallLocals) for(const auto& transition : localTransitions) {
if(deterministicCallLocals) for(const auto& transition : d.getLocalTransitions ( ) ) {
if(state == transition.first.first) {
deterministicCallLocals = true;
break;
......@@ -118,20 +109,11 @@ ext::set < DeterministicStateType > localClosure ( const DeterministicStateType
return closed;
}
 
template<class T, class DeterministicStateType, class InputSymbolType, class DeterministicPushdownStoreSymbolType, class R>
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> existsDirtyStateSymbol(const T& d, const ext::set<DeterministicStateType>& rubbishStates, const ext::map < ext::pair < DeterministicStateType, InputSymbolType>, ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > & rubbishCallTransitions, const ext::map < ext::tuple < DeterministicStateType, InputSymbolType, DeterministicPushdownStoreSymbolType >, DeterministicStateType > & rubbishReturnTransitions, const R& n) {
template<class T, class DeterministicStateType, class DeterministicPushdownStoreSymbolType, class R>
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> existsDirtyStateSymbol(const T& d, const ext::set < ext::pair < DeterministicStateType, DeterministicPushdownStoreSymbolType > > & rubbishReturnTransitions, const R& n) {
ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>> dirtyStateSymbols;
 
ext::set<DeterministicStateType> states = d.getStates();
states.insert(rubbishStates.begin(), rubbishStates.end());
auto callTransitions = d.getCallTransitions();
callTransitions.insert(rubbishCallTransitions.begin(), rubbishCallTransitions.end());
auto returnTransitions = d.getReturnTransitions();
returnTransitions.insert(rubbishReturnTransitions.begin(), rubbishReturnTransitions.end());
for(const DeterministicStateType& state : states) {
for(const DeterministicStateType& state : d.getStates ( ) ) {
bool originalPops = false;
auto dSubSet = retrieveDSubSet(state);
 
......@@ -147,7 +129,7 @@ ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>
 
ext::set<DeterministicPushdownStoreSymbolType> topSymbols;
for(const DeterministicStateType& localState : lc) {
for(const auto& transition : callTransitions) {
for(const auto& transition : d.getCallTransitions ( ) ) {
const auto& to = transition.second;
if(localState != to.first) continue;
 
......@@ -158,12 +140,18 @@ ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>
topSymbols.insert(d.getBottomOfTheStackSymbol());
}
 
for(const auto& transition : returnTransitions) {
for(const auto& transition : d.getReturnTransitions ( ) ) {
if(state != std::get<0>(transition.first)) continue;
 
topSymbols.erase(std::get<2>(transition.first));
}
 
for ( const auto & transition : rubbishReturnTransitions ) {
if(state != transition.first) continue;
topSymbols.erase(transition.second);
}
for(const DeterministicPushdownStoreSymbolType& topSymbol : topSymbols)
dirtyStateSymbols.insert(ext::make_pair(state, topSymbol));
}
......
......@@ -50,6 +50,8 @@ protected:
ext::map < ext::pair < StateType, ext::variant < EpsilonType, InputSymbolType > >, StateType > localTransitions;
 
public:
using StateType_t = StateType;
explicit RealTimeHeightDeterministicDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates );
explicit RealTimeHeightDeterministicDPDA ( StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol );
 
......
......@@ -51,6 +51,8 @@ protected:
ext::map < ext::pair < StateType, InputSymbolType >, StateType > localTransitions;
 
public:
using StateType_t = StateType;
explicit VisiblyPushdownDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > callAlphabet, ext::set < InputSymbolType > returnAlphabet, ext::set < InputSymbolType > localAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates );
explicit VisiblyPushdownDPDA ( StateType initialSymbol, PushdownStoreSymbolType bottomOfTheStackSymbol );
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment