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

simplify VPA and RHDPDA determinisation algo

parent 3735a6b0
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -26,7 +26,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 ) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::set<ext::pair<StateType, StateType>> & S = state;
 
ext::set<ext::pair<StateType, StateType>> S1;
for(const auto& entry : S) {
......@@ -45,26 +45,21 @@ void retInitial(const ext::set < ext::pair < StateType, StateType > > & state, c
}
}
 
bool S1Empty = S1.empty();
auto to ( packToStateLabel ( std::move ( S1 ) ) );
if(S1Empty) {
ext::tuple < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > > key(state, input, pdaSymbol);
rubbishReturnTransitions.insert(std::make_pair(key, to));
} else {
addRetTransition(state, input, pdaSymbol, to, deterministic);
}
if ( S1.empty ( ) )
rubbishReturnTransitions.insert ( std::make_pair ( ext::make_tuple ( state, input, pdaSymbol ), std::move ( S1 ) ) );
else
addRetTransition ( state, input, pdaSymbol, std::move ( S1 ), deterministic );
}
 
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) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::pair<ext::set < ext::pair < StateType, StateType > >, ext::variant<EpsilonType, InputSymbolType>> & pdaSymbolUnpack = unpackFromStackSymbol(pdaSymbol);
const ext::set<ext::pair<StateType, StateType>>& S1 = unpackFromStateLabel ( pdaSymbolUnpack.first );
const ext::set<ext::pair<StateType, StateType>> & S = state;
const ext::set<ext::pair<StateType, StateType>>& S1 = pdaSymbol.first;
 
ext::set<ext::pair<StateType, StateType>> update;
 
for(const auto& transition : nondeterministic.getCallTransitions()) {
if(pdaSymbolUnpack.second != std::get<1>(transition.first)) continue;
if(pdaSymbol.second != std::get<1>(transition.first)) continue;
 
const StateType& q = std::get<0>(transition.first);
for(const auto& to : transition.second) {
......@@ -103,14 +98,10 @@ void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ex
}
}
 
bool S2Empty = S2.empty();
auto to ( packToStateLabel ( std::move ( S2 ) ) );
if(S2Empty) {
ext::tuple < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType >, ext::pair < ext::set < ext::pair < StateType, StateType > >, ext::variant < EpsilonType, InputSymbolType > > > key(state, input, pdaSymbol);
rubbishReturnTransitions.insert(std::make_pair(key, to));
} else {
addRetTransition(state, input, pdaSymbol, to, deterministic);
}
if ( S2.empty ( ) )
rubbishReturnTransitions.insert(std::make_pair(ext::make_tuple(state, input, pdaSymbol), std::move ( S2 ) ) );
else
addRetTransition(state, input, pdaSymbol, std::move ( S2 ), deterministic);
}
 
template < class InputSymbolType, class EpsilonType, class StateType >
......@@ -124,7 +115,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) {
const ext::set < ext::pair < StateType, StateType > > & S = unpackFromStateLabel(state);
const ext::set < ext::pair < StateType, StateType > > & S = state;
 
ext::set < StateType > R = retrieveDSubSet(S);
ext::set < StateType > R1;
......@@ -142,14 +133,10 @@ void call(const ext::set < ext::pair < StateType, StateType > > & state, const e
}
}
 
bool R1Empty = R1.empty();
auto to = packToStateLabel(createIdentity(std::move(R1)));
auto push = packToStackSymbolLabel(ext::make_pair(state, input));
if(R1Empty) {
rubbishCallTransitions.insert(std::make_pair(ext::make_pair(state, input), ext::make_pair(to, push)));
} else {
addCallTransition(state, input, to, push, deterministic);
}
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
addCallTransition ( state, input, createIdentity ( std::move ( R1 ) ), ext::make_pair ( state, input ), deterministic);
}
 
template < class InputSymbolType, class EpsilonType, class StateType >
......@@ -162,7 +149,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 ) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::set<ext::pair<StateType, StateType>> & S = state;
ext::set<ext::pair<StateType, StateType>> S1;
 
