diff --git a/acompare2/src/AutomatonCompare.cpp b/acompare2/src/AutomatonCompare.cpp index a68b8287247fc26634bfd52440c9f0addc10ba05..22ef96dbae70bd94c48e59f7d851166ebd5cea52 100644 --- a/acompare2/src/AutomatonCompare.cpp +++ b/acompare2/src/AutomatonCompare.cpp @@ -170,7 +170,7 @@ bool AutomatonCompare::testCompare(const automaton::VisiblyPushdownNPDA& a, cons a.getLocalTransitions() == b.getLocalTransitions() ; } -bool AutomatonCompare::testCompare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b) { +bool AutomatonCompare::testCompare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b) { return a.getFinalStates() == b.getFinalStates() && a.getInitialState() == b.getInitialState() && // a.getInputAlphabet() == b.getInputAlphabet() && @@ -900,7 +900,7 @@ void AutomatonCompare::printCompare(const automaton::VisiblyPushdownNPDA& a, con } } -void AutomatonCompare::printCompare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b) { +void AutomatonCompare::printCompare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b) { std::cout << "AutomatonCompareer" << std::endl; if(a.getFinalStates() != b.getFinalStates()){ @@ -1326,7 +1326,7 @@ int AutomatonCompare::compare(const automaton::VisiblyPushdownNPDA& a, const aut auto AutomatonCompareVisiblyPushdownNPDA = AutomatonCompare::RegistratorWrapper<int, automaton::VisiblyPushdownNPDA, automaton::VisiblyPushdownNPDA>(AutomatonCompare::compare); -int AutomatonCompare::compare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b) { +int AutomatonCompare::compare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b) { if(!AutomatonCompare::testCompare(a, b)) { AutomatonCompare::printCompare(a, b); return 1; @@ -1335,7 +1335,7 @@ int AutomatonCompare::compare(const automaton::RealTimeHeightDeterministicDPDA& } } -auto AutomatonCompareRealTimeHeightDeterministicDPDA = AutomatonCompare::RegistratorWrapper<int, automaton::RealTimeHeightDeterministicDPDA, automaton::RealTimeHeightDeterministicDPDA>(AutomatonCompare::compare); +auto AutomatonCompareRealTimeHeightDeterministicDPDA = AutomatonCompare::RegistratorWrapper<int, automaton::RealTimeHeightDeterministicDPDA < >, automaton::RealTimeHeightDeterministicDPDA < > >(AutomatonCompare::compare); int AutomatonCompare::compare(const automaton::RealTimeHeightDeterministicNPDA& a, const automaton::RealTimeHeightDeterministicNPDA& b) { if(!AutomatonCompare::testCompare(a, b)) { diff --git a/acompare2/src/AutomatonCompare.h b/acompare2/src/AutomatonCompare.h index 5268371950b0766a0d20d07d5ccc1a42c9431513..2b9bd3d73ef1b2af020c905bec9c239329aa88f7 100644 --- a/acompare2/src/AutomatonCompare.h +++ b/acompare2/src/AutomatonCompare.h @@ -62,8 +62,8 @@ private: static bool testCompare(const automaton::VisiblyPushdownNPDA& a, const automaton::VisiblyPushdownNPDA& b); static void printCompare(const automaton::VisiblyPushdownNPDA& a, const automaton::VisiblyPushdownNPDA& b); - static bool testCompare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b); - static void printCompare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b); + static bool testCompare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b); + static void printCompare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b); static bool testCompare(const automaton::RealTimeHeightDeterministicNPDA& a, const automaton::RealTimeHeightDeterministicNPDA& b); static void printCompare(const automaton::RealTimeHeightDeterministicNPDA& a, const automaton::RealTimeHeightDeterministicNPDA& b); @@ -95,7 +95,7 @@ public: static int compare(const automaton::NPDA < > & a, const automaton::NPDA < > & b); static int compare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b); static int compare(const automaton::InputDrivenNPDA < > & a, const automaton::InputDrivenNPDA < > & b); - static int compare(const automaton::RealTimeHeightDeterministicDPDA& a, const automaton::RealTimeHeightDeterministicDPDA& b); + static int compare(const automaton::RealTimeHeightDeterministicDPDA < > & a, const automaton::RealTimeHeightDeterministicDPDA < > & b); static int compare(const automaton::RealTimeHeightDeterministicNPDA& a, const automaton::RealTimeHeightDeterministicNPDA& b); static int compare(const automaton::SinglePopDPDA& a, const automaton::SinglePopDPDA& b); static int compare(const automaton::SinglePopNPDA& a, const automaton::SinglePopNPDA& b); diff --git a/aconvert2/src/DotConverter.cpp b/aconvert2/src/DotConverter.cpp index 3fb4df69e3e13e4d2383580ed54f8ad43488d4f6..06dc595d0f81f06eb6b81dd23dfef4297db125a7 100644 --- a/aconvert2/src/DotConverter.cpp +++ b/aconvert2/src/DotConverter.cpp @@ -508,7 +508,7 @@ void DotConverter::convert(std::ostream& out, const automaton::VisiblyPushdownNP auto DotConverterVisiblyPushdownNPDA = DotConverter::RegistratorWrapper<void, automaton::VisiblyPushdownNPDA>(DotConverter::convert); -void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA& a) { +void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a) { out << "digraph automaton {\n"; out << "rankdir=LR;\n"; int cnt = 1; @@ -539,7 +539,7 @@ void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDet out << "}"; } -auto DotConverterRealTimeHeightDeterministicDPDA = DotConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA>(DotConverter::convert); +auto DotConverterRealTimeHeightDeterministicDPDA = DotConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA < > >(DotConverter::convert); void DotConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA& a) { out << "digraph automaton {\n"; @@ -1458,7 +1458,7 @@ void DotConverter::transitions(const automaton::VisiblyPushdownNPDA& pda, const } } -void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA& pda, const std::map<label::Label, int>& states, std::ostream& out) { +void DotConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { std::map<std::pair<int, int>, std::string> transitions; for (const auto& transition : pda.getCallTransitions()) { diff --git a/aconvert2/src/DotConverter.h b/aconvert2/src/DotConverter.h index 989542eda6a3c4ac04805d65901707bec1a09193..c12f3791841383924105d38b05d842aeb8d52cb9 100644 --- a/aconvert2/src/DotConverter.h +++ b/aconvert2/src/DotConverter.h @@ -34,7 +34,7 @@ class DotConverter : public std::SingleDispatchFirstStaticParam<DotConverter, vo static void transitions(const automaton::InputDrivenNPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::VisiblyPushdownDPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::VisiblyPushdownNPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicDPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); + static void transitions(const automaton::RealTimeHeightDeterministicDPDA < > & tm, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::RealTimeHeightDeterministicNPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::NPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::SinglePopNPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); @@ -56,7 +56,7 @@ public: static void convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a); static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA& a); static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA& a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA& a); + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a); static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA& a); static void convert(std::ostream& out, const automaton::NPDA < > & a); static void convert(std::ostream& out, const automaton::SinglePopNPDA& a); diff --git a/aconvert2/src/GasTexConverter.cpp b/aconvert2/src/GasTexConverter.cpp index cef284cf349cbf27182679d871f8650066d106fd..8e080221d3f7b6138472afe75f05c7253ad8cf66 100644 --- a/aconvert2/src/GasTexConverter.cpp +++ b/aconvert2/src/GasTexConverter.cpp @@ -542,7 +542,7 @@ void GasTexConverter::convert(std::ostream& out, const automaton::VisiblyPushdow auto GasTexConverterVisiblyPushdownNPDA = GasTexConverter::RegistratorWrapper<void, automaton::VisiblyPushdownNPDA>(GasTexConverter::convert); -void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA& a) { +void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a) { out << "\\begin{center}\n"; out << "\\begin{picture}(,)(,)\n"; @@ -581,7 +581,7 @@ void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeight out << "\\end{picture}\n"; } -auto GasTexConverterRealTimeHeightDeterministicDPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA>(GasTexConverter::convert); +auto GasTexConverterRealTimeHeightDeterministicDPDA = GasTexConverter::RegistratorWrapper<void, automaton::RealTimeHeightDeterministicDPDA < > >(GasTexConverter::convert); void GasTexConverter::convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA& a) { out << "\\begin{center}\n"; @@ -1174,7 +1174,7 @@ void GasTexConverter::transitions(const automaton::VisiblyPushdownNPDA& pda, std printTransitionMap(transitionMap, out); } -void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA& pda, std::ostream& out) { +void GasTexConverter::transitions(const automaton::RealTimeHeightDeterministicDPDA < > & pda, std::ostream& out) { std::map<std::pair<std::string, std::string>, std::string> transitionMap; for (const auto& transition : pda.getCallTransitions()) { diff --git a/aconvert2/src/GasTexConverter.h b/aconvert2/src/GasTexConverter.h index a5d4c10ef540ccf0786d0fac959bbcf09cef84c9..7732fec0db30915ca2ef79b8c26c4776613da6b5 100644 --- a/aconvert2/src/GasTexConverter.h +++ b/aconvert2/src/GasTexConverter.h @@ -35,7 +35,7 @@ class GasTexConverter : public std::SingleDispatchFirstStaticParam<GasTexConvert static void transitions(const automaton::InputDrivenNPDA < > & pda, std::ostream& out); static void transitions(const automaton::VisiblyPushdownDPDA& tm, std::ostream& out); static void transitions(const automaton::VisiblyPushdownNPDA& tm, std::ostream& out); - static void transitions(const automaton::RealTimeHeightDeterministicDPDA& tm, std::ostream& out); + static void transitions(const automaton::RealTimeHeightDeterministicDPDA < > & tm, std::ostream& out); static void transitions(const automaton::RealTimeHeightDeterministicNPDA& tm, std::ostream& out); static void transitions(const automaton::NPDA < > & pda, std::ostream& out); static void transitions(const automaton::SinglePopNPDA& tm, std::ostream& out); @@ -57,7 +57,7 @@ public: static void convert(std::ostream& out, const automaton::InputDrivenNPDA < > & a); static void convert(std::ostream& out, const automaton::VisiblyPushdownDPDA& a); static void convert(std::ostream& out, const automaton::VisiblyPushdownNPDA& a); - static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA& a); + static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicDPDA < > & a); static void convert(std::ostream& out, const automaton::RealTimeHeightDeterministicNPDA& a); static void convert(std::ostream& out, const automaton::NPDA < > & a); static void convert(std::ostream& out, const automaton::SinglePopNPDA& a); diff --git a/aconvert2/src/TikZConverter.cpp b/aconvert2/src/TikZConverter.cpp index 54aacc78d4f33fbd44abf90af409b7019cf99636..540ac8aa79b53ad641ef062743a3678c3adfc0ce 100644 --- a/aconvert2/src/TikZConverter.cpp +++ b/aconvert2/src/TikZConverter.cpp @@ -451,7 +451,7 @@ void TikZConverter::convert ( std::ostream & out, const automaton::VisiblyPushdo auto TikZConverterVisiblyPushdownNPDA = TikZConverter::RegistratorWrapper < void, automaton::VisiblyPushdownNPDA > ( TikZConverter::convert ); -void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA & a ) { +void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA < > & a ) { out << "\\begin{tikzpicture}\n"; int cnt = 1; @@ -478,7 +478,7 @@ void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeigh out << "\\end{tikzpicture}"; } -auto TikZConverterRealTimeHeightDeterministicDPDA = TikZConverter::RegistratorWrapper < void, automaton::RealTimeHeightDeterministicDPDA > ( TikZConverter::convert ); +auto TikZConverterRealTimeHeightDeterministicDPDA = TikZConverter::RegistratorWrapper < void, automaton::RealTimeHeightDeterministicDPDA < > > ( TikZConverter::convert ); void TikZConverter::convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicNPDA & a ) { out << "\\begin{tikzpicture}\n"; @@ -1504,7 +1504,7 @@ void TikZConverter::transitions ( const automaton::VisiblyPushdownNPDA & pda, co } } -void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicDPDA & pda, const std::map < label::Label, int > & states, std::ostream & out ) { +void TikZConverter::transitions ( const automaton::RealTimeHeightDeterministicDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { std::map < std::pair < int, int >, std::string > transitions; for ( const auto & transition : pda.getCallTransitions ( ) ) { diff --git a/aconvert2/src/TikZConverter.h b/aconvert2/src/TikZConverter.h index a5ad7e7dca1a0333143f422b83690e0a7902518a..c79bf9138091cb625d66d92c168de41612d7b86e 100644 --- a/aconvert2/src/TikZConverter.h +++ b/aconvert2/src/TikZConverter.h @@ -34,7 +34,7 @@ class TikZConverter : public std::SingleDispatchFirstStaticParam < TikZConverter static void transitions ( const automaton::InputDrivenNPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::VisiblyPushdownDPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::VisiblyPushdownNPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::RealTimeHeightDeterministicDPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); + static void transitions ( const automaton::RealTimeHeightDeterministicDPDA < > & tm, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::RealTimeHeightDeterministicNPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::NPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::SinglePopNPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); @@ -57,7 +57,7 @@ public: static void convert ( std::ostream & out, const automaton::InputDrivenNPDA < > & a ); static void convert ( std::ostream & out, const automaton::VisiblyPushdownDPDA & a ); static void convert ( std::ostream & out, const automaton::VisiblyPushdownNPDA & a ); - static void convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA & a ); + static void convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicDPDA < > & a ); static void convert ( std::ostream & out, const automaton::RealTimeHeightDeterministicNPDA & a ); static void convert ( std::ostream & out, const automaton::NPDA < > & a ); static void convert ( std::ostream & out, const automaton::SinglePopNPDA & a ); diff --git a/alib2algo/src/automaton/determinize/Determinize.cpp b/alib2algo/src/automaton/determinize/Determinize.cpp index d4c17a92b6327a3332de0921f3d282b0eaa6713a..2749ab8a39533807b62e6074e28a11bc97103d35 100644 --- a/alib2algo/src/automaton/determinize/Determinize.cpp +++ b/alib2algo/src/automaton/determinize/Determinize.cpp @@ -59,15 +59,15 @@ VisiblyPushdownDPDA Determinize::determinize(const automaton::VisiblyPushdownDPD auto DeterminizeVisiblyPushdownDPDA = Determinize::RegistratorWrapper<automaton::VisiblyPushdownDPDA, automaton::VisiblyPushdownDPDA>(Determinize::determinize); -RealTimeHeightDeterministicDPDA Determinize::determinize(const automaton::RealTimeHeightDeterministicDPDA& automaton) { +RealTimeHeightDeterministicDPDA < > Determinize::determinize(const automaton::RealTimeHeightDeterministicDPDA < > & automaton) { return automaton; } -auto DeterminizeRealTimeHeightDeterministicDPDA = Determinize::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA, automaton::RealTimeHeightDeterministicDPDA>(Determinize::determinize); +auto DeterminizeRealTimeHeightDeterministicDPDA = Determinize::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA < >, automaton::RealTimeHeightDeterministicDPDA < > >(Determinize::determinize); DPDA < > Determinize::determinize(const automaton::NPDA < > & automaton) { automaton::RealTimeHeightDeterministicNPDA rhpda = automaton::PDAToRHPDA::convert(automaton); - automaton::RealTimeHeightDeterministicDPDA dpda = Determinize::determinize(rhpda); + automaton::RealTimeHeightDeterministicDPDA < > dpda = Determinize::determinize(rhpda); return automaton::RHPDAToPDA::convert(dpda); } diff --git a/alib2algo/src/automaton/determinize/Determinize.h b/alib2algo/src/automaton/determinize/Determinize.h index 3fd3351808d37d9be0733c7efcc00bd383a6dfc5..84442090b5a170a92065e8211dfda7e5c17f5ca6 100644 --- a/alib2algo/src/automaton/determinize/Determinize.h +++ b/alib2algo/src/automaton/determinize/Determinize.h @@ -41,8 +41,8 @@ public: static automaton::VisiblyPushdownDPDA determinize(const automaton::VisiblyPushdownNPDA& nondeterministic); static automaton::InputDrivenDPDA < > determinize(const automaton::InputDrivenDPDA < > & nfa); static automaton::InputDrivenDPDA < > determinize(const automaton::InputDrivenNPDA < > & nfa); - static automaton::RealTimeHeightDeterministicDPDA determinize(const automaton::RealTimeHeightDeterministicDPDA& nondeterministic); - static automaton::RealTimeHeightDeterministicDPDA determinize(const automaton::RealTimeHeightDeterministicNPDA& nondeterministic); + static automaton::RealTimeHeightDeterministicDPDA < > determinize(const automaton::RealTimeHeightDeterministicDPDA < > & nondeterministic); + static automaton::RealTimeHeightDeterministicDPDA < > determinize(const automaton::RealTimeHeightDeterministicNPDA& nondeterministic); static automaton::DFTA determinize(const automaton::DFTA& nfta); static automaton::DFTA determinize(const automaton::NFTA& nfta); diff --git a/alib2algo/src/automaton/determinize/DeterminizeRHDPDAPart.cxx b/alib2algo/src/automaton/determinize/DeterminizeRHDPDAPart.cxx index 3487eff259087ac382c659c88a27706d09e64879..85600a0f8edeeef8197b0f10f082223768be8a31 100644 --- a/alib2algo/src/automaton/determinize/DeterminizeRHDPDAPart.cxx +++ b/alib2algo/src/automaton/determinize/DeterminizeRHDPDAPart.cxx @@ -18,7 +18,7 @@ namespace automaton { namespace determinize { -void addRetTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const alphabet::Symbol& dvpdaSymbol, const label::Label& to, automaton::RealTimeHeightDeterministicDPDA& deterministic) { +void addRetTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const alphabet::Symbol& dvpdaSymbol, const label::Label& to, automaton::RealTimeHeightDeterministicDPDA < > & deterministic) { deterministic.addState(from); deterministic.addState(to); deterministic.addPushdownStoreSymbol(dvpdaSymbol); @@ -26,7 +26,7 @@ void addRetTransition(const label::Label& from, const std::variant<string::Epsil deterministic.addReturnTransition(from, input, dvpdaSymbol, to); } -void retInitial(const label::Label& state, const alphabet::Symbol& pdaSymbol, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA& deterministic, std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions) { +void retInitial(const label::Label& state, const alphabet::Symbol& pdaSymbol, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA < > & deterministic, std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions) { std::set<std::pair<label::Label, label::Label>> S = unpackFromStateLabel(state); std::set<std::pair<label::Label, label::Label>> S1; @@ -55,7 +55,7 @@ void retInitial(const label::Label& state, const alphabet::Symbol& pdaSymbol, co } } -void ret(const label::Label& state, const alphabet::Symbol& pdaSymbol, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA& deterministic, std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions) { +void ret(const label::Label& state, const alphabet::Symbol& pdaSymbol, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA < > & deterministic, std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions) { std::set<std::pair<label::Label, label::Label>> S = unpackFromStateLabel(state); std::pair<std::set<std::pair<label::Label, label::Label>>, std::variant<string::Epsilon < >, alphabet::Symbol>> pdaSymbolUnpack = unpackFromDRHDPDAStackSymbol(pdaSymbol); const std::set<std::pair<label::Label, label::Label>>& S1 = pdaSymbolUnpack.first; @@ -111,7 +111,7 @@ void ret(const label::Label& state, const alphabet::Symbol& pdaSymbol, const std } } -void addCallTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to, const alphabet::Symbol& dvpdaSymbol, automaton::RealTimeHeightDeterministicDPDA& deterministic) { +void addCallTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to, const alphabet::Symbol& dvpdaSymbol, automaton::RealTimeHeightDeterministicDPDA < > & deterministic) { deterministic.addState(from); deterministic.addState(to); deterministic.addPushdownStoreSymbol(dvpdaSymbol); @@ -119,7 +119,7 @@ void addCallTransition(const label::Label& from, const std::variant<string::Epsi deterministic.addCallTransition(from, input, to, dvpdaSymbol); } -void call(const label::Label& state, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA& deterministic, std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions) { +void call(const label::Label& state, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA < > & deterministic, std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions) { std::set<std::pair<label::Label, label::Label>> S = unpackFromStateLabel(state); std::set<label::Label> R = retrieveDSubSet(S); @@ -147,14 +147,14 @@ void call(const label::Label& state, const std::variant<string::Epsilon < >, alp } } -void addLocalTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to, automaton::RealTimeHeightDeterministicDPDA& deterministic) { +void addLocalTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to, automaton::RealTimeHeightDeterministicDPDA < > & deterministic) { deterministic.addState(from); deterministic.addState(to); deterministic.addLocalTransition(from, input, to); } -void local(const label::Label& state, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA& deterministic, std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, label::Label>& rubbishLocalTransitions ) { +void local(const label::Label& state, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const automaton::RealTimeHeightDeterministicNPDA& nondeterministic, automaton::RealTimeHeightDeterministicDPDA < > & deterministic, std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, label::Label>& rubbishLocalTransitions ) { std::set<std::pair<label::Label, label::Label>> S = unpackFromStateLabel(state); std::set<std::pair<label::Label, label::Label>> S1; @@ -206,10 +206,10 @@ std::tuple<std::set<std::variant<string::Epsilon < >, alphabet::Symbol>>, std::s return std::make_tuple(std::move(local), std::move(call), std::move(ret)); } -automaton::RealTimeHeightDeterministicDPDA Determinize::determinize(const automaton::RealTimeHeightDeterministicNPDA& n) { +automaton::RealTimeHeightDeterministicDPDA < > Determinize::determinize(const automaton::RealTimeHeightDeterministicNPDA& n) { label::Label initialLabel = packToStateLabel(createIdentity(n.getInitialStates())); - automaton::RealTimeHeightDeterministicDPDA d(label::Label(initialLabel), n.getBottomOfTheStackSymbol()); + automaton::RealTimeHeightDeterministicDPDA < > d(label::Label(initialLabel), n.getBottomOfTheStackSymbol()); d.setInputAlphabet(n.getInputAlphabet()); std::set<label::Label> rubbishStates = {label::Label(packToStateLabel({}))}; @@ -276,7 +276,7 @@ automaton::RealTimeHeightDeterministicDPDA Determinize::determinize(const automa return d; } -auto DeterminizeRealTimeHeightDeterministicNPDA = Determinize::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA, automaton::RealTimeHeightDeterministicNPDA>( Determinize::determinize ); +auto DeterminizeRealTimeHeightDeterministicNPDA = Determinize::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA < >, automaton::RealTimeHeightDeterministicNPDA>( Determinize::determinize ); } /* namespace determinize */ diff --git a/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp b/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp index ed7872ce6f0e8c483887a76c171ee949fc9d46f1..bd5f6eb39a00be36888ff23d1d38378b86c71aeb 100644 --- a/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp +++ b/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp @@ -142,7 +142,7 @@ std::set<label::Label> existsDirtyState(const T& d, const std::set<label::Label> } template std::set<label::Label> existsDirtyState(const automaton::VisiblyPushdownDPDA& d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, alphabet::Symbol>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::pair<label::Label, alphabet::Symbol>, label::Label>& rubbishLocalTransitions, const automaton::VisiblyPushdownNPDA& n); -template std::set<label::Label> existsDirtyState(const automaton::RealTimeHeightDeterministicDPDA& d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, label::Label>& rubbishLocalTransitions, const automaton::RealTimeHeightDeterministicNPDA& n); +template std::set<label::Label> existsDirtyState(const automaton::RealTimeHeightDeterministicDPDA < > & d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, label::Label>& rubbishLocalTransitions, const automaton::RealTimeHeightDeterministicNPDA& n); template<class T> void localClosure(std::set<label::Label>& states, const std::set<label::Label>& oldStates, const T& d) { @@ -178,7 +178,7 @@ void localClosure(std::set<label::Label>& states, const std::set<label::Label>& } template void localClosure(std::set<label::Label>& states, const std::set<label::Label>& oldStates, const automaton::VisiblyPushdownDPDA& d); -template void localClosure(std::set<label::Label>& states, const std::set<label::Label>& oldStates, const automaton::RealTimeHeightDeterministicDPDA& d); +template void localClosure(std::set<label::Label>& states, const std::set<label::Label>& oldStates, const automaton::RealTimeHeightDeterministicDPDA < > & d); template<class T, class S, class R> std::set<std::pair<label::Label, alphabet::Symbol>> existsDirtyStateSymbol(const T& d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, S>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::tuple<label::Label, S, alphabet::Symbol>, label::Label>& rubbishReturnTransitions, const R& n) { @@ -235,7 +235,7 @@ break2: if(!originalPops) continue; } template std::set<std::pair<label::Label, alphabet::Symbol>> existsDirtyStateSymbol(const automaton::VisiblyPushdownDPDA& d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, alphabet::Symbol>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::tuple<label::Label, alphabet::Symbol, alphabet::Symbol>, label::Label>& rubbishReturnTransitions, const automaton::VisiblyPushdownNPDA& n); -template std::set<std::pair<label::Label, alphabet::Symbol>> existsDirtyStateSymbol(const automaton::RealTimeHeightDeterministicDPDA& d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions, const automaton::RealTimeHeightDeterministicNPDA& n); +template std::set<std::pair<label::Label, alphabet::Symbol>> existsDirtyStateSymbol(const automaton::RealTimeHeightDeterministicDPDA < > & d, const std::set<label::Label>& rubbishStates, const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& rubbishCallTransitions, const std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& rubbishReturnTransitions, const automaton::RealTimeHeightDeterministicNPDA& n); } /* namespace automaton */ diff --git a/alib2algo/src/automaton/run/Accept.cpp b/alib2algo/src/automaton/run/Accept.cpp index b5b5a709e0cf54768c70689fec4beeb543a2649e..acc5d969e8076233d1835782363f3e1b1fdbd130 100644 --- a/alib2algo/src/automaton/run/Accept.cpp +++ b/alib2algo/src/automaton/run/Accept.cpp @@ -89,13 +89,13 @@ bool Accept::accept ( const automaton::VisiblyPushdownDPDA & automaton, const st auto AcceptVisiblyPushdownDPDALinearString = Accept::RegistratorWrapper < bool, automaton::VisiblyPushdownDPDA, string::LinearString < > > ( Accept::accept ); -bool Accept::accept ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ) { +bool Accept::accept ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 0 > ( res ) && automaton.getFinalStates ( ).count ( std::get < 1 > ( res ) ); } -auto AcceptRealTimeHeightDeterministicDPDALinearString = Accept::RegistratorWrapper < bool, automaton::RealTimeHeightDeterministicDPDA, string::LinearString < > > ( Accept::accept ); +auto AcceptRealTimeHeightDeterministicDPDALinearString = Accept::RegistratorWrapper < bool, automaton::RealTimeHeightDeterministicDPDA < >, string::LinearString < > > ( Accept::accept ); bool Accept::accept ( const automaton::DPDA < > & automaton, const string::LinearString < > & string ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); diff --git a/alib2algo/src/automaton/run/Accept.h b/alib2algo/src/automaton/run/Accept.h index bbc2c47ba1e02b0cf0b9af3952166d22f59884de..eb8f7cca612672fb5b079638708ba2ffed3f9f3c 100644 --- a/alib2algo/src/automaton/run/Accept.h +++ b/alib2algo/src/automaton/run/Accept.h @@ -35,7 +35,7 @@ public: static bool accept ( const automaton::NFTA & automaton, const tree::RankedTree & tree ); static bool accept ( const automaton::InputDrivenDPDA < > & automaton, const string::LinearString < > & string ); static bool accept ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString < > & string ); - static bool accept ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ); + static bool accept ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ); static bool accept ( const automaton::DPDA < > & automaton, const string::LinearString < > & string ); static bool accept ( const automaton::NPDTA < > & automaton, const string::LinearString < > & string ); diff --git a/alib2algo/src/automaton/run/Occurrences.cpp b/alib2algo/src/automaton/run/Occurrences.cpp index 8ae79852a56c9ef834f0738b9b767448579d6f41..a4ba20c30bb085529708acf912b67615b0726c9d 100644 --- a/alib2algo/src/automaton/run/Occurrences.cpp +++ b/alib2algo/src/automaton/run/Occurrences.cpp @@ -65,13 +65,13 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::VisiblyPushdow auto OccurrencesVisiblyPushdownDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::VisiblyPushdownDPDA, string::LinearString < > > ( Occurrences::occurrences ); -std::set < unsigned > Occurrences::occurrences ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ) { +std::set < unsigned > Occurrences::occurrences ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); return std::get < 2 > ( res ); } -auto OccurrencesRealTimeHeightDeterministicDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::RealTimeHeightDeterministicDPDA, string::LinearString < > > ( Occurrences::occurrences ); +auto OccurrencesRealTimeHeightDeterministicDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::RealTimeHeightDeterministicDPDA < >, string::LinearString < > > ( Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::DPDA < > & automaton, const string::LinearString < > & string ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); diff --git a/alib2algo/src/automaton/run/Occurrences.h b/alib2algo/src/automaton/run/Occurrences.h index 2686b2f144550948ec5e97be9012e5e76605f20a..149adec1d705caef1a8537e7cd6ade6b883ef649 100644 --- a/alib2algo/src/automaton/run/Occurrences.h +++ b/alib2algo/src/automaton/run/Occurrences.h @@ -33,7 +33,7 @@ public: static std::set < unsigned > occurrences ( const automaton::DFTA & automaton, const tree::RankedTree & tree ); static std::set < unsigned > occurrences ( const automaton::InputDrivenDPDA < > & automaton, const string::LinearString < > & string ); static std::set < unsigned > occurrences ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString < > & string ); - static std::set < unsigned > occurrences ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ); + static std::set < unsigned > occurrences ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ); static std::set < unsigned > occurrences ( const automaton::DPDA < > & automaton, const string::LinearString < > & string ); }; diff --git a/alib2algo/src/automaton/run/Result.cpp b/alib2algo/src/automaton/run/Result.cpp index 28c30a021255a727ec2b1f92dd248fe378229edb..7840b5a070296278013ea6ee381e6f85f82b91fe 100644 --- a/alib2algo/src/automaton/run/Result.cpp +++ b/alib2algo/src/automaton/run/Result.cpp @@ -65,7 +65,7 @@ label::Label Result::result ( const automaton::VisiblyPushdownDPDA & automaton, auto ResultVisiblyPushdownDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::VisiblyPushdownDPDA, string::LinearString < > > ( Result::result ); -label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string, const label::Label & failLabel ) { +label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); if ( std::get < 0 > ( res ) ) return std::get < 1 > ( res ); @@ -73,7 +73,7 @@ label::Label Result::result ( const automaton::RealTimeHeightDeterministicDPDA & return failLabel; } -auto ResultRealTimeHeightDeterministicDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::RealTimeHeightDeterministicDPDA, string::LinearString < > > ( Result::result ); +auto ResultRealTimeHeightDeterministicDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::RealTimeHeightDeterministicDPDA < >, string::LinearString < > > ( Result::result ); label::Label Result::result ( const automaton::DPDA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel ) { std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > res = Run::calculateState ( automaton, string ); diff --git a/alib2algo/src/automaton/run/Result.h b/alib2algo/src/automaton/run/Result.h index 171eaf86f5e923cf8beaeab3366383eb23de3bd6..aa806d9e2db1bb7f86ebb13c76af888cd6cf83d2 100644 --- a/alib2algo/src/automaton/run/Result.h +++ b/alib2algo/src/automaton/run/Result.h @@ -33,7 +33,7 @@ public: static label::Label result ( const automaton::DFTA & automaton, const tree::RankedTree & tree, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); static label::Label result ( const automaton::InputDrivenDPDA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); static label::Label result ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); - static label::Label result ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); + static label::Label result ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); static label::Label result ( const automaton::DPDA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); }; diff --git a/alib2algo/src/automaton/run/Run.cpp b/alib2algo/src/automaton/run/Run.cpp index e5363fe8ea5fc9b409fba02fba34623710f4b437..f9d51305bdabac37a0907fbda44a419ccd9d8289 100644 --- a/alib2algo/src/automaton/run/Run.cpp +++ b/alib2algo/src/automaton/run/Run.cpp @@ -331,7 +331,7 @@ std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::S // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ) { +std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ) { label::Label state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getBottomOfTheStackSymbol ( ) diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h index 0a8072c25266e826f8faae4945b07feb9221bbe1..3882dacd7fa283597268fccc54f44020941aed22 100644 --- a/alib2algo/src/automaton/run/Run.h +++ b/alib2algo/src/automaton/run/Run.h @@ -31,7 +31,7 @@ public: static std::tuple < bool, std::set < label::Label >, std::set < unsigned > > calculateStates ( const automaton::NFTA & automaton, const tree::RankedTree & tree ); static std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::InputDrivenDPDA < > & automaton, const string::LinearString < > & string ); static std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::VisiblyPushdownDPDA & automaton, const string::LinearString < > & string ); - static std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const string::LinearString < > & string ); + static std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::RealTimeHeightDeterministicDPDA < > & automaton, const string::LinearString < > & string ); static std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > calculateState ( const automaton::DPDA < > & automaton, const string::LinearString < > & string ); static std::tuple < bool, std::set < label::Label >, std::set < std::vector < alphabet::Symbol > > > calculateStates ( const automaton::NPDTA < > & automaton, const string::LinearString < > & string ); }; diff --git a/alib2algo/src/automaton/simplify/Rename.cpp b/alib2algo/src/automaton/simplify/Rename.cpp index 1679f75d97243a1f80d8ff41f760ca4b38b8492e..51fbff6b7d0493c520208265b91ab111ea453b4e 100644 --- a/alib2algo/src/automaton/simplify/Rename.cpp +++ b/alib2algo/src/automaton/simplify/Rename.cpp @@ -235,7 +235,7 @@ automaton::VisiblyPushdownDPDA Rename::rename(const automaton::VisiblyPushdownDP auto RenameVisiblyPushdownDPDA = Rename::RegistratorWrapper<automaton::VisiblyPushdownDPDA, automaton::VisiblyPushdownDPDA>(Rename::rename); -automaton::RealTimeHeightDeterministicDPDA Rename::rename(const automaton::RealTimeHeightDeterministicDPDA& pda) { +automaton::RealTimeHeightDeterministicDPDA < > Rename::rename(const automaton::RealTimeHeightDeterministicDPDA < > & pda) { int counterState = 0; std::map<label::Label, int > renamingDataState; int counterSymbol = 0; @@ -248,7 +248,7 @@ automaton::RealTimeHeightDeterministicDPDA Rename::rename(const automaton::RealT for(const alphabet::Symbol & symbol : pda.getPushdownStoreAlphabet()) renamingDataSymbol.insert(std::make_pair(symbol, counterSymbol++)); - automaton::RealTimeHeightDeterministicDPDA result(label::labelFrom(renamingDataState.find(pda.getInitialState())->second), alphabet::symbolFrom(renamingDataSymbol.find(pda.getBottomOfTheStackSymbol())->second)); + automaton::RealTimeHeightDeterministicDPDA < > result(label::labelFrom(renamingDataState.find(pda.getInitialState())->second), alphabet::symbolFrom(renamingDataSymbol.find(pda.getBottomOfTheStackSymbol())->second)); result.setInputAlphabet(pda.getInputAlphabet()); @@ -278,7 +278,7 @@ automaton::RealTimeHeightDeterministicDPDA Rename::rename(const automaton::RealT return result; } -auto RenameRealTimeHeightDeterministicDPDA = Rename::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA, automaton::RealTimeHeightDeterministicDPDA>(Rename::rename); +auto RenameRealTimeHeightDeterministicDPDA = Rename::RegistratorWrapper<automaton::RealTimeHeightDeterministicDPDA < >, automaton::RealTimeHeightDeterministicDPDA < > >(Rename::rename); } /* namespace simplify */ diff --git a/alib2algo/src/automaton/simplify/Rename.h b/alib2algo/src/automaton/simplify/Rename.h index 540f99726451a2115ed4e71b87d7eb4d8c573e31..937a6f93c5cf60832bcdc32d4e4e0fa9ae0cfddf 100644 --- a/alib2algo/src/automaton/simplify/Rename.h +++ b/alib2algo/src/automaton/simplify/Rename.h @@ -33,7 +33,7 @@ public: static automaton::SinglePopDPDA rename(const automaton::SinglePopDPDA& pda); static automaton::InputDrivenDPDA < > rename(const automaton::InputDrivenDPDA < > & pda); static automaton::VisiblyPushdownDPDA rename(const automaton::VisiblyPushdownDPDA& pda); - static automaton::RealTimeHeightDeterministicDPDA rename(const automaton::RealTimeHeightDeterministicDPDA& pda); + static automaton::RealTimeHeightDeterministicDPDA < > rename(const automaton::RealTimeHeightDeterministicDPDA < > & pda); }; } /* namespace simplify */ diff --git a/alib2algo/src/automaton/transform/PDAToRHPDA.cpp b/alib2algo/src/automaton/transform/PDAToRHPDA.cpp index 1643a25893b1efb287f06b372cb31df73e48c2a9..6851197636e04f90bb8c83297086ad0e4b7d7dd2 100644 --- a/alib2algo/src/automaton/transform/PDAToRHPDA.cpp +++ b/alib2algo/src/automaton/transform/PDAToRHPDA.cpp @@ -22,11 +22,11 @@ namespace automaton { -automaton::RealTimeHeightDeterministicDPDA PDAToRHPDA::convert ( const automaton::RealTimeHeightDeterministicDPDA & pda ) { +automaton::RealTimeHeightDeterministicDPDA < > PDAToRHPDA::convert ( const automaton::RealTimeHeightDeterministicDPDA < > & pda ) { return pda; } -auto PDAToRHPDARealTimeHeightDeterministicDPDA = PDAToRHPDA::RegistratorWrapper < automaton::RealTimeHeightDeterministicDPDA, automaton::RealTimeHeightDeterministicDPDA > ( PDAToRHPDA::convert ); +auto PDAToRHPDARealTimeHeightDeterministicDPDA = PDAToRHPDA::RegistratorWrapper < automaton::RealTimeHeightDeterministicDPDA < >, automaton::RealTimeHeightDeterministicDPDA < > > ( PDAToRHPDA::convert ); automaton::RealTimeHeightDeterministicNPDA PDAToRHPDA::convert ( const automaton::RealTimeHeightDeterministicNPDA & pda ) { return pda; @@ -34,10 +34,10 @@ automaton::RealTimeHeightDeterministicNPDA PDAToRHPDA::convert ( const automaton auto PDAToRHPDARealTimeHeightDeterministicNPDA = PDAToRHPDA::RegistratorWrapper < automaton::RealTimeHeightDeterministicNPDA, automaton::RealTimeHeightDeterministicNPDA > ( PDAToRHPDA::convert ); -automaton::RealTimeHeightDeterministicDPDA PDAToRHPDA::convert ( const automaton::DPDA < > & pda ) { +automaton::RealTimeHeightDeterministicDPDA < > PDAToRHPDA::convert ( const automaton::DPDA < > & pda ) { label::Label q0 = label::createUniqueLabel ( label::InitialStateLabel::INITIAL_STATE_LABEL, pda.getStates ( ) ); - RealTimeHeightDeterministicDPDA res ( q0, alphabet::Symbol { alphabet::BottomOfTheStackSymbol::BOTTOM_OF_THE_STACK } ); + RealTimeHeightDeterministicDPDA < > res ( q0, alphabet::Symbol { alphabet::BottomOfTheStackSymbol::BOTTOM_OF_THE_STACK } ); res.setInputAlphabet ( pda.getInputAlphabet ( ) ); @@ -108,7 +108,7 @@ automaton::RealTimeHeightDeterministicDPDA PDAToRHPDA::convert ( const automaton return res; } -auto PDAToRHPDADPDA = PDAToRHPDA::RegistratorWrapper < automaton::RealTimeHeightDeterministicDPDA, automaton::DPDA < > > ( PDAToRHPDA::convert ); +auto PDAToRHPDADPDA = PDAToRHPDA::RegistratorWrapper < automaton::RealTimeHeightDeterministicDPDA < >, automaton::DPDA < > > ( PDAToRHPDA::convert ); automaton::RealTimeHeightDeterministicNPDA PDAToRHPDA::convert ( const automaton::NPDA < > & pda ) { RealTimeHeightDeterministicNPDA res ( alphabet::Symbol { alphabet::BottomOfTheStackSymbol::BOTTOM_OF_THE_STACK } ); @@ -192,6 +192,6 @@ automaton::Automaton PDAToRHPDA::convert ( const Automaton & automaton ) { namespace alib { -auto RealTimeHeightDeterministicDPDAFromDPDA = castApi::CastRegister < automaton::RealTimeHeightDeterministicDPDA, automaton::DPDA < > > ( automaton::PDAToRHPDA::convert ); +auto RealTimeHeightDeterministicDPDAFromDPDA = castApi::CastRegister < automaton::RealTimeHeightDeterministicDPDA < >, automaton::DPDA < > > ( automaton::PDAToRHPDA::convert ); auto RealTimeHeightDeterministicNPDAFromNPDA = castApi::CastRegister < automaton::RealTimeHeightDeterministicNPDA, automaton::NPDA < > > ( automaton::PDAToRHPDA::convert ); } diff --git a/alib2algo/src/automaton/transform/PDAToRHPDA.h b/alib2algo/src/automaton/transform/PDAToRHPDA.h index d1cf7b56160382253ccff92eed71dfc7c6ed0013..0bf2aa4522c34bc3f2e53d9ecf597560e4b1c0a7 100644 --- a/alib2algo/src/automaton/transform/PDAToRHPDA.h +++ b/alib2algo/src/automaton/transform/PDAToRHPDA.h @@ -20,8 +20,8 @@ namespace automaton { class PDAToRHPDA : public std::SingleDispatch<PDAToRHPDA, automaton::Automaton, const automaton::AutomatonBase &> { public: - static automaton::RealTimeHeightDeterministicDPDA convert( const automaton::RealTimeHeightDeterministicDPDA & pda); - static automaton::RealTimeHeightDeterministicDPDA convert( const automaton::DPDA < > & pda); + static automaton::RealTimeHeightDeterministicDPDA < > convert( const automaton::RealTimeHeightDeterministicDPDA < > & pda); + static automaton::RealTimeHeightDeterministicDPDA < > convert( const automaton::DPDA < > & pda); static automaton::RealTimeHeightDeterministicNPDA convert( const automaton::RealTimeHeightDeterministicNPDA & pda); static automaton::RealTimeHeightDeterministicNPDA convert( const automaton::NPDA < > & pda); diff --git a/alib2algo/src/automaton/transform/RHPDAToPDA.cpp b/alib2algo/src/automaton/transform/RHPDAToPDA.cpp index 77721ad3a3cc4197013d68a1891b8b97509778e4..f2869678e7a427c772987e01129cb517494fb19b 100644 --- a/alib2algo/src/automaton/transform/RHPDAToPDA.cpp +++ b/alib2algo/src/automaton/transform/RHPDAToPDA.cpp @@ -53,7 +53,7 @@ void constructTransitions ( const std::tuple < label::Label, alphabet::Symbol, s } } -automaton::DPDA < > RHPDAToPDA::convert ( const automaton::RealTimeHeightDeterministicDPDA & pda ) { +automaton::DPDA < > RHPDAToPDA::convert ( const automaton::RealTimeHeightDeterministicDPDA < > & pda ) { std::map < std::tuple < label::Label, alphabet::Symbol, std::vector < alphabet::Symbol > >, std::set < std::pair < label::Label, std::vector < alphabet::Symbol > > > > readingTransitions; std::map < label::Label, std::set < std::tuple < std::vector < alphabet::Symbol >, label::Label, std::vector < alphabet::Symbol > > > > epsilonTransitions; @@ -153,7 +153,7 @@ automaton::DPDA < > RHPDAToPDA::convert ( const automaton::RealTimeHeightDetermi return res; } -auto RHPDAToPDARealTimeHeightDeterministicDPDA = RHPDAToPDA::RegistratorWrapper < automaton::DPDA < >, automaton::RealTimeHeightDeterministicDPDA > ( RHPDAToPDA::convert ); +auto RHPDAToPDARealTimeHeightDeterministicDPDA = RHPDAToPDA::RegistratorWrapper < automaton::DPDA < >, automaton::RealTimeHeightDeterministicDPDA < > > ( RHPDAToPDA::convert ); // This may not work correctly -- generation of initial state and initial symbol automaton::NPDA < > RHPDAToPDA::convert ( const automaton::RealTimeHeightDeterministicNPDA & pda ) { @@ -279,6 +279,6 @@ automaton::Automaton RHPDAToPDA::convert ( const Automaton & automaton ) { namespace alib { -auto DPDAFromRealTimeHeightDeterministicNPDA = castApi::CastRegister < automaton::DPDA < >, automaton::RealTimeHeightDeterministicDPDA > ( automaton::RHPDAToPDA::convert ); +auto DPDAFromRealTimeHeightDeterministicNPDA = castApi::CastRegister < automaton::DPDA < >, automaton::RealTimeHeightDeterministicDPDA < > > ( automaton::RHPDAToPDA::convert ); auto NPDAFromRealTimeHeightDeterministicNPDA = castApi::CastRegister < automaton::NPDA < >, automaton::RealTimeHeightDeterministicNPDA > ( automaton::RHPDAToPDA::convert ); } diff --git a/alib2algo/src/automaton/transform/RHPDAToPDA.h b/alib2algo/src/automaton/transform/RHPDAToPDA.h index c695bbee4bfee00cbc8c46144d538bcc8df67885..48fd5a6b5300a93a7eb60f734e586a04aa3a2e0e 100644 --- a/alib2algo/src/automaton/transform/RHPDAToPDA.h +++ b/alib2algo/src/automaton/transform/RHPDAToPDA.h @@ -20,7 +20,7 @@ namespace automaton { class RHPDAToPDA : public std::SingleDispatch<RHPDAToPDA, automaton::Automaton, const automaton::AutomatonBase &> { public: - static automaton::DPDA < > convert( const automaton::RealTimeHeightDeterministicDPDA & pda); + static automaton::DPDA < > convert( const automaton::RealTimeHeightDeterministicDPDA < > & pda); static automaton::DPDA < > convert( const automaton::DPDA < > & pda); static automaton::NPDA < > convert( const automaton::RealTimeHeightDeterministicNPDA & pda); static automaton::NPDA < > convert( const automaton::NPDA < > & pda); diff --git a/alib2data/src/automaton/AutomatonFeatures.h b/alib2data/src/automaton/AutomatonFeatures.h index 7c6077a22c71dcb706a98a95f5f516c78d600ddb..5cd3d6bf23be004a9ff93dbce6db366dc8f017f9 100644 --- a/alib2data/src/automaton/AutomatonFeatures.h +++ b/alib2data/src/automaton/AutomatonFeatures.h @@ -60,6 +60,7 @@ template<class SymbolType = typename alphabet::Symbol, class StateType = typenam class InputDrivenNPDA; class VisiblyPushdownDPDA; class VisiblyPushdownNPDA; +template<class SymbolType = typename alphabet::Symbol, class EpsilonType = typename string::Epsilon < SymbolType >, class StateType = typename label::Label > class RealTimeHeightDeterministicDPDA; class RealTimeHeightDeterministicNPDA; template<class SymbolType = typename alphabet::Symbol, class EpsilonType = typename string::Epsilon < SymbolType >, class StateType = typename label::Label > diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp index 55a14c9e9e4fcce152dfaeb7f75b5466f548521b..77cc92db593853b9bbb25448fcb20d0afefed91d 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp @@ -6,436 +6,16 @@ */ #include "RealTimeHeightDeterministicDPDA.h" -#include <algorithm> -#include <sstream> - -#include <sax/FromXMLParserHelper.h> -#include "../common/AutomatonFromXMLParser.h" -#include "../common/AutomatonToXMLComposer.h" #include "../Automaton.h" #include <object/Object.h> #include <XmlApi.hpp> #include <cast/CastApi.hpp> -namespace automaton { - -RealTimeHeightDeterministicDPDA::RealTimeHeightDeterministicDPDA ( std::set < label::Label > states, std::set < alphabet::Symbol > inputAlphabet, std::set < alphabet::Symbol > pushdownStoreAlphabet, label::Label initialState, alphabet::Symbol bottomOfTheStackSymbol, std::set < label::Label > finalStates ) : std::Components < RealTimeHeightDeterministicDPDA, alphabet::Symbol, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < BottomOfTheStackSymbol >, label::Label, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ) ), std::make_tuple ( std::move ( bottomOfTheStackSymbol ) ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { -} - -RealTimeHeightDeterministicDPDA::RealTimeHeightDeterministicDPDA(label::Label initialState, alphabet::Symbol bottomOfTheStackSymbol) : RealTimeHeightDeterministicDPDA ( std::set < label::Label > { initialState }, std::set < alphabet::Symbol > { }, std::set < alphabet::Symbol > { bottomOfTheStackSymbol }, initialState, bottomOfTheStackSymbol, std::set < label::Label > { }) { -} - -AutomatonBase* RealTimeHeightDeterministicDPDA::clone() const { - return new RealTimeHeightDeterministicDPDA(*this); -} - -AutomatonBase* RealTimeHeightDeterministicDPDA::plunder() && { - return new RealTimeHeightDeterministicDPDA(std::move(*this)); -} - -bool RealTimeHeightDeterministicDPDA::addCallTransition(label::Label from, std::variant<string::Epsilon < >, alphabet::Symbol> input, label::Label to, alphabet::Symbol push) { - if (!getStates().count(from)) { - throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); - } - - if (input.is<alphabet::Symbol>() && !getInputAlphabet().count(input.get<alphabet::Symbol>())) { - throw AutomatonException("Input symbol \"" + std::to_string ( input.get<alphabet::Symbol>() ) + "\" doesn't exist."); - } - - if (!getStates().count(to)) { - throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); - } - - if (!getPushdownStoreAlphabet().count(push)) { - throw AutomatonException("Pushdown store symbol \"" + std::to_string ( push ) + "\" doesn't exist."); - } - - if(getBottomOfTheStackSymbol() == push) - throw AutomatonException("Pushdown store symbol \"" + std::to_string ( push ) + "\" is bottom of the stack."); - - std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>> key(std::move(from), std::move(input)); - std::pair<label::Label, alphabet::Symbol> value = std::make_pair(std::move(to), std::move(push)); - - if(callTransitions.find(key) != callTransitions.end() && callTransitions.find(key)->second == value) - return false; - - if(key.second.is<string::Epsilon < >>()) { - for(const auto& transition : callTransitions) - if(transition.first.first == key.first ) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == key.first) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == key.first) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( from ) + "\" when other transitions are present."); - } else { - for(const auto& transition : callTransitions) - if(transition.first.first == key.first && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).is<string::Epsilon < >>() || std::get<1>(transition.first) == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == key.first && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - } - - callTransitions.insert(std::make_pair(std::move(key), std::move(value))); - return true; -} - -bool RealTimeHeightDeterministicDPDA::addCallTransition(label::Label from, label::Label to, alphabet::Symbol push) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push)); -} - -bool RealTimeHeightDeterministicDPDA::addCallTransition(label::Label from, alphabet::Symbol input, label::Label to, alphabet::Symbol push) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(std::move(input)); - return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push)); -} - -bool RealTimeHeightDeterministicDPDA::addReturnTransition(label::Label from, std::variant<string::Epsilon < >, alphabet::Symbol> input, alphabet::Symbol pop, label::Label to) { - if (!getStates().count(from)) { - throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); - } - - if (input.is<alphabet::Symbol>() && !getInputAlphabet().count(input.get<alphabet::Symbol>())) { - throw AutomatonException("Input symbol \"" + std::to_string ( input.get<alphabet::Symbol>() ) + "\" doesn't exist."); - } - - if (!getStates().count(to)) { - throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); - } - - if (!getPushdownStoreAlphabet().count(pop)) { - throw AutomatonException("Pushdown store symbol \"" + std::to_string ( pop ) + "\" doesn't exist."); - } - - std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol> key(std::move(from), std::move(input), std::move(pop)); - - if(returnTransitions.find(key) != returnTransitions.end() && returnTransitions.find(key)->second == to) - return false; - - if(std::get<1>(key).is<string::Epsilon < >>()) { - for(const auto& transition : callTransitions) - if(transition.first.first == std::get<0>(key) ) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == std::get<0>(key) && std::get<2>(transition.first) == std::get<2>(key)) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == std::get<0>(key)) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); - } else { - for(const auto& transition : callTransitions) - if(transition.first.first == std::get<0>(key) && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == std::get<1>(key))) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == std::get<0>(key) && (std::get<1>(transition.first).is<string::Epsilon < >>() || std::get<1>(transition.first) == std::get<1>(key)) && std::get<2>(transition.first) == std::get<2>(key)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == std::get<0>(key) && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == std::get<1>(key))) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); - } - - returnTransitions.insert(std::make_pair(std::move(key), std::move(to))); - return true; -} - -bool RealTimeHeightDeterministicDPDA::addReturnTransition(label::Label from, alphabet::Symbol pop, label::Label to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to)); -} - -bool RealTimeHeightDeterministicDPDA::addReturnTransition(label::Label from, alphabet::Symbol input, alphabet::Symbol pop, label::Label to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(std::move(input)); - return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to)); -} - -bool RealTimeHeightDeterministicDPDA::addLocalTransition(label::Label from, std::variant<string::Epsilon < >, alphabet::Symbol> input, label::Label to) { - if (!getStates().count(from)) { - throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); - } - - if (input.is<alphabet::Symbol>() && !getInputAlphabet().count(input.get<alphabet::Symbol>())) { - throw AutomatonException("Input symbol \"" + std::to_string ( input.get<alphabet::Symbol>() ) + "\" doesn't exist."); - } - - if (!getStates().count(to)) { - throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); - } - - std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>> key(std::move(from), std::move(input)); - - if(localTransitions.find(key) != localTransitions.end() && localTransitions.find(key)->second == to) - return false; - - if(key.second.is<string::Epsilon < >>()) { - for(const auto& transition : callTransitions) - if(transition.first.first == key.first ) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == key.first) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == key.first) - throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); - } else { - for(const auto& transition : callTransitions) - if(transition.first.first == key.first && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - - for(const auto& transition : returnTransitions) - if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).is<string::Epsilon < >>() || std::get<1>(transition.first) == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - - for(const auto& transition : localTransitions) - if(transition.first.first == key.first && (transition.first.second.is<string::Epsilon < >>() || transition.first.second == key.second)) - throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); - } - - localTransitions.insert(std::make_pair(std::move(key), std::move(to))); - return true; -} - -bool RealTimeHeightDeterministicDPDA::addLocalTransition(label::Label from, label::Label to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to)); -} - -bool RealTimeHeightDeterministicDPDA::addLocalTransition(label::Label from, alphabet::Symbol input, label::Label to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(std::move(input)); - return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to)); -} - -bool RealTimeHeightDeterministicDPDA::removeCallTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to, const alphabet::Symbol& push) { - std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>> key(from, input); - std::pair<label::Label, alphabet::Symbol> value = std::make_pair(to, push); - - if (callTransitions.find(key) == callTransitions.end()) - return false; - - if(callTransitions.find(key)->second != value) - throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); - - callTransitions.erase(key); - return true; -} - -bool RealTimeHeightDeterministicDPDA::removeCallTransition(const label::Label& from, const label::Label& to, const alphabet::Symbol& push) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return removeCallTransition(from, inputVariant, to, push); -} - -bool RealTimeHeightDeterministicDPDA::removeCallTransition(const label::Label& from, const alphabet::Symbol& input, const label::Label& to, const alphabet::Symbol& push) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(input); - return removeCallTransition(from, inputVariant, to, push); -} - -bool RealTimeHeightDeterministicDPDA::removeReturnTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const alphabet::Symbol& pop, const label::Label& to) { - std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol> key(from, input, pop); - - if (returnTransitions.find(key) == returnTransitions.end()) - return false; - - if(returnTransitions.find(key)->second != to) - throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); - - returnTransitions.erase(key); - return true; -} - -bool RealTimeHeightDeterministicDPDA::removeReturnTransition(const label::Label& from, const alphabet::Symbol& pop, const label::Label& to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return removeReturnTransition(from, inputVariant, pop, to); -} - -bool RealTimeHeightDeterministicDPDA::removeReturnTransition(const label::Label& from, const alphabet::Symbol& input, const alphabet::Symbol& pop, const label::Label& to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(input); - return removeReturnTransition(from, inputVariant, pop, to); -} - -bool RealTimeHeightDeterministicDPDA::removeLocalTransition(const label::Label& from, const std::variant<string::Epsilon < >, alphabet::Symbol>& input, const label::Label& to) { - std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>> key(from, input); - - if (localTransitions.find(key) == localTransitions.end()) - return false; - - if(localTransitions.find(key)->second != to) - throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); - - localTransitions.erase(key); - return true; -} - -bool RealTimeHeightDeterministicDPDA::removeLocalTransition(const label::Label& from, const label::Label& to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(string::Epsilon < >::EPSILON); - return removeLocalTransition(from, inputVariant, to); -} - -bool RealTimeHeightDeterministicDPDA::removeLocalTransition(const label::Label& from, const alphabet::Symbol& input, const label::Label& to) { - std::variant<string::Epsilon < >, alphabet::Symbol> inputVariant(input); - return removeLocalTransition(from, inputVariant, to); -} - -const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& RealTimeHeightDeterministicDPDA::getCallTransitions() const { - return callTransitions; -} - -const std::map<std::tuple<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& RealTimeHeightDeterministicDPDA::getReturnTransitions() const { - return returnTransitions; -} - -const std::map<std::pair<label::Label, std::variant<string::Epsilon < >, alphabet::Symbol>>, label::Label>& RealTimeHeightDeterministicDPDA::getLocalTransitions() const { - return localTransitions; -} - -int RealTimeHeightDeterministicDPDA::compare(const RealTimeHeightDeterministicDPDA& other) const { - auto first = std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions); - auto second = std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions); - - std::compare<decltype(first)> comp; - return comp(first, second); -} - -void RealTimeHeightDeterministicDPDA::operator>>(std::ostream& out) const { - out << "(RealTimeHeightDeterministicDPDA " - << "states = " << getStates() - << "inputAlphabet = " << getInputAlphabet() - << "initialState = " << getInitialState() - << "finalStates = " << getFinalStates() - << "pushdownStoreAlphabet = " << getPushdownStoreAlphabet() - << "bottomOfTheStackSymbol = " << getBottomOfTheStackSymbol() - << "callTransitions = " << callTransitions - << "returnTransitions = " << returnTransitions - << "localTransitions = " << localTransitions - << ")"; -} - -RealTimeHeightDeterministicDPDA::operator std::string () const { - std::stringstream ss; - ss << *this; - return ss.str(); -} - -RealTimeHeightDeterministicDPDA RealTimeHeightDeterministicDPDA::parse(std::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, RealTimeHeightDeterministicDPDA::getXmlTagName()); - - std::set<label::Label> states = AutomatonFromXMLParser::parseStates<label::Label>(input); - std::set<alphabet::Symbol> inputSymbols = AutomatonFromXMLParser::parseInputAlphabet<alphabet::Symbol>(input); - std::set<alphabet::Symbol> stackSymbols = AutomatonFromXMLParser::parsePushdownStoreAlphabet<alphabet::Symbol>(input); - label::Label initialState = AutomatonFromXMLParser::parseInitialState<label::Label>(input); - alphabet::Symbol bottomOfTheStackSymbol = AutomatonFromXMLParser::parseBottomOfTheStackSymbol<alphabet::Symbol>(input); - std::set<label::Label> finalStates = AutomatonFromXMLParser::parseFinalStates<label::Label>(input); - - RealTimeHeightDeterministicDPDA automaton(std::move(initialState), std::move(bottomOfTheStackSymbol)); - automaton.setStates(std::move(states)); - automaton.setInputAlphabet(std::move(inputSymbols)); - automaton.setPushdownStoreAlphabet(std::move(stackSymbols)); - automaton.setFinalStates(std::move(finalStates)); - - AutomatonFromXMLParser::parseTransitions<RealTimeHeightDeterministicDPDA>(input, automaton); - - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, RealTimeHeightDeterministicDPDA::getXmlTagName()); - return automaton; -} - -void RealTimeHeightDeterministicDPDA::parseTransition(std::deque<sax::Token>::iterator& input, RealTimeHeightDeterministicDPDA& automaton) { - if(sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, "callTransition")) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "callTransition"); - label::Label from = AutomatonFromXMLParser::parseTransitionFrom<label::Label>(input); - std::variant<string::Epsilon < >, alphabet::Symbol> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<string::Epsilon < >,alphabet::Symbol>(input); - label::Label to = AutomatonFromXMLParser::parseTransitionTo<label::Label>(input); - alphabet::Symbol push = AutomatonFromXMLParser::parseTransitionSinglePush<alphabet::Symbol>(input); - - automaton.addCallTransition(std::move(from), std::move(inputSymbol), std::move(to), std::move(push)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "callTransition"); - } else if(sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, "returnTransition")) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "returnTransition"); - label::Label from = AutomatonFromXMLParser::parseTransitionFrom<label::Label>(input); - std::variant<string::Epsilon < >, alphabet::Symbol> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<string::Epsilon < >,alphabet::Symbol>(input); - alphabet::Symbol pop = AutomatonFromXMLParser::parseTransitionSinglePop<alphabet::Symbol>(input); - label::Label to = AutomatonFromXMLParser::parseTransitionTo<label::Label>(input); - - automaton.addReturnTransition(std::move(from), std::move(inputSymbol), std::move(pop), std::move(to)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "returnTransition"); - } else { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "localTransition"); - label::Label from = AutomatonFromXMLParser::parseTransitionFrom<label::Label>(input); - std::variant<string::Epsilon < >, alphabet::Symbol> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<string::Epsilon < >,alphabet::Symbol>(input); - label::Label to = AutomatonFromXMLParser::parseTransitionTo<label::Label>(input); - - automaton.addLocalTransition(std::move(from), std::move(inputSymbol), std::move(to)); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "localTransition"); - } -} - -void RealTimeHeightDeterministicDPDA::compose(std::deque<sax::Token>& out) const { - out.emplace_back(RealTimeHeightDeterministicDPDA::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); - - AutomatonToXMLComposer::composeStates(out, this->getStates()); - AutomatonToXMLComposer::composeInputAlphabet(out, this->getInputAlphabet()); - AutomatonToXMLComposer::composePushdownStoreAlphabet(out, this->getPushdownStoreAlphabet()); - AutomatonToXMLComposer::composeInitialState(out, this->getInitialState()); - AutomatonToXMLComposer::composeBottomOfTheStackSymbol(out, this->getBottomOfTheStackSymbol()); - AutomatonToXMLComposer::composeFinalStates(out, this->getFinalStates()); - composeTransitions(out); - - out.emplace_back(RealTimeHeightDeterministicDPDA::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); -} - -void RealTimeHeightDeterministicDPDA::composeTransitions(std::deque<sax::Token>& out) const { - out.emplace_back("transitions", sax::Token::TokenType::START_ELEMENT); - for(const auto& transition : this->getCallTransitions()) { - out.emplace_back("callTransition", sax::Token::TokenType::START_ELEMENT); - - AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); - AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, transition.first.second); - AutomatonToXMLComposer::composeTransitionTo(out, transition.second.first); - AutomatonToXMLComposer::composeTransitionSinglePush(out, transition.second.second); - - out.emplace_back("callTransition", sax::Token::TokenType::END_ELEMENT); - } - for(const auto& transition : this->getReturnTransitions()) { - out.emplace_back("returnTransition", sax::Token::TokenType::START_ELEMENT); - - AutomatonToXMLComposer::composeTransitionFrom(out, std::get<0>(transition.first)); - AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, std::get<1>(transition.first)); - AutomatonToXMLComposer::composeTransitionSinglePop(out, std::get<2>(transition.first)); - AutomatonToXMLComposer::composeTransitionTo(out, transition.second); - - out.emplace_back("returnTransition", sax::Token::TokenType::END_ELEMENT); - } - for(const auto& transition : this->getLocalTransitions()) { - out.emplace_back("localTransition", sax::Token::TokenType::START_ELEMENT); - - AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); - AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, transition.first.second); - AutomatonToXMLComposer::composeTransitionTo(out, transition.second); - - out.emplace_back("localTransition", sax::Token::TokenType::END_ELEMENT); - } - out.emplace_back("transitions", sax::Token::TokenType::END_ELEMENT); -} - -} /* namespace automaton */ - namespace alib { -auto realTimeHeightDeterministicDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::RealTimeHeightDeterministicDPDA>(); -auto realTimeHeightDeterministicDPDAParserRegister2 = xmlApi<alib::Object>::ParserRegister<automaton::RealTimeHeightDeterministicDPDA>(); +auto realTimeHeightDeterministicDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::RealTimeHeightDeterministicDPDA < > >(); +auto realTimeHeightDeterministicDPDAParserRegister2 = xmlApi<alib::Object>::ParserRegister<automaton::RealTimeHeightDeterministicDPDA < > >(); -auto RealTimeHeightDeterministicDPDACastBinder = castApi::CastPoolStringBinder<automaton::RealTimeHeightDeterministicDPDA>(automaton::RealTimeHeightDeterministicDPDA::getXmlTagName()); +auto RealTimeHeightDeterministicDPDACastBinder = castApi::CastPoolStringBinder<automaton::RealTimeHeightDeterministicDPDA < > >(automaton::RealTimeHeightDeterministicDPDA < >::getXmlTagName()); } /* namespace alib */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h index 8f61268de0377f59be537be1781d23ddddb09389..b96fcc482fe4344dc9067b1e3453ff138eda0047 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h @@ -8,15 +8,20 @@ #ifndef REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ #define REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ -#include "../AutomatonException.h" #include <map> #include <vector> #include <variant> +#include <algorithm> +#include <sstream> + #include <core/components.hpp> +#include <sax/FromXMLParserHelper.h> + #include "../AutomatonBase.h" -#include "../../alphabet/Symbol.h" -#include "../../label/Label.h" -#include "../../string/Epsilon.h" +#include "../AutomatonFeatures.h" +#include "../AutomatonException.h" +#include "../common/AutomatonFromXMLParser.h" +#include "../common/AutomatonToXMLComposer.h" namespace automaton { @@ -31,106 +36,107 @@ class InitialState; * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class RealTimeHeightDeterministicDPDA : public AutomatonBase, public std::Components < RealTimeHeightDeterministicDPDA, alphabet::Symbol, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < BottomOfTheStackSymbol >, label::Label, std::tuple < States, FinalStates >, std::tuple < InitialState > > { +template<class SymbolType, class EpsilonType, class StateType > +class RealTimeHeightDeterministicDPDA : public AutomatonBase, public std::Components < RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, SymbolType, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < BottomOfTheStackSymbol >, StateType, std::tuple < States, FinalStates >, std::tuple < InitialState > > { protected: - std::map < std::pair < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol > >, std::pair < label::Label, alphabet::Symbol > > callTransitions; - std::map < std::tuple < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol >, alphabet::Symbol >, label::Label > returnTransitions; - std::map < std::pair < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol > >, label::Label > localTransitions; + std::map < std::pair < StateType, std::variant < EpsilonType, SymbolType > >, std::pair < StateType, SymbolType > > callTransitions; + std::map < std::tuple < StateType, std::variant < EpsilonType, SymbolType >, SymbolType >, StateType > returnTransitions; + std::map < std::pair < StateType, std::variant < EpsilonType, SymbolType > >, StateType > localTransitions; public: - explicit RealTimeHeightDeterministicDPDA ( std::set < label::Label > states, std::set < alphabet::Symbol > inputAlphabet, std::set < alphabet::Symbol > pushdownStoreSymbol, label::Label initialState, alphabet::Symbol bottomOfTheStackSymbol, std::set < label::Label > finalStates ); - explicit RealTimeHeightDeterministicDPDA ( label::Label initialState, alphabet::Symbol bottomOfTheStackSymbol ); + explicit RealTimeHeightDeterministicDPDA ( std::set < StateType > states, std::set < SymbolType > inputAlphabet, std::set < SymbolType > pushdownStoreSymbol, StateType initialState, SymbolType bottomOfTheStackSymbol, std::set < StateType > finalStates ); + explicit RealTimeHeightDeterministicDPDA ( StateType initialState, SymbolType bottomOfTheStackSymbol ); virtual AutomatonBase * clone ( ) const; virtual AutomatonBase * plunder ( ) &&; - const label::Label & getInitialState ( ) const { - return accessElement < InitialState > ( ).get ( ); + const StateType & getInitialState ( ) const { + return this->template accessElement < InitialState > ( ).get ( ); } - bool setInitialState ( label::Label state ) { - return accessElement < InitialState > ( ).set ( std::move ( state ) ); + bool setInitialState ( StateType state ) { + return this->template accessElement < InitialState > ( ).set ( std::move ( state ) ); } - const std::set < label::Label > & getStates ( ) const { - return accessComponent < States > ( ).get ( ); + const std::set < StateType > & getStates ( ) const { + return this->template accessComponent < States > ( ).get ( ); } - bool addState ( label::Label state ) { - return accessComponent < States > ( ).add ( std::move ( state ) ); + bool addState ( StateType state ) { + return this->template accessComponent < States > ( ).add ( std::move ( state ) ); } - void setStates ( std::set < label::Label > states ) { - accessComponent < States > ( ).set ( std::move ( states ) ); + void setStates ( std::set < StateType > states ) { + this->template accessComponent < States > ( ).set ( std::move ( states ) ); } - void removeState ( const label::Label & state ) { - accessComponent < States > ( ).remove ( state ); + void removeState ( const StateType & state ) { + this->template accessComponent < States > ( ).remove ( state ); } - const std::set < label::Label > & getFinalStates ( ) const { - return accessComponent < FinalStates > ( ).get ( ); + const std::set < StateType > & getFinalStates ( ) const { + return this->template accessComponent < FinalStates > ( ).get ( ); } - bool addFinalState ( label::Label state ) { - return accessComponent < FinalStates > ( ).add ( std::move ( state ) ); + bool addFinalState ( StateType state ) { + return this->template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); } - void setFinalStates ( std::set < label::Label > states ) { - accessComponent < FinalStates > ( ).set ( std::move ( states ) ); + void setFinalStates ( std::set < StateType > states ) { + this->template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); } - void removeFinalState ( const label::Label & state ) { - accessComponent < FinalStates > ( ).remove ( state ); + void removeFinalState ( const StateType & state ) { + this->template accessComponent < FinalStates > ( ).remove ( state ); } - const std::set < alphabet::Symbol > & getPushdownStoreAlphabet ( ) const { - return accessComponent < PushdownStoreAlphabet > ( ).get ( ); + const std::set < SymbolType > & getPushdownStoreAlphabet ( ) const { + return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ); } - bool addPushdownStoreSymbol ( alphabet::Symbol symbol ) { - return accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); + bool addPushdownStoreSymbol ( SymbolType symbol ) { + return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); } - void addPushdownStoreSymbols ( std::set < alphabet::Symbol > symbols ) { - accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); + void addPushdownStoreSymbols ( std::set < SymbolType > symbols ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); } - void setPushdownStoreAlphabet ( std::set < alphabet::Symbol > symbols ) { - accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); + void setPushdownStoreAlphabet ( std::set < SymbolType > symbols ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); } - void removePushdownStoreSymbol ( const alphabet::Symbol & symbol ) { - accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); + void removePushdownStoreSymbol ( const SymbolType & symbol ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); } - const alphabet::Symbol & getBottomOfTheStackSymbol ( ) const { - return accessElement < BottomOfTheStackSymbol > ( ).get ( ); + const SymbolType & getBottomOfTheStackSymbol ( ) const { + return this->template accessElement < BottomOfTheStackSymbol > ( ).get ( ); } - bool setBottomOfTheStackSymbol ( alphabet::Symbol symbol ) { - return accessElement < BottomOfTheStackSymbol > ( ).set ( std::move ( symbol ) ); + bool setBottomOfTheStackSymbol ( SymbolType symbol ) { + return this->template accessElement < BottomOfTheStackSymbol > ( ).set ( std::move ( symbol ) ); } - const std::set < alphabet::Symbol > & getInputAlphabet ( ) const { - return accessComponent < InputAlphabet > ( ).get ( ); + const std::set < SymbolType > & getInputAlphabet ( ) const { + return this->template accessComponent < InputAlphabet > ( ).get ( ); } - bool addInputSymbol ( alphabet::Symbol symbol ) { - return accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); + bool addInputSymbol ( SymbolType symbol ) { + return this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); } - void addInputSymbols ( std::set < alphabet::Symbol > symbols ) { - accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); + void addInputSymbols ( std::set < SymbolType > symbols ) { + this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); } - void setInputAlphabet ( std::set < alphabet::Symbol > symbols ) { - accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); + void setInputAlphabet ( std::set < SymbolType > symbols ) { + this->template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); } - void removeInputSymbol ( const alphabet::Symbol & symbol ) { - accessComponent < InputAlphabet > ( ).remove ( symbol ); + void removeInputSymbol ( const SymbolType & symbol ) { + this->template accessComponent < InputAlphabet > ( ).remove ( symbol ); } /** @@ -140,9 +146,9 @@ public: * @param next next state * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton */ - bool addCallTransition ( label::Label current, std::variant < string::Epsilon < >, alphabet::Symbol > input, label::Label next, alphabet::Symbol push ); - bool addCallTransition ( label::Label current, label::Label next, alphabet::Symbol push ); - bool addCallTransition ( label::Label current, alphabet::Symbol input, label::Label next, alphabet::Symbol push ); + bool addCallTransition ( StateType current, std::variant < EpsilonType, SymbolType > input, StateType next, SymbolType push ); + bool addCallTransition ( StateType current, StateType next, SymbolType push ); + bool addCallTransition ( StateType current, SymbolType input, StateType next, SymbolType push ); /** * Adds return transition defined by parameters to the automaton. @@ -151,9 +157,9 @@ public: * @param next next state * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton */ - bool addReturnTransition ( label::Label current, std::variant < string::Epsilon < >, alphabet::Symbol > input, alphabet::Symbol pop, label::Label next ); - bool addReturnTransition ( label::Label current, alphabet::Symbol pop, label::Label next ); - bool addReturnTransition ( label::Label current, alphabet::Symbol input, alphabet::Symbol pop, label::Label next ); + bool addReturnTransition ( StateType current, std::variant < EpsilonType, SymbolType > input, SymbolType pop, StateType next ); + bool addReturnTransition ( StateType current, SymbolType pop, StateType next ); + bool addReturnTransition ( StateType current, SymbolType input, SymbolType pop, StateType next ); /** * Adds local transition defined by parameters to the automaton. @@ -162,42 +168,42 @@ public: * @param next next state * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton */ - bool addLocalTransition ( label::Label current, std::variant < string::Epsilon < >, alphabet::Symbol > input, label::Label next ); - bool addLocalTransition ( label::Label current, label::Label next ); - bool addLocalTransition ( label::Label current, alphabet::Symbol input, label::Label next ); + bool addLocalTransition ( StateType current, std::variant < EpsilonType, SymbolType > input, StateType next ); + bool addLocalTransition ( StateType current, StateType next ); + bool addLocalTransition ( StateType current, SymbolType input, StateType next ); /** * Removes call transition from the automaton. * @param transition transition to remove * @throws AutomatonException when transition doesn't exists. */ - bool removeCallTransition ( const label::Label & current, const std::variant < string::Epsilon < >, alphabet::Symbol > & input, const label::Label & next, const alphabet::Symbol & push ); - bool removeCallTransition ( const label::Label & current, const label::Label & next, const alphabet::Symbol & push ); - bool removeCallTransition ( const label::Label & current, const alphabet::Symbol & input, const label::Label & next, const alphabet::Symbol & push ); + bool removeCallTransition ( const StateType & current, const std::variant < EpsilonType, SymbolType > & input, const StateType & next, const SymbolType & push ); + bool removeCallTransition ( const StateType & current, const StateType & next, const SymbolType & push ); + bool removeCallTransition ( const StateType & current, const SymbolType & input, const StateType & next, const SymbolType & push ); /** * Removes return transition from the automaton. * @param transition transition to remove * @throws AutomatonException when transition doesn't exists. */ - bool removeReturnTransition ( const label::Label & current, const std::variant < string::Epsilon < >, alphabet::Symbol > & input, const alphabet::Symbol & pop, const label::Label & next ); - bool removeReturnTransition ( const label::Label & current, const alphabet::Symbol & pop, const label::Label & next ); - bool removeReturnTransition ( const label::Label & current, const alphabet::Symbol & input, const alphabet::Symbol & pop, const label::Label & next ); + bool removeReturnTransition ( const StateType & current, const std::variant < EpsilonType, SymbolType > & input, const SymbolType & pop, const StateType & next ); + bool removeReturnTransition ( const StateType & current, const SymbolType & pop, const StateType & next ); + bool removeReturnTransition ( const StateType & current, const SymbolType & input, const SymbolType & pop, const StateType & next ); /** * Removes transition local from the automaton. * @param transition transition to remove * @throws AutomatonException when transition doesn't exists. */ - bool removeLocalTransition ( const label::Label & current, const std::variant < string::Epsilon < >, alphabet::Symbol > & input, const label::Label & next ); - bool removeLocalTransition ( const label::Label & current, const label::Label & next ); - bool removeLocalTransition ( const label::Label & current, const alphabet::Symbol & input, const label::Label & next ); + bool removeLocalTransition ( const StateType & current, const std::variant < EpsilonType, SymbolType > & input, const StateType & next ); + bool removeLocalTransition ( const StateType & current, const StateType & next ); + bool removeLocalTransition ( const StateType & current, const SymbolType & input, const StateType & next ); - const std::map < std::pair < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol > >, std::pair < label::Label, alphabet::Symbol > > & getCallTransitions ( ) const; + const std::map < std::pair < StateType, std::variant < EpsilonType, SymbolType > >, std::pair < StateType, SymbolType > > & getCallTransitions ( ) const; - const std::map < std::tuple < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol >, alphabet::Symbol >, label::Label > & getReturnTransitions ( ) const; + const std::map < std::tuple < StateType, std::variant < EpsilonType, SymbolType >, SymbolType >, StateType > & getReturnTransitions ( ) const; - const std::map < std::pair < label::Label, std::variant < string::Epsilon < >, alphabet::Symbol > >, label::Label > & getLocalTransitions ( ) const; + const std::map < std::pair < StateType, std::variant < EpsilonType, SymbolType > >, StateType > & getLocalTransitions ( ) const; virtual int compare ( const ObjectBase & other ) const { if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); @@ -224,46 +230,488 @@ public: void composeTransitions ( std::deque < sax::Token > & out ) const; }; +template<class SymbolType, class EpsilonType, class StateType > +RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::RealTimeHeightDeterministicDPDA ( std::set < StateType > states, std::set < SymbolType > inputAlphabet, std::set < SymbolType > pushdownStoreAlphabet, StateType initialState, SymbolType bottomOfTheStackSymbol, std::set < StateType > finalStates ) : std::Components < RealTimeHeightDeterministicDPDA, SymbolType, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < BottomOfTheStackSymbol >, StateType, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ) ), std::make_tuple ( std::move ( bottomOfTheStackSymbol ) ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { +} + +template<class SymbolType, class EpsilonType, class StateType > +RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::RealTimeHeightDeterministicDPDA(StateType initialState, SymbolType bottomOfTheStackSymbol) : RealTimeHeightDeterministicDPDA ( std::set < StateType > { initialState }, std::set < SymbolType > { }, std::set < SymbolType > { bottomOfTheStackSymbol }, initialState, bottomOfTheStackSymbol, std::set < StateType > { }) { +} + +template<class SymbolType, class EpsilonType, class StateType > +AutomatonBase* RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::clone() const { + return new RealTimeHeightDeterministicDPDA(*this); +} + +template<class SymbolType, class EpsilonType, class StateType > +AutomatonBase* RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::plunder() && { + return new RealTimeHeightDeterministicDPDA(std::move(*this)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addCallTransition(StateType from, std::variant<EpsilonType, SymbolType> input, StateType to, SymbolType push) { + if (!getStates().count(from)) { + throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); + } + + if (input.template is<SymbolType>() && !getInputAlphabet().count(input.template get<SymbolType>())) { + throw AutomatonException("Input symbol \"" + std::to_string ( input.template get<SymbolType>() ) + "\" doesn't exist."); + } + + if (!getStates().count(to)) { + throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); + } + + if (!getPushdownStoreAlphabet().count(push)) { + throw AutomatonException("Pushdown store symbol \"" + std::to_string ( push ) + "\" doesn't exist."); + } + + if(getBottomOfTheStackSymbol() == push) + throw AutomatonException("Pushdown store symbol \"" + std::to_string ( push ) + "\" is bottom of the stack."); + + std::pair<StateType, std::variant<EpsilonType, SymbolType>> key(std::move(from), std::move(input)); + std::pair<StateType, SymbolType> value = std::make_pair(std::move(to), std::move(push)); + + if(callTransitions.find(key) != callTransitions.end() && callTransitions.find(key)->second == value) + return false; + + if(key.second.template is<EpsilonType>()) { + for(const auto& transition : callTransitions) + if(transition.first.first == key.first ) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == key.first) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == key.first) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( from ) + "\" when other transitions are present."); + } else { + for(const auto& transition : callTransitions) + if(transition.first.first == key.first && (transition.first.second.template is<EpsilonType>() || transition.first.second == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).template is<EpsilonType>() || std::get<1>(transition.first) == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == key.first && (transition.first.second.template is<EpsilonType>() || transition.first.second == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + } + + callTransitions.insert(std::make_pair(std::move(key), std::move(value))); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addCallTransition(StateType from, StateType to, SymbolType push) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addCallTransition(StateType from, SymbolType input, StateType to, SymbolType push) { + std::variant<EpsilonType, SymbolType> inputVariant(std::move(input)); + return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addReturnTransition(StateType from, std::variant<EpsilonType, SymbolType> input, SymbolType pop, StateType to) { + if (!getStates().count(from)) { + throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); + } + + if (input.template is<SymbolType>() && !getInputAlphabet().count(input.template get<SymbolType>())) { + throw AutomatonException("Input symbol \"" + std::to_string ( input.template get<SymbolType>() ) + "\" doesn't exist."); + } + + if (!getStates().count(to)) { + throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); + } + + if (!getPushdownStoreAlphabet().count(pop)) { + throw AutomatonException("Pushdown store symbol \"" + std::to_string ( pop ) + "\" doesn't exist."); + } + + std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType> key(std::move(from), std::move(input), std::move(pop)); + + if(returnTransitions.find(key) != returnTransitions.end() && returnTransitions.find(key)->second == to) + return false; + + if(std::get<1>(key).template is<EpsilonType>()) { + for(const auto& transition : callTransitions) + if(transition.first.first == std::get<0>(key) ) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == std::get<0>(key) && std::get<2>(transition.first) == std::get<2>(key)) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == std::get<0>(key)) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when other transitions are present."); + } else { + for(const auto& transition : callTransitions) + if(transition.first.first == std::get<0>(key) && (transition.first.second.template is<EpsilonType>() || transition.first.second == std::get<1>(key))) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == std::get<0>(key) && (std::get<1>(transition.first).template is<EpsilonType>() || std::get<1>(transition.first) == std::get<1>(key)) && std::get<2>(transition.first) == std::get<2>(key)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == std::get<0>(key) && (transition.first.second.template is<EpsilonType>() || transition.first.second == std::get<1>(key))) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + std::to_string ( std::get<1>(key) ) + "\" is present."); + } + + returnTransitions.insert(std::make_pair(std::move(key), std::move(to))); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addReturnTransition(StateType from, SymbolType pop, StateType to) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addReturnTransition(StateType from, SymbolType input, SymbolType pop, StateType to) { + std::variant<EpsilonType, SymbolType> inputVariant(std::move(input)); + return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addLocalTransition(StateType from, std::variant<EpsilonType, SymbolType> input, StateType to) { + if (!getStates().count(from)) { + throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); + } + + if (input.template is<SymbolType>() && !getInputAlphabet().count(input.template get<SymbolType>())) { + throw AutomatonException("Input symbol \"" + std::to_string ( input.template get<SymbolType>() ) + "\" doesn't exist."); + } + + if (!getStates().count(to)) { + throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); + } + + std::pair<StateType, std::variant<EpsilonType, SymbolType>> key(std::move(from), std::move(input)); + + if(localTransitions.find(key) != localTransitions.end() && localTransitions.find(key)->second == to) + return false; + + if(key.second.template is<EpsilonType>()) { + for(const auto& transition : callTransitions) + if(transition.first.first == key.first ) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == key.first) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == key.first) + throw AutomatonException("Can't add epsilon transition from state \"" + std::to_string ( key.first ) + "\" when other transitions are present."); + } else { + for(const auto& transition : callTransitions) + if(transition.first.first == key.first && (transition.first.second.template is<EpsilonType>() || transition.first.second == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + + for(const auto& transition : returnTransitions) + if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).template is<EpsilonType>() || std::get<1>(transition.first) == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + + for(const auto& transition : localTransitions) + if(transition.first.first == key.first && (transition.first.second.template is<EpsilonType>() || transition.first.second == key.second)) + throw AutomatonException("Can't add transition from state \"" + std::to_string ( key.first ) + "\" when transition reading \"" + std::to_string ( key.second ) + "\" is present."); + } + + localTransitions.insert(std::make_pair(std::move(key), std::move(to))); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addLocalTransition(StateType from, StateType to) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::addLocalTransition(StateType from, SymbolType input, StateType to) { + std::variant<EpsilonType, SymbolType> inputVariant(std::move(input)); + return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to)); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeCallTransition(const StateType& from, const std::variant<EpsilonType, SymbolType>& input, const StateType& to, const SymbolType& push) { + std::pair<StateType, std::variant<EpsilonType, SymbolType>> key(from, input); + std::pair<StateType, SymbolType> value = std::make_pair(to, push); + + if (callTransitions.find(key) == callTransitions.end()) + return false; + + if(callTransitions.find(key)->second != value) + throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); + + callTransitions.erase(key); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeCallTransition(const StateType& from, const StateType& to, const SymbolType& push) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return removeCallTransition(from, inputVariant, to, push); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeCallTransition(const StateType& from, const SymbolType& input, const StateType& to, const SymbolType& push) { + std::variant<EpsilonType, SymbolType> inputVariant(input); + return removeCallTransition(from, inputVariant, to, push); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeReturnTransition(const StateType& from, const std::variant<EpsilonType, SymbolType>& input, const SymbolType& pop, const StateType& to) { + std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType> key(from, input, pop); + + if (returnTransitions.find(key) == returnTransitions.end()) + return false; + + if(returnTransitions.find(key)->second != to) + throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); + + returnTransitions.erase(key); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeReturnTransition(const StateType& from, const SymbolType& pop, const StateType& to) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return removeReturnTransition(from, inputVariant, pop, to); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeReturnTransition(const StateType& from, const SymbolType& input, const SymbolType& pop, const StateType& to) { + std::variant<EpsilonType, SymbolType> inputVariant(input); + return removeReturnTransition(from, inputVariant, pop, to); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeLocalTransition(const StateType& from, const std::variant<EpsilonType, SymbolType>& input, const StateType& to) { + std::pair<StateType, std::variant<EpsilonType, SymbolType>> key(from, input); + + if (localTransitions.find(key) == localTransitions.end()) + return false; + + if(localTransitions.find(key)->second != to) + throw AutomatonException("Transition (\"" + std::to_string ( from ) + "\", \"" + (std::string) input + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); + + localTransitions.erase(key); + return true; +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeLocalTransition(const StateType& from, const StateType& to) { + std::variant<EpsilonType, SymbolType> inputVariant(EpsilonType::EPSILON); + return removeLocalTransition(from, inputVariant, to); +} + +template<class SymbolType, class EpsilonType, class StateType > +bool RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::removeLocalTransition(const StateType& from, const SymbolType& input, const StateType& to) { + std::variant<EpsilonType, SymbolType> inputVariant(input); + return removeLocalTransition(from, inputVariant, to); +} + +template<class SymbolType, class EpsilonType, class StateType > +const std::map<std::pair<StateType, std::variant<EpsilonType, SymbolType>>, std::pair<StateType, SymbolType> >& RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::getCallTransitions() const { + return callTransitions; +} + +template<class SymbolType, class EpsilonType, class StateType > +const std::map<std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType>, StateType>& RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::getReturnTransitions() const { + return returnTransitions; +} + +template<class SymbolType, class EpsilonType, class StateType > +const std::map<std::pair<StateType, std::variant<EpsilonType, SymbolType>>, StateType>& RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::getLocalTransitions() const { + return localTransitions; +} + +template<class SymbolType, class EpsilonType, class StateType > +int RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::compare(const RealTimeHeightDeterministicDPDA& other) const { + auto first = std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions); + auto second = std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions); + + std::compare<decltype(first)> comp; + return comp(first, second); +} + +template<class SymbolType, class EpsilonType, class StateType > +void RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::operator>>(std::ostream& out) const { + out << "(RealTimeHeightDeterministicDPDA " + << "states = " << getStates() + << "inputAlphabet = " << getInputAlphabet() + << "initialState = " << getInitialState() + << "finalStates = " << getFinalStates() + << "pushdownStoreAlphabet = " << getPushdownStoreAlphabet() + << "bottomOfTheStackSymbol = " << getBottomOfTheStackSymbol() + << "callTransitions = " << callTransitions + << "returnTransitions = " << returnTransitions + << "localTransitions = " << localTransitions + << ")"; +} + +template<class SymbolType, class EpsilonType, class StateType > +RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::operator std::string () const { + std::stringstream ss; + ss << *this; + return ss.str(); +} + +template<class SymbolType, class EpsilonType, class StateType > +RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::parse(std::deque<sax::Token>::iterator& input) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, RealTimeHeightDeterministicDPDA::getXmlTagName()); + + std::set<StateType> states = AutomatonFromXMLParser::parseStates<StateType>(input); + std::set<SymbolType> inputSymbols = AutomatonFromXMLParser::parseInputAlphabet<SymbolType>(input); + std::set<SymbolType> stackSymbols = AutomatonFromXMLParser::parsePushdownStoreAlphabet<SymbolType>(input); + StateType initialState = AutomatonFromXMLParser::parseInitialState<StateType>(input); + SymbolType bottomOfTheStackSymbol = AutomatonFromXMLParser::parseBottomOfTheStackSymbol<SymbolType>(input); + std::set<StateType> finalStates = AutomatonFromXMLParser::parseFinalStates<StateType>(input); + + RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > automaton(std::move(initialState), std::move(bottomOfTheStackSymbol)); + automaton.setStates(std::move(states)); + automaton.setInputAlphabet(std::move(inputSymbols)); + automaton.setPushdownStoreAlphabet(std::move(stackSymbols)); + automaton.setFinalStates(std::move(finalStates)); + + AutomatonFromXMLParser::parseTransitions<RealTimeHeightDeterministicDPDA>(input, automaton); + + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, RealTimeHeightDeterministicDPDA::getXmlTagName()); + return automaton; +} + +template<class SymbolType, class EpsilonType, class StateType > +void RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::parseTransition(std::deque<sax::Token>::iterator& input, RealTimeHeightDeterministicDPDA& automaton) { + if(sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, "callTransition")) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "callTransition"); + StateType from = AutomatonFromXMLParser::parseTransitionFrom<StateType>(input); + std::variant<EpsilonType, SymbolType> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<EpsilonType,SymbolType>(input); + StateType to = AutomatonFromXMLParser::parseTransitionTo<StateType>(input); + SymbolType push = AutomatonFromXMLParser::parseTransitionSinglePush<SymbolType>(input); + + automaton.addCallTransition(std::move(from), std::move(inputSymbol), std::move(to), std::move(push)); + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "callTransition"); + } else if(sax::FromXMLParserHelper::isToken(input, sax::Token::TokenType::START_ELEMENT, "returnTransition")) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "returnTransition"); + StateType from = AutomatonFromXMLParser::parseTransitionFrom<StateType>(input); + std::variant<EpsilonType, SymbolType> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<EpsilonType,SymbolType>(input); + SymbolType pop = AutomatonFromXMLParser::parseTransitionSinglePop<SymbolType>(input); + StateType to = AutomatonFromXMLParser::parseTransitionTo<StateType>(input); + + automaton.addReturnTransition(std::move(from), std::move(inputSymbol), std::move(pop), std::move(to)); + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "returnTransition"); + } else { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "localTransition"); + StateType from = AutomatonFromXMLParser::parseTransitionFrom<StateType>(input); + std::variant<EpsilonType, SymbolType> inputSymbol = AutomatonFromXMLParser::parseTransitionInputEpsilonSymbol<EpsilonType,SymbolType>(input); + StateType to = AutomatonFromXMLParser::parseTransitionTo<StateType>(input); + + automaton.addLocalTransition(std::move(from), std::move(inputSymbol), std::move(to)); + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "localTransition"); + } +} + +template<class SymbolType, class EpsilonType, class StateType > +void RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::compose(std::deque<sax::Token>& out) const { + out.emplace_back(RealTimeHeightDeterministicDPDA::getXmlTagName(), sax::Token::TokenType::START_ELEMENT); + + AutomatonToXMLComposer::composeStates(out, this->getStates()); + AutomatonToXMLComposer::composeInputAlphabet(out, this->getInputAlphabet()); + AutomatonToXMLComposer::composePushdownStoreAlphabet(out, this->getPushdownStoreAlphabet()); + AutomatonToXMLComposer::composeInitialState(out, this->getInitialState()); + AutomatonToXMLComposer::composeBottomOfTheStackSymbol(out, this->getBottomOfTheStackSymbol()); + AutomatonToXMLComposer::composeFinalStates(out, this->getFinalStates()); + composeTransitions(out); + + out.emplace_back(RealTimeHeightDeterministicDPDA::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +} + +template<class SymbolType, class EpsilonType, class StateType > +void RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >::composeTransitions(std::deque<sax::Token>& out) const { + out.emplace_back("transitions", sax::Token::TokenType::START_ELEMENT); + for(const auto& transition : this->getCallTransitions()) { + out.emplace_back("callTransition", sax::Token::TokenType::START_ELEMENT); + + AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); + AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, transition.first.second); + AutomatonToXMLComposer::composeTransitionTo(out, transition.second.first); + AutomatonToXMLComposer::composeTransitionSinglePush(out, transition.second.second); + + out.emplace_back("callTransition", sax::Token::TokenType::END_ELEMENT); + } + for(const auto& transition : this->getReturnTransitions()) { + out.emplace_back("returnTransition", sax::Token::TokenType::START_ELEMENT); + + AutomatonToXMLComposer::composeTransitionFrom(out, std::get<0>(transition.first)); + AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, std::get<1>(transition.first)); + AutomatonToXMLComposer::composeTransitionSinglePop(out, std::get<2>(transition.first)); + AutomatonToXMLComposer::composeTransitionTo(out, transition.second); + + out.emplace_back("returnTransition", sax::Token::TokenType::END_ELEMENT); + } + for(const auto& transition : this->getLocalTransitions()) { + out.emplace_back("localTransition", sax::Token::TokenType::START_ELEMENT); + + AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); + AutomatonToXMLComposer::composeTransitionInputEpsilonSymbol(out, transition.first.second); + AutomatonToXMLComposer::composeTransitionTo(out, transition.second); + + out.emplace_back("localTransition", sax::Token::TokenType::END_ELEMENT); + } + out.emplace_back("transitions", sax::Token::TokenType::END_ELEMENT); +} + } /* namespace automaton */ namespace std { -template < > -class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::InputAlphabet > { +template<class SymbolType, class EpsilonType, class StateType > +class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, SymbolType, automaton::InputAlphabet > { public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (callTransition.first.second.is<alphabet::Symbol>() && symbol == callTransition.first.second.get<alphabet::Symbol>()) + static bool used ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const SymbolType & symbol ) { + for (const std::pair<const std::pair<StateType, std::variant<EpsilonType, SymbolType>>, std::pair<StateType, SymbolType> >& callTransition : automaton.getCallTransitions()) + if (callTransition.first.second.template is<SymbolType>() && symbol == callTransition.first.second.get<SymbolType>()) return true; - for (const std::pair<const std::tuple<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& returnTransition : automaton.getReturnTransitions()) - if (std::get<1>(returnTransition.first).is<alphabet::Symbol>() && symbol == std::get<1>(returnTransition.first).get<alphabet::Symbol>()) + for (const std::pair<const std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType>, StateType>& returnTransition : automaton.getReturnTransitions()) + if (std::get<1>(returnTransition.first).template is<SymbolType>() && symbol == std::get<1>(returnTransition.first).template get<SymbolType>()) return true; - for (const std::pair<const std::pair<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>>, label::Label>& localTransition : automaton.getLocalTransitions()) - if (localTransition.first.second.is<alphabet::Symbol>() && symbol == localTransition.first.second.get<alphabet::Symbol>()) + for (const std::pair<const std::pair<StateType, std::variant<EpsilonType, SymbolType>>, StateType>& localTransition : automaton.getLocalTransitions()) + if (localTransition.first.second.template is<SymbolType>() && symbol == localTransition.first.second.template get<SymbolType>()) return true; return false; } - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const SymbolType & ) { return true; } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const SymbolType & ) { } }; -template < > -class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +template<class SymbolType, class EpsilonType, class StateType > +class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, SymbolType, automaton::PushdownStoreAlphabet > { public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + static bool used ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const SymbolType & symbol ) { + for (const std::pair<const std::pair<StateType, std::variant<EpsilonType, SymbolType>>, std::pair<StateType, SymbolType> >& callTransition : automaton.getCallTransitions()) if (symbol == callTransition.second.second) return true; - for (const std::pair<const std::tuple<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& returnTransition : automaton.getReturnTransitions()) + for (const std::pair<const std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType>, StateType>& returnTransition : automaton.getReturnTransitions()) if (symbol == std::get<2>(returnTransition.first)) return true; @@ -273,81 +721,81 @@ public: return false; } - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const SymbolType & ) { return true; } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const SymbolType & ) { } }; -template < > -class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { +template<class SymbolType, class EpsilonType, class StateType > +class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, SymbolType, automaton::BottomOfTheStackSymbol > { public: - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const SymbolType & symbol ) { + return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const SymbolType & ) { } }; -template < > -class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA, label::Label, automaton::States > { +template<class SymbolType, class EpsilonType, class StateType > +class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, StateType, automaton::States > { public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const label::Label & state ) { + static bool used ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const StateType & state ) { if ( automaton.getInitialState ( ) == state ) return true; if ( automaton.getFinalStates ( ).count ( state ) ) return true; - for (const std::pair<const std::pair<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>>, std::pair<label::Label, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + for (const std::pair<const std::pair<StateType, std::variant<EpsilonType, SymbolType>>, std::pair<StateType, SymbolType> >& callTransition : automaton.getCallTransitions()) if (state == callTransition.first.first || callTransition.second.first == state) return true; - for (const std::pair<const std::tuple<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>, alphabet::Symbol>, label::Label>& returnTransition : automaton.getReturnTransitions()) + for (const std::pair<const std::tuple<StateType, std::variant<EpsilonType, SymbolType>, SymbolType>, StateType>& returnTransition : automaton.getReturnTransitions()) if (state == std::get<0>(returnTransition.first) || returnTransition.second == state) return true; - for (const std::pair<const std::pair<label::Label, std::variant<::string::Epsilon < >, alphabet::Symbol>>, label::Label>& localTransition : automaton.getLocalTransitions()) + for (const std::pair<const std::pair<StateType, std::variant<EpsilonType, SymbolType>>, StateType>& localTransition : automaton.getLocalTransitions()) if (state == localTransition.first.first || localTransition.second == state) return true; return false; } - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const label::Label & ) { + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const StateType & ) { return true; } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const label::Label & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const StateType & ) { } }; -template < > -class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA, label::Label, automaton::FinalStates > { +template<class SymbolType, class EpsilonType, class StateType > +class ComponentConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, StateType, automaton::FinalStates > { public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA &, const label::Label & ) { + static bool used ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const StateType & ) { return false; } - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const label::Label & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const label::Label & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const StateType & ) { } }; -template < > -class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA, label::Label, automaton::InitialState > { +template<class SymbolType, class EpsilonType, class StateType > +class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType >, StateType, automaton::InitialState > { public: - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const label::Label & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + static bool available ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const label::Label & ) { + static void valid ( const automaton::RealTimeHeightDeterministicDPDA < SymbolType, EpsilonType, StateType > &, const StateType & ) { } };