for(const auto& entry : S) {
......@@ -180,13 +167,10 @@ void local(const ext::set < ext::pair < StateType, StateType > > & state, const
}
}
 
bool S1Empty = S1.empty();
auto to = packToStateLabel(std::move(S1));
if(S1Empty) {
rubbishLocalTransitions.insert(std::make_pair(ext::make_pair(state, input), to));
} else {
addLocalTransition(state, input, to, deterministic);
}
if ( S1.empty ( ) )
rubbishLocalTransitions.insert ( std::make_pair ( ext::make_pair ( state, input ), std::move ( S1 ) ) );
else
addLocalTransition ( state, input, std::move ( S1 ), deterministic );
}
 
template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType >
......@@ -195,7 +179,7 @@ ext::tuple<ext::set<ext::variant<EpsilonType, InputSymbolType>>, ext::set<ext::v
ext::set<ext::variant<EpsilonType, InputSymbolType>> call;
ext::set<ext::variant<EpsilonType, InputSymbolType>> ret;
 
const ext::set<StateType> dSubSet = retrieveDSubSet(unpackFromStateLabel(state));
const ext::set<StateType> dSubSet = retrieveDSubSet(state);
 
for(const auto& transition : n.getLocalTransitions()) {
if(dSubSet.count(transition.first.first))
......@@ -220,13 +204,13 @@ automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::
using DeterministicStateType = ext::set < ext::pair < StateType, StateType > >;
using DeterministicPushdownStoreSymbolType = ext::pair < DeterministicStateType, ext::variant < EpsilonType, InputSymbolType > >;
 
DeterministicStateType initialLabel = packToStateLabel(createIdentity(n.getInitialStates()));
DeterministicStateType initialLabel = createIdentity(n.getInitialStates());
DeterministicPushdownStoreSymbolType bottom = ext::make_pair ( DeterministicStateType { }, ext::variant < EpsilonType, InputSymbolType > ( alphabet::BottomOfTheStackSymbol::instance < InputSymbolType > ( ) ) );
 
automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, DeterministicPushdownStoreSymbolType, DeterministicStateType > d ( initialLabel, bottom );
d.setInputAlphabet ( n.getInputAlphabet ( ) );
 
ext::set < DeterministicStateType > rubbishStates = { packToStateLabel < StateType > ({})};
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;
......@@ -273,7 +257,7 @@ automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, ext::
 
const ext::set<StateType>& finalLabels = n.getFinalStates();
for(const DeterministicStateType & state : d.getStates()) {
const ext::set<StateType> labels = retrieveDSubSet(unpackFromStateLabel(state));
const ext::set<StateType> labels = retrieveDSubSet(state);
 
if(!ext::excludes(finalLabels.begin(), finalLabels.end(), labels.begin(), labels.end())) {
d.addFinalState(state);
......
......@@ -26,7 +26,7 @@ void addRetTransition(const ext::set < ext::pair < StateType, StateType > > & fr
 
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
void retInitial ( const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType > & pdaSymbol, const InputSymbolType & input, const automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType >, ext::set < ext::pair < StateType, StateType > > > & deterministic) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::set<ext::pair<StateType, StateType>> & S = state;
 
ext::set<ext::pair<StateType, StateType>> S1;
for(const auto& entry : S) {
......@@ -45,19 +45,18 @@ void retInitial ( const ext::set < ext::pair < StateType, StateType > > & state,
}
}
 
addRetTransition(state, input, pdaSymbol, packToStateLabel(std::move(S1)), deterministic);
addRetTransition(state, input, pdaSymbol, std::move(S1), deterministic);
}
 
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType > & pdaSymbol, const InputSymbolType & input, const automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType >, ext::set < ext::pair < StateType, StateType > > > & deterministic) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::pair<ext::set<ext::pair<StateType, StateType>>, InputSymbolType> & pdaSymbolUnpack = unpackFromStackSymbol(pdaSymbol);
const ext::set<ext::pair<StateType, StateType>>& S1 = unpackFromStateLabel ( pdaSymbolUnpack.first );
const ext::set<ext::pair<StateType, StateType>> & S = state;
const ext::set<ext::pair<StateType, StateType>>& S1 = pdaSymbol.first;
 
ext::set<ext::pair<StateType, StateType>> update;
 
for(const auto& transition : nondeterministic.getCallTransitions()) {
if(pdaSymbolUnpack.second != std::get<1>(transition.first)) continue;
if(pdaSymbol.second != std::get<1>(transition.first)) continue;
 
const StateType& q = std::get<0>(transition.first);
for(const auto& to : transition.second) {
......@@ -96,7 +95,7 @@ void ret(const ext::set < ext::pair < StateType, StateType > > & state, const ex
}
}
 
addRetTransition(state, input, pdaSymbol, packToStateLabel(std::move(S2)), deterministic);
addRetTransition(state, input, pdaSymbol, std::move(S2), deterministic);
}
 
template < class InputSymbolType, class StateType >
......@@ -110,7 +109,7 @@ void addCallTransition(const ext::set < ext::pair < StateType, StateType > > & f
 
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
void call(const ext::set < ext::pair < StateType, StateType > > & state, const InputSymbolType& input, const automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType >, ext::set < ext::pair < StateType, StateType > > > & deterministic) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::set<ext::pair<StateType, StateType>> & S = state;
 
ext::set<StateType> R = retrieveDSubSet(S);
ext::set<StateType> R1;
......@@ -128,7 +127,7 @@ void call(const ext::set < ext::pair < StateType, StateType > > & state, const I
}
}
 
addCallTransition(state, input, packToStateLabel(createIdentity(std::move(R1))), packToStackSymbolLabel(ext::make_pair(state, input)), deterministic);
addCallTransition(state, input, createIdentity(std::move(R1)), ext::make_pair(state, input), deterministic);
}
 
template < class InputSymbolType, class StateType >
......@@ -141,7 +140,7 @@ void addLocalTransition(const ext::set < ext::pair < StateType, StateType > > &
 
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
void local(const ext::set < ext::pair < StateType, StateType > > & state, const InputSymbolType& input, const automaton::VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & nondeterministic, automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pair < StateType, StateType > >, InputSymbolType >, ext::set < ext::pair < StateType, StateType > > > & deterministic) {
const ext::set<ext::pair<StateType, StateType>> & S = unpackFromStateLabel(state);
const ext::set<ext::pair<StateType, StateType>> & S = state;
ext::set<ext::pair<StateType, StateType>> S1;
 
for(const auto& entry : S) {
......@@ -159,7 +158,7 @@ void local(const ext::set < ext::pair < StateType, StateType > > & state, const
}
}
 
addLocalTransition(state, input, packToStateLabel(std::move(S1)), deterministic);
addLocalTransition(state, input, std::move(S1), deterministic);
}
 
template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
......@@ -167,7 +166,7 @@ automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pa
using DeterministicStateType = ext::set < ext::pair < StateType, StateType > >;
using DeterministicPushdownStoreSymbolType = ext::pair < DeterministicStateType, InputSymbolType >;
 
DeterministicStateType initialLabel = packToStateLabel(createIdentity(n.getInitialStates()));
DeterministicStateType initialLabel = createIdentity(n.getInitialStates());
DeterministicPushdownStoreSymbolType bottom = ext::make_pair ( DeterministicStateType { }, alphabet::BottomOfTheStackSymbol::instance < InputSymbolType > ( ) );
 
automaton::VisiblyPushdownDPDA < InputSymbolType, DeterministicPushdownStoreSymbolType, DeterministicStateType > d(initialLabel, bottom);
......@@ -176,7 +175,7 @@ automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pa
d.setLocalInputAlphabet(n.getLocalInputAlphabet());
d.setReturnInputAlphabet(n.getReturnInputAlphabet());
 
ext::set < DeterministicStateType > rubbishStates = { packToStateLabel < StateType > ({})};
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;
......@@ -209,7 +208,7 @@ automaton::VisiblyPushdownDPDA < InputSymbolType, ext::pair < ext::set < ext::pa
 
const ext::set<StateType>& finalLabels = n.getFinalStates();
for(const DeterministicStateType & state : d.getStates()) {
const ext::set<StateType> labels = retrieveDSubSet(unpackFromStateLabel(state));
const ext::set<StateType> labels = retrieveDSubSet(state);
 
if(!ext::excludes(finalLabels.begin(), finalLabels.end(), labels.begin(), labels.end())) {
d.addFinalState(state);
......
......@@ -14,36 +14,6 @@ namespace automaton {
 
namespace determinize {
 
template < class StateType >
ext::set<ext::pair<StateType, StateType>> packToStateLabel(ext::set<ext::pair<StateType, StateType>> data) {
return std::move ( data );
}
template < class StateType >
const ext::set<ext::pair<StateType, StateType>> & unpackFromStateLabel(const ext::set<ext::pair<StateType, StateType>> & data) {
return data;
}
template < class StateType, class InputSymbolType >
ext::pair<ext::set<ext::pair<StateType, StateType>>, InputSymbolType> packToStackSymbolLabel(ext::pair<ext::set<ext::pair<StateType, StateType>>, InputSymbolType> data) {
return std::move ( data );
}
template < class StateType, class InputSymbolType >
const ext::pair<ext::set<ext::pair<StateType, StateType>>, InputSymbolType> & unpackFromStackSymbol(const ext::pair<ext::set<ext::pair<StateType, StateType>>, InputSymbolType> & symbol) {
return symbol;
}
template < class StateType, class EpsilonType, class InputSymbolType >
ext::pair<ext::set<ext::pair<StateType, StateType>>, ext::variant<EpsilonType, InputSymbolType>> packToStackSymbolLabel(ext::pair<ext::set<ext::pair<StateType, StateType>>, ext::variant<EpsilonType, InputSymbolType>> data) {
return std::move ( data );
}
template < class StateType, class EpsilonType, class InputSymbolType >
const ext::pair<ext::set<ext::pair<StateType, StateType>>, ext::variant<EpsilonType, InputSymbolType>> & unpackFromStackSymbol(const ext::pair<ext::set<ext::pair<StateType, StateType>>, ext::variant<EpsilonType, InputSymbolType>> & symbol) {
return symbol;
}
template < class StateType >
ext::set<StateType> retrieveDSubSet(const ext::set<ext::pair<StateType, StateType>>& localOperation) {
ext::set<StateType> id;
......@@ -76,7 +46,7 @@ ext::set<ext::set<ext::pair<StateType,StateType>>> existsDirtyState(const T& d,
localTransitions.insert(rubbishLocalTransitions.begin(), rubbishLocalTransitions.end());
 
for(const ext::set<ext::pair<StateType,StateType>>& state : states) {
const ext::set<StateType> dSubSet = retrieveDSubSet(unpackFromStateLabel(state));
const ext::set<StateType> dSubSet = retrieveDSubSet(state);
 
bool originalCallsLocals = false;
for(const auto& transition : n.getCallTransitions()) {
......@@ -134,7 +104,7 @@ void localClosure(ext::set<DeterministicStateType>& states, const ext::set<Deter
const auto& popSymbol = std::get<2>(transition.first);
if(popSymbol == d.getBottomOfTheStackSymbol()) continue;
 
const DeterministicStateType & statePart = unpackFromStackSymbol ( popSymbol ).first;
const DeterministicStateType & statePart = popSymbol.first;
 
if(!states.count(statePart)) {
states.insert(statePart);
......@@ -162,7 +132,7 @@ ext::set<ext::pair<DeterministicStateType, DeterministicPushdownStoreSymbolType>
 
for(const DeterministicStateType& state : states) {
bool originalPops = false;
auto dSubSet = retrieveDSubSet(unpackFromStateLabel(state));
auto dSubSet = retrieveDSubSet(state);
 
for(const auto& transition : n.getReturnTransitions()) {
if(dSubSet.count(std::get<0>(transition.first))) {
......
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