diff --git a/aaccess2/src/AutomatonAccess.cpp b/aaccess2/src/AutomatonAccess.cpp index d397a1a5ba0726e15f00ca132be16b37707dd635..0a0063c282d9ca25417ad9d100b0095c4c7db706 100644 --- a/aaccess2/src/AutomatonAccess.cpp +++ b/aaccess2/src/AutomatonAccess.cpp @@ -94,7 +94,7 @@ void AutomatonAccess::access ( automaton::InputDrivenNPDA & automaton, const Aut auto AutomatonAccessInputDrivenNPDA = AutomatonAccess::RegistratorWrapper < void, automaton::InputDrivenNPDA > ( AutomatonAccess::access ); -void AutomatonAccess::access ( automaton::InputDrivenDPDA & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ) { +void AutomatonAccess::access ( automaton::InputDrivenDPDA < > & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ) { if ( settings == AutomatonSettings::Settings::STATES ) return handleComponent < automaton::States > ( automaton, operation, argument ); @@ -113,7 +113,7 @@ void AutomatonAccess::access ( automaton::InputDrivenDPDA & automaton, const Aut throw exception::CommonException ( "Component not available" ); } -auto AutomatonAccessInputDrivenDPDA = AutomatonAccess::RegistratorWrapper < void, automaton::InputDrivenDPDA > ( AutomatonAccess::access ); +auto AutomatonAccessInputDrivenDPDA = AutomatonAccess::RegistratorWrapper < void, automaton::InputDrivenDPDA < > > ( AutomatonAccess::access ); void AutomatonAccess::access ( automaton::NPDA & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ) { if ( settings == AutomatonSettings::Settings::STATES ) diff --git a/aaccess2/src/AutomatonAccess.h b/aaccess2/src/AutomatonAccess.h index 1709b493b1b20f8166ade9bb3d6e693ff0199257..253b5395cdd1dde39e60e231801bbf71144f3268 100644 --- a/aaccess2/src/AutomatonAccess.h +++ b/aaccess2/src/AutomatonAccess.h @@ -25,7 +25,7 @@ public: static void access ( automaton::DFA < > & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); static void access ( automaton::InputDrivenNPDA & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); - static void access ( automaton::InputDrivenDPDA & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); + static void access ( automaton::InputDrivenDPDA < > & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); static void access ( automaton::DPDA < > & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); static void access ( automaton::NPDA & automaton, const AutomatonSettings::Settings & settings, const OperationSettings::Settings & operation, std::deque < sax::Token > & argument ); diff --git a/acompare2/src/AutomatonCompare.cpp b/acompare2/src/AutomatonCompare.cpp index 0c43fb951bd0f85e9424451bd550b1f460a8f87a..f7967a1fdc8b88539db0e063eaece291b3328339 100644 --- a/acompare2/src/AutomatonCompare.cpp +++ b/acompare2/src/AutomatonCompare.cpp @@ -120,7 +120,7 @@ bool AutomatonCompare::testCompare(const automaton::NPDA& a, const automaton::NP a.getTransitions() == b.getTransitions() ; } -bool AutomatonCompare::testCompare(const automaton::InputDrivenDPDA& a, const automaton::InputDrivenDPDA& b) { +bool AutomatonCompare::testCompare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b) { return a.getFinalStates() == b.getFinalStates() && a.getInitialState() == b.getInitialState() && // a.getInputAlphabet() == b.getInputAlphabet() && @@ -642,7 +642,7 @@ void AutomatonCompare::printCompare(const automaton::NPDA& a, const automaton::N } } -void AutomatonCompare::printCompare(const automaton::InputDrivenDPDA& a, const automaton::InputDrivenDPDA& b) { +void AutomatonCompare::printCompare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b) { std::cout << "AutomatonCompareer" << std::endl; if(a.getFinalStates() != b.getFinalStates()){ @@ -1282,7 +1282,7 @@ int AutomatonCompare::compare(const automaton::NPDA& a, const automaton::NPDA& b auto AutomatonCompareNPDA = AutomatonCompare::RegistratorWrapper<int, automaton::NPDA, automaton::NPDA>(AutomatonCompare::compare); -int AutomatonCompare::compare(const automaton::InputDrivenDPDA& a, const automaton::InputDrivenDPDA& b) { +int AutomatonCompare::compare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b) { if(!AutomatonCompare::testCompare(a, b)) { AutomatonCompare::printCompare(a, b); return 1; @@ -1291,7 +1291,7 @@ int AutomatonCompare::compare(const automaton::InputDrivenDPDA& a, const automat } } -auto AutomatonCompareInputDrivenDPDA = AutomatonCompare::RegistratorWrapper<int, automaton::InputDrivenDPDA, automaton::InputDrivenDPDA>(AutomatonCompare::compare); +auto AutomatonCompareInputDrivenDPDA = AutomatonCompare::RegistratorWrapper<int, automaton::InputDrivenDPDA < >, automaton::InputDrivenDPDA < > >(AutomatonCompare::compare); int AutomatonCompare::compare(const automaton::InputDrivenNPDA& a, const automaton::InputDrivenNPDA& b) { if(!AutomatonCompare::testCompare(a, b)) { diff --git a/acompare2/src/AutomatonCompare.h b/acompare2/src/AutomatonCompare.h index 3672b34adabbc3ee35301197479f200f3a86f398..31e7dbe09d7d263ea9a91949803ccf460ab18bb1 100644 --- a/acompare2/src/AutomatonCompare.h +++ b/acompare2/src/AutomatonCompare.h @@ -50,8 +50,8 @@ private: static bool testCompare(const automaton::NFTA& a, const automaton::NFTA& b); static void printCompare(const automaton::NFTA& a, const automaton::NFTA& b); - static bool testCompare(const automaton::InputDrivenDPDA& a, const automaton::InputDrivenDPDA& b); - static void printCompare(const automaton::InputDrivenDPDA& a, const automaton::InputDrivenDPDA& b); + static bool testCompare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b); + static void printCompare(const automaton::InputDrivenDPDA < > & a, const automaton::InputDrivenDPDA < > & b); static bool testCompare(const automaton::InputDrivenNPDA& a, const automaton::InputDrivenNPDA& b); static void printCompare(const automaton::InputDrivenNPDA& a, const automaton::InputDrivenNPDA& b); @@ -93,7 +93,7 @@ public: static int compare(const automaton::DPDA < > & a, const automaton::DPDA < > & b); 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::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::RealTimeHeightDeterministicNPDA& a, const automaton::RealTimeHeightDeterministicNPDA& b); diff --git a/aconvert2/src/DotConverter.cpp b/aconvert2/src/DotConverter.cpp index 9f01574c346f8ab9951d7d731caf3a34f449c3bb..504d1fe37ade295a183dc644cc31d97c67a47f31 100644 --- a/aconvert2/src/DotConverter.cpp +++ b/aconvert2/src/DotConverter.cpp @@ -374,7 +374,7 @@ void DotConverter::convert(std::ostream& out, const automaton::SinglePopDPDA& a) auto DotConverterSinglePopDPDA = DotConverter::RegistratorWrapper<void, automaton::SinglePopDPDA>(DotConverter::convert); -void DotConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA& a) { +void DotConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a) { out << "digraph automaton {\n"; out << "rankdir=LR;\n"; int cnt = 1; @@ -405,7 +405,7 @@ void DotConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA& out << "}"; } -auto DotConverterInputDrivenDPDA = DotConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA>(DotConverter::convert); +auto DotConverterInputDrivenDPDA = DotConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA < > >(DotConverter::convert); void DotConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA& a) { out << "digraph automaton {\n"; @@ -1101,7 +1101,7 @@ void DotConverter::transitions(const automaton::SinglePopDPDA& pda, const std::m } } -void DotConverter::transitions(const automaton::InputDrivenDPDA& pda, const std::map<label::Label, int>& states, std::ostream& out) { +void DotConverter::transitions(const automaton::InputDrivenDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out) { std::map<std::pair<int, int>, std::string> transitions; const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); diff --git a/aconvert2/src/DotConverter.h b/aconvert2/src/DotConverter.h index 8d05e7d31b89cef5a77d4751ffdd024de126f5af..22eee476f84034903edad1752f7141eb7e1721d2 100644 --- a/aconvert2/src/DotConverter.h +++ b/aconvert2/src/DotConverter.h @@ -30,7 +30,7 @@ class DotConverter : public std::SingleDispatchFirstStaticParam<DotConverter, vo static void transitions(const automaton::DFTA& fsm, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::DPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); static void transitions(const automaton::SinglePopDPDA& tm, const std::map<label::Label, int>& states, std::ostream& out); - static void transitions(const automaton::InputDrivenDPDA& pda, const std::map<label::Label, int>& states, std::ostream& out); + static void transitions(const automaton::InputDrivenDPDA < > & pda, const std::map<label::Label, int>& states, std::ostream& out); 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); @@ -52,7 +52,7 @@ public: static void convert(std::ostream& out, const automaton::DFTA& a); static void convert(std::ostream& out, const automaton::DPDA < > & a); static void convert(std::ostream& out, const automaton::SinglePopDPDA& a); - static void convert(std::ostream& out, const automaton::InputDrivenDPDA& a); + static void convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a); 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); diff --git a/aconvert2/src/GasTexConverter.cpp b/aconvert2/src/GasTexConverter.cpp index 5ec1fbcd14c1f9b31a206bdcbc78bdff45f8d977..392c120ebffe2b6feacb77b40a1ee582f147b5b4 100644 --- a/aconvert2/src/GasTexConverter.cpp +++ b/aconvert2/src/GasTexConverter.cpp @@ -378,7 +378,7 @@ void GasTexConverter::convert(std::ostream& out, const automaton::SinglePopDPDA& auto GasTexConverterSinglePopDPDA = GasTexConverter::RegistratorWrapper<void, automaton::SinglePopDPDA>(GasTexConverter::convert); -void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA& a) { +void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a) { out << "\\begin{center}\n"; out << "\\begin{picture}(,)(,)\n"; @@ -417,7 +417,7 @@ void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenDPD out << "\\end{picture}\n"; } -auto GasTexConverterInputDrivenDPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA>(GasTexConverter::convert); +auto GasTexConverterInputDrivenDPDA = GasTexConverter::RegistratorWrapper<void, automaton::InputDrivenDPDA < > >(GasTexConverter::convert); void GasTexConverter::convert(std::ostream& out, const automaton::InputDrivenNPDA& a) { out << "\\begin{center}\n"; @@ -975,7 +975,7 @@ void GasTexConverter::transitions(const automaton::SinglePopDPDA& pda, std::ostr printTransitionMap(transitionMap, out); } -void GasTexConverter::transitions(const automaton::InputDrivenDPDA& pda, std::ostream& out) { +void GasTexConverter::transitions(const automaton::InputDrivenDPDA < > & pda, std::ostream& out) { std::map<std::pair<std::string, std::string>, std::string> transitionMap; const auto& symbolToPDSOperation = pda.getPushdownStoreOperations(); diff --git a/aconvert2/src/GasTexConverter.h b/aconvert2/src/GasTexConverter.h index b17442040316e5a05c996e85b5bfd532464f01dd..1ea1d1046274dbf81a367fbab8b2834a1c86b10d 100644 --- a/aconvert2/src/GasTexConverter.h +++ b/aconvert2/src/GasTexConverter.h @@ -31,7 +31,7 @@ class GasTexConverter : public std::SingleDispatchFirstStaticParam<GasTexConvert static void transitions(const automaton::DFTA& fsm, std::ostream& out); static void transitions(const automaton::DPDA < > & pda, std::ostream& out); static void transitions(const automaton::SinglePopDPDA& tm, std::ostream& out); - static void transitions(const automaton::InputDrivenDPDA& pda, std::ostream& out); + static void transitions(const automaton::InputDrivenDPDA < > & pda, std::ostream& out); 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); @@ -53,7 +53,7 @@ public: static void convert(std::ostream& out, const automaton::DFTA& a); static void convert(std::ostream& out, const automaton::DPDA < > & a); static void convert(std::ostream& out, const automaton::SinglePopDPDA& a); - static void convert(std::ostream& out, const automaton::InputDrivenDPDA& a); + static void convert(std::ostream& out, const automaton::InputDrivenDPDA < > & a); 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); diff --git a/aconvert2/src/TikZConverter.cpp b/aconvert2/src/TikZConverter.cpp index a94efaa0cb75bea3afe8436894f6dda64814bb74..081f4443baa1baf59421a96997adff6582fe4d15 100644 --- a/aconvert2/src/TikZConverter.cpp +++ b/aconvert2/src/TikZConverter.cpp @@ -335,7 +335,7 @@ void TikZConverter::convert ( std::ostream & out, const automaton::SinglePopDPDA auto TikZConverterSinglePopDPDA = TikZConverter::RegistratorWrapper < void, automaton::SinglePopDPDA > ( TikZConverter::convert ); -void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenDPDA & a ) { +void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenDPDA < > & a ) { out << "\\begin{tikzpicture}\n"; int cnt = 1; @@ -362,7 +362,7 @@ void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenDP out << "\\end{tikzpicture}"; } -auto TikZConverterInputDrivenDPDA = TikZConverter::RegistratorWrapper < void, automaton::InputDrivenDPDA > ( TikZConverter::convert ); +auto TikZConverterInputDrivenDPDA = TikZConverter::RegistratorWrapper < void, automaton::InputDrivenDPDA < > > ( TikZConverter::convert ); void TikZConverter::convert ( std::ostream & out, const automaton::InputDrivenNPDA & a ) { out << "\\begin{tikzpicture}\n"; @@ -1103,7 +1103,7 @@ void TikZConverter::transitions ( const automaton::SinglePopDPDA & pda, const st } } -void TikZConverter::transitions ( const automaton::InputDrivenDPDA & pda, const std::map < label::Label, int > & states, std::ostream & out ) { +void TikZConverter::transitions ( const automaton::InputDrivenDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ) { std::map < std::pair < int, int >, std::string > transitions; const auto & symbolToPDSOperation = pda.getPushdownStoreOperations ( ); diff --git a/aconvert2/src/TikZConverter.h b/aconvert2/src/TikZConverter.h index 677ad3ad7c361593f87761dff3f8b50375419165..33be3dd83134af337caa6c8778bbeeaad59651d3 100644 --- a/aconvert2/src/TikZConverter.h +++ b/aconvert2/src/TikZConverter.h @@ -30,7 +30,7 @@ class TikZConverter : public std::SingleDispatchFirstStaticParam < TikZConverter static void transitions ( const automaton::DFTA & fsm, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::DPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); static void transitions ( const automaton::SinglePopDPDA & tm, const std::map < label::Label, int > & states, std::ostream & out ); - static void transitions ( const automaton::InputDrivenDPDA & pda, const std::map < label::Label, int > & states, std::ostream & out ); + static void transitions ( const automaton::InputDrivenDPDA < > & pda, const std::map < label::Label, int > & states, std::ostream & out ); 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 ); @@ -53,7 +53,7 @@ public: static void convert ( std::ostream & out, const automaton::DFTA & a ); static void convert ( std::ostream & out, const automaton::DPDA < > & a ); static void convert ( std::ostream & out, const automaton::SinglePopDPDA & a ); - static void convert ( std::ostream & out, const automaton::InputDrivenDPDA & a ); + static void convert ( std::ostream & out, const automaton::InputDrivenDPDA < > & a ); 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 ); diff --git a/alib2algo/src/automaton/determinize/Determinize.cpp b/alib2algo/src/automaton/determinize/Determinize.cpp index f31d85397353edeae01faa097bffae2359ee5662..368807354d614c45b98bbb5079fd572d7bea24ba 100644 --- a/alib2algo/src/automaton/determinize/Determinize.cpp +++ b/alib2algo/src/automaton/determinize/Determinize.cpp @@ -47,11 +47,11 @@ SinglePopDPDA Determinize::determinize(const automaton::SinglePopDPDA& automaton auto DeterminizeSinglePopDPDA = Determinize::RegistratorWrapper<automaton::SinglePopDPDA, automaton::SinglePopDPDA>(Determinize::determinize); -InputDrivenDPDA Determinize::determinize(const automaton::InputDrivenDPDA& automaton) { +InputDrivenDPDA < > Determinize::determinize(const automaton::InputDrivenDPDA < > & automaton) { return automaton; } -auto DeterminizeInputDrivenDPDA = Determinize::RegistratorWrapper<automaton::InputDrivenDPDA, automaton::InputDrivenDPDA>(Determinize::determinize); +auto DeterminizeInputDrivenDPDA = Determinize::RegistratorWrapper<automaton::InputDrivenDPDA < >, automaton::InputDrivenDPDA < > >(Determinize::determinize); VisiblyPushdownDPDA Determinize::determinize(const automaton::VisiblyPushdownDPDA& automaton) { return automaton; diff --git a/alib2algo/src/automaton/determinize/Determinize.h b/alib2algo/src/automaton/determinize/Determinize.h index 5d433bee98534504a83851bdfcc359e5c136a7b4..31af09716839499dcbccd44b77a5151ddbcbbaf1 100644 --- a/alib2algo/src/automaton/determinize/Determinize.h +++ b/alib2algo/src/automaton/determinize/Determinize.h @@ -39,8 +39,8 @@ public: static automaton::SinglePopDPDA determinize(const automaton::SinglePopDPDA& dpda); static automaton::VisiblyPushdownDPDA determinize(const automaton::VisiblyPushdownDPDA& nondeterministic); 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::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::DFTA determinize(const automaton::DFTA& nfta); diff --git a/alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx b/alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx index 5675def291fa21d0bfc6dd505ac2d97a30d15873..9c093c7b5a0f21150588c2322b3973c1a1a98d68 100644 --- a/alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx +++ b/alib2algo/src/automaton/determinize/DeterminizeIDPDAPart.cxx @@ -17,10 +17,10 @@ namespace automaton { namespace determinize { -automaton::InputDrivenDPDA Determinize::determinize ( const automaton::InputDrivenNPDA & nfa ) { +automaton::InputDrivenDPDA < > Determinize::determinize ( const automaton::InputDrivenNPDA & nfa ) { // 1, 4 label::Label initialState ( createDFAState ( { nfa.getInitialState ( ) } ) ); - automaton::InputDrivenDPDA res ( initialState, nfa.getInitialSymbol ( ) ); + automaton::InputDrivenDPDA < > res ( initialState, nfa.getInitialSymbol ( ) ); res.setInputAlphabet ( nfa.getInputAlphabet ( ) ); res.setPushdownStoreAlphabet ( nfa.getPushdownStoreAlphabet ( ) ); @@ -70,7 +70,7 @@ automaton::InputDrivenDPDA Determinize::determinize ( const automaton::InputDriv return res; } -auto DeterminizeInputDrivenNPDA = Determinize::RegistratorWrapper < automaton::InputDrivenDPDA, automaton::InputDrivenNPDA > ( Determinize::determinize ); +auto DeterminizeInputDrivenNPDA = Determinize::RegistratorWrapper < automaton::InputDrivenDPDA < >, automaton::InputDrivenNPDA > ( Determinize::determinize ); } /* namespace determinize */ diff --git a/alib2algo/src/automaton/run/Accept.cpp b/alib2algo/src/automaton/run/Accept.cpp index e14c30b628486a7ba39f2739210326137c8a8c09..34edbb554131657f87eaa0f0625898f48be799d9 100644 --- a/alib2algo/src/automaton/run/Accept.cpp +++ b/alib2algo/src/automaton/run/Accept.cpp @@ -73,13 +73,13 @@ bool Accept::accept ( const automaton::NFTA & automaton, const tree::RankedTree auto AcceptNFTARankedTree = Accept::RegistratorWrapper < bool, automaton::NFTA, tree::RankedTree > ( Accept::accept ); -bool Accept::accept ( const automaton::InputDrivenDPDA & automaton, const string::LinearString < > & string ) { +bool Accept::accept ( const automaton::InputDrivenDPDA < > & 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 ) ) || ( automaton.getFinalStates ( ).size ( ) == 0 && std::get < 3 > ( res ).size ( ) == 0 ) ); } -auto AcceptInputDrivenDPDALinearString = Accept::RegistratorWrapper < bool, automaton::InputDrivenDPDA, string::LinearString < > > ( Accept::accept ); +auto AcceptInputDrivenDPDALinearString = Accept::RegistratorWrapper < bool, automaton::InputDrivenDPDA < >, string::LinearString < > > ( Accept::accept ); bool Accept::accept ( const automaton::VisiblyPushdownDPDA & 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 e6a4b0cafd60a4727f5301e26f8af8a026347c96..6a9d95ce8087a9e5a0839f67bea315ad5d0adf59 100644 --- a/alib2algo/src/automaton/run/Accept.h +++ b/alib2algo/src/automaton/run/Accept.h @@ -33,7 +33,7 @@ public: static bool accept ( const automaton::NFA < > & automaton, const string::LinearString < > & string ); static bool accept ( const automaton::DFTA & automaton, const tree::RankedTree & tree ); 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::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::DPDA < > & automaton, const string::LinearString < > & string ); diff --git a/alib2algo/src/automaton/run/Occurrences.cpp b/alib2algo/src/automaton/run/Occurrences.cpp index cf570affaf358fc6658c56fb7a20511558db5ac9..8ae79852a56c9ef834f0738b9b767448579d6f41 100644 --- a/alib2algo/src/automaton/run/Occurrences.cpp +++ b/alib2algo/src/automaton/run/Occurrences.cpp @@ -49,13 +49,13 @@ std::set < unsigned > Occurrences::occurrences ( const automaton::DFTA & automat auto OccurrencesDFTARankedTree = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::DFTA, tree::RankedTree > ( Occurrences::occurrences ); -std::set < unsigned > Occurrences::occurrences ( const automaton::InputDrivenDPDA & automaton, const string::LinearString < > & string ) { +std::set < unsigned > Occurrences::occurrences ( const automaton::InputDrivenDPDA < > & 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 OccurrencesInputDrivenDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::InputDrivenDPDA, string::LinearString < > > ( Occurrences::occurrences ); +auto OccurrencesInputDrivenDPDALinearString = Occurrences::RegistratorWrapper < std::set < unsigned >, automaton::InputDrivenDPDA < >, string::LinearString < > > ( Occurrences::occurrences ); std::set < unsigned > Occurrences::occurrences ( const automaton::VisiblyPushdownDPDA & 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 309a499720592a85fc3a6a5edeb5aa73c86faf53..2686b2f144550948ec5e97be9012e5e76605f20a 100644 --- a/alib2algo/src/automaton/run/Occurrences.h +++ b/alib2algo/src/automaton/run/Occurrences.h @@ -31,7 +31,7 @@ public: static std::set < unsigned > occurrences ( const automaton::DFA<> & automaton, const string::LinearString < > & string ); 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::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::DPDA < > & automaton, const string::LinearString < > & string ); diff --git a/alib2algo/src/automaton/run/Result.cpp b/alib2algo/src/automaton/run/Result.cpp index 2a9881603cc68a3e869c935043533bac9c85ad16..28c30a021255a727ec2b1f92dd248fe378229edb 100644 --- a/alib2algo/src/automaton/run/Result.cpp +++ b/alib2algo/src/automaton/run/Result.cpp @@ -45,7 +45,7 @@ label::Label Result::result ( const automaton::DFTA & automaton, const tree::Ran auto ResultDFTARankedTree = Result::RegistratorWrapper < label::Label, automaton::DFTA, tree::RankedTree > ( Result::result ); -label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, const string::LinearString < > & string, const label::Label & failLabel ) { +label::Label Result::result ( const automaton::InputDrivenDPDA < > & 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 ); @@ -53,7 +53,7 @@ label::Label Result::result ( const automaton::InputDrivenDPDA & automaton, cons return failLabel; } -auto ResultInputDrivenDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::InputDrivenDPDA, string::LinearString < > > ( Result::result ); +auto ResultInputDrivenDPDALinearString = Result::RegistratorWrapper < label::Label, automaton::InputDrivenDPDA < >, string::LinearString < > > ( Result::result ); label::Label Result::result ( const automaton::VisiblyPushdownDPDA & 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 6543d9179071a499b68f41ae7fb12b429a5c7462..171eaf86f5e923cf8beaeab3366383eb23de3bd6 100644 --- a/alib2algo/src/automaton/run/Result.h +++ b/alib2algo/src/automaton/run/Result.h @@ -31,7 +31,7 @@ public: static label::Label result ( const automaton::DFA < > & automaton, const string::LinearString < > & string, const label::Label & failLabel = label::FailStateLabel::FAIL_STATE_LABEL ); 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::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::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 aad61b2a7038fd3bb5a614a68b557511708b3c76..8a7fa1d880f4733c1f65eeaecff670a8b96a6c81 100644 --- a/alib2algo/src/automaton/run/Run.cpp +++ b/alib2algo/src/automaton/run/Run.cpp @@ -217,7 +217,7 @@ bool Run::canPop ( const std::deque < alphabet::Symbol > & pushdownStore, const // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::InputDrivenDPDA & automaton, const string::LinearString < > & string ) { +std::tuple < bool, label::Label, std::set < unsigned >, std::deque < alphabet::Symbol > > Run::calculateState ( const automaton::InputDrivenDPDA < > & automaton, const string::LinearString < > & string ) { label::Label state = automaton.getInitialState ( ); std::deque < alphabet::Symbol > pushdownStore { automaton.getInitialSymbol ( ) diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h index 300b7dc6e163ada527e700b66ede698b38336ba0..52bf847fa86c12dda01f9a6455108f15d899a26d 100644 --- a/alib2algo/src/automaton/run/Run.h +++ b/alib2algo/src/automaton/run/Run.h @@ -29,7 +29,7 @@ public: static std::tuple < bool, std::set < label::Label >, std::set < unsigned > > calculateStates ( const automaton::NFA < > & automaton, const string::LinearString < > & string ); static std::tuple < bool, label::Label, std::set < unsigned > > calculateState ( const automaton::DFTA & automaton, const tree::RankedTree & tree ); 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::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::DPDA < > & automaton, const string::LinearString < > & string ); diff --git a/alib2algo/src/automaton/simplify/Rename.cpp b/alib2algo/src/automaton/simplify/Rename.cpp index 98857ad0762c654b9ae3afa6a5ca69695f253173..1679f75d97243a1f80d8ff41f760ca4b38b8492e 100644 --- a/alib2algo/src/automaton/simplify/Rename.cpp +++ b/alib2algo/src/automaton/simplify/Rename.cpp @@ -139,7 +139,7 @@ automaton::SinglePopDPDA Rename::rename(const automaton::SinglePopDPDA& pda) { auto RenameSinglePopDPDA = Rename::RegistratorWrapper<automaton::SinglePopDPDA, automaton::SinglePopDPDA>(Rename::rename); -automaton::InputDrivenDPDA Rename::rename(const automaton::InputDrivenDPDA& pda) { +automaton::InputDrivenDPDA < > Rename::rename(const automaton::InputDrivenDPDA < > & pda) { int counter = 0; std::map<label::Label, int > renamingData; int counterSymbol = 0; @@ -152,7 +152,7 @@ automaton::InputDrivenDPDA Rename::rename(const automaton::InputDrivenDPDA& pda) for(const alphabet::Symbol & symbol : pda.getPushdownStoreAlphabet()) renamingDataSymbol.insert(std::make_pair(symbol, counterSymbol++)); - automaton::InputDrivenDPDA result(label::labelFrom(renamingData.find(pda.getInitialState())->second), alphabet::symbolFrom(renamingDataSymbol.find(pda.getInitialSymbol())->second)); + automaton::InputDrivenDPDA < > result(label::labelFrom(renamingData.find(pda.getInitialState())->second), alphabet::symbolFrom(renamingDataSymbol.find(pda.getInitialSymbol())->second)); result.setInputAlphabet(pda.getInputAlphabet()); @@ -186,7 +186,7 @@ automaton::InputDrivenDPDA Rename::rename(const automaton::InputDrivenDPDA& pda) return result; } -auto RenameInputDrivenDPDA = Rename::RegistratorWrapper<automaton::InputDrivenDPDA, automaton::InputDrivenDPDA>(Rename::rename); +auto RenameInputDrivenDPDA = Rename::RegistratorWrapper<automaton::InputDrivenDPDA < >, automaton::InputDrivenDPDA < > >(Rename::rename); automaton::VisiblyPushdownDPDA Rename::rename(const automaton::VisiblyPushdownDPDA& pda) { int counterState = 0; diff --git a/alib2algo/src/automaton/simplify/Rename.h b/alib2algo/src/automaton/simplify/Rename.h index 237e6a34d332181034452ae797f25f9f95fe14f2..540f99726451a2115ed4e71b87d7eb4d8c573e31 100644 --- a/alib2algo/src/automaton/simplify/Rename.h +++ b/alib2algo/src/automaton/simplify/Rename.h @@ -31,7 +31,7 @@ public: static automaton::DFA<> rename(const automaton::DFA<>& dfa); static automaton::DPDA < > rename(const automaton::DPDA < > & pda); static automaton::SinglePopDPDA rename(const automaton::SinglePopDPDA& pda); - static automaton::InputDrivenDPDA rename(const automaton::InputDrivenDPDA& 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); }; diff --git a/alib2algo/test-src/automaton/determinize/determinizeTest.cpp b/alib2algo/test-src/automaton/determinize/determinizeTest.cpp index c94e9e6af58d2b01b1b401f7f0cc80f59deb46c2..182a5c5797ab035ef1610ae28ca665487080e102 100644 --- a/alib2algo/test-src/automaton/determinize/determinizeTest.cpp +++ b/alib2algo/test-src/automaton/determinize/determinizeTest.cpp @@ -58,7 +58,7 @@ void determinizeTest::testDeterminizeIDPDA() { automaton.addFinalState(label::labelFrom(3)); - automaton::InputDrivenDPDA determinized = automaton::determinize::Determinize::determinize(automaton); + automaton::InputDrivenDPDA < > determinized = automaton::determinize::Determinize::determinize(automaton); CPPUNIT_ASSERT(determinized.getStates().size() == 3); } diff --git a/alib2data/src/automaton/AutomatonFeatures.h b/alib2data/src/automaton/AutomatonFeatures.h index 70b465f57da8c417ae911cd437932c1b1a4f90de..e4190c42b18b7039a77c7070e4c6410b0097daab 100644 --- a/alib2data/src/automaton/AutomatonFeatures.h +++ b/alib2data/src/automaton/AutomatonFeatures.h @@ -54,6 +54,7 @@ class ExtendedNFA; template<class SymbolType = typename alphabet::Symbol, class EpsilonType = typename string::Epsilon < SymbolType >, class StateType = typename label::Label > class DPDA; class SinglePopDPDA; +template<class SymbolType = typename alphabet::Symbol, class StateType = typename label::Label > class InputDrivenDPDA; class InputDrivenNPDA; class VisiblyPushdownDPDA; diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp b/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp index 1c639a672bd59d9e9d035ba6be1ac820568fd7d4..03d7a154a9353a914ef35f24b2ded09503c7dd26 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp @@ -6,250 +6,13 @@ */ #include "InputDrivenDPDA.h" -#include <ostream> -#include <sstream> -#include <algorithm> - -#include <sax/FromXMLParserHelper.h> -#include "../common/AutomatonFromXMLParser.h" -#include "../common/AutomatonToXMLComposer.h" #include "../Automaton.h" #include <object/Object.h> #include <XmlApi.hpp> -namespace automaton { - -InputDrivenDPDA::InputDrivenDPDA ( std::set < label::Label > states, std::set < alphabet::Symbol > inputAlphabet, std::set < alphabet::Symbol > pushdownStoreAlphabet, label::Label initialState, alphabet::Symbol initialSymbol, std::set < label::Label > finalStates ) : std::Components < InputDrivenDPDA, alphabet::Symbol, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < InitialSymbol >, label::Label, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ) ), std::make_tuple ( std::move ( initialSymbol ) ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { -} - -InputDrivenDPDA::InputDrivenDPDA(label::Label initialState, alphabet::Symbol initialPushdownSymbol) : InputDrivenDPDA ( std::set < label::Label > { initialState }, std::set < alphabet::Symbol > { }, std::set < alphabet::Symbol > { initialPushdownSymbol }, initialState, initialPushdownSymbol, std::set < label::Label > { }) { -} - -AutomatonBase* InputDrivenDPDA::clone() const { - return new InputDrivenDPDA(*this); -} - -AutomatonBase* InputDrivenDPDA::plunder() && { - return new InputDrivenDPDA(std::move(*this)); -} - -void InputDrivenDPDA::checkPushdownStoreOperation(const alphabet::Symbol& input, const std::vector<alphabet::Symbol>& pop, const std::vector<alphabet::Symbol>& push) { - if (! getInputAlphabet().count(input)) { - throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); - } - - for(const alphabet::Symbol& popSymbol : pop) { - if (! getPushdownStoreAlphabet().count(popSymbol)) { - throw AutomatonException("Pushdown store symbol \"" + std::to_string ( popSymbol ) + "\" doesn't exist."); - } - } - - for(const alphabet::Symbol& pushSymbol : push) { - if (! getPushdownStoreAlphabet().count(pushSymbol)) { - throw AutomatonException("Pushdown store symbol \"" + std::to_string ( pushSymbol ) + "\" doesn't exist."); - } - } -} - -bool InputDrivenDPDA::setPushdownStoreOperation(alphabet::Symbol input, std::vector<alphabet::Symbol> pop, std::vector<alphabet::Symbol> push) { - checkPushdownStoreOperation(input, pop, push); - return inputSymbolToPushdownStoreOperation.insert(std::make_pair(std::move(input), std::make_pair(std::move(pop), std::move(push)))).second; -} - -void InputDrivenDPDA::setPushdownStoreOperations(std::map<alphabet::Symbol, std::pair<std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol>>> operations) { - std::set<alphabet::Symbol> removed; - std::set_difference(getInputAlphabet().begin(), getInputAlphabet().end(), key_begin(operations), key_end(operations), std::inserter(removed, removed.end())); - - for(const alphabet::Symbol& removedSymbol : removed) { - clearPushdownStoreOperation(removedSymbol); - } - - for(const auto& added : operations) { - checkPushdownStoreOperation(added.first, added.second.first, added.second.second); - } - - inputSymbolToPushdownStoreOperation = std::move(operations); -} - -bool InputDrivenDPDA::clearPushdownStoreOperation(const alphabet::Symbol& input) { - for (const std::pair<const std::pair<label::Label, alphabet::Symbol>, label::Label>& transition : transitions) { - if (transition.first.second == input) - throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" is used."); - } - - return inputSymbolToPushdownStoreOperation.erase(input); -} - -const std::map<alphabet::Symbol, std::pair<std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol>>>& InputDrivenDPDA::getPushdownStoreOperations() const { - return inputSymbolToPushdownStoreOperation; -} - -bool InputDrivenDPDA::addTransition(label::Label from, alphabet::Symbol input, label::Label to) { - if (!getStates().count(from)) - throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); - - if (!getInputAlphabet().count(input)) - throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); - - if (! getPushdownStoreOperations().count(input)) - throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); - - if (! getStates().count(to)) - throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); - - std::pair<label::Label, alphabet::Symbol> key = std::make_pair(std::move(from), std::move(input)); - - if (transitions.find(key) != transitions.end()) { - if(transitions.find(key)->second == to) - return false; - else - throw AutomatonException( "Transition from this state and symbol already exists (\"" + std::to_string ( key.first ) + "\", \"" + std::to_string ( key.second ) + "\") -> \"" + std::to_string ( to ) + "\"." ); - } - - transitions.insert(std::make_pair(std::move(key), std::move(to))); - return true; -} - -bool InputDrivenDPDA::removeTransition(const label::Label& from, const alphabet::Symbol& input, const label::Label& to) { - std::pair<label::Label, alphabet::Symbol> key = std::make_pair(from, input); - - if (transitions.find(key) == transitions.end()) - return false; - - if(transitions.find(key)->second != to) - throw AutomatonException( "Transition (\"" + std::to_string ( from ) + "\", \"" + std::to_string ( input ) + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); - - transitions.erase(key); - return true; -} - -const std::map<std::pair<label::Label, alphabet::Symbol>, label::Label>& InputDrivenDPDA::getTransitions() const { - return transitions; -} - -std::map<std::pair<label::Label, alphabet::Symbol>, label::Label > InputDrivenDPDA::getTransitionsFromState(const label::Label& from) const { - if( ! getStates().count(from)) - throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist"); - - std::map<std::pair<label::Label, alphabet::Symbol>, label::Label> transitionsFromState; - for (const std::pair<const std::pair<label::Label, alphabet::Symbol>, label::Label>& transition : transitions) { - if (transition.first.first == from) { - transitionsFromState.insert(transition); - } - } - - return transitionsFromState; -} - -std::map<std::pair<label::Label, alphabet::Symbol>, label::Label> InputDrivenDPDA::getTransitionsToState(const label::Label& to) const { - if( ! getStates().count(to)) - throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist"); - - std::map<std::pair<label::Label, alphabet::Symbol>, label::Label> transitionsToState; - for (const std::pair<const std::pair<label::Label, alphabet::Symbol>, label::Label>& transition : transitions) { - if (transition.second == to) { - transitionsToState.insert(transition); - } - } - - return transitionsToState; -} - -int InputDrivenDPDA::compare(const InputDrivenDPDA& other) const { - auto first = std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getInitialSymbol(), getPushdownStoreOperations(), transitions); - auto second = std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.getPushdownStoreOperations(), other.transitions); - - std::compare<decltype(first)> comp; - return comp(first, second); -} - -void InputDrivenDPDA::operator>>(std::ostream& out) const { - out << "(InputDrivenDPDA " - << " states = " << getStates() - << " inputAlphabet = " << getInputAlphabet() - << " initialState = " << getInitialState() - << " finalStates = " << getFinalStates() - << " pushdownStoreAlphabet = " << getPushdownStoreAlphabet() - << " initialSymbol = " << getInitialSymbol() - << " transitions = " << transitions - << " inputSymbolToPushdownStoreOperation = " << getPushdownStoreOperations() - << ")"; -} - -InputDrivenDPDA::operator std::string () const { - std::stringstream ss; - ss << *this; - return ss.str(); -} - -InputDrivenDPDA InputDrivenDPDA::parse(std::deque<sax::Token>::iterator& input) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, InputDrivenDPDA::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> pushdownStoreSymbols = AutomatonFromXMLParser::parsePushdownStoreAlphabet<alphabet::Symbol>(input); - label::Label initialState = AutomatonFromXMLParser::parseInitialState<label::Label>(input); - alphabet::Symbol initialPushdownStoreSymbol = AutomatonFromXMLParser::parseInitialPushdownStoreSymbol<alphabet::Symbol>(input); - std::set<label::Label> finalStates = AutomatonFromXMLParser::parseFinalStates<label::Label>(input); - - InputDrivenDPDA automaton(std::move(initialState), std::move(initialPushdownStoreSymbol)); - automaton.setStates(std::move(states)); - automaton.setInputAlphabet(std::move(inputSymbols)); - automaton.setPushdownStoreAlphabet(std::move(pushdownStoreSymbols)); - automaton.setFinalStates(std::move(finalStates)); - - automaton.setPushdownStoreOperations(AutomatonFromXMLParser::parseInputToPushdownStoreOperation<alphabet::Symbol>(input)); - AutomatonFromXMLParser::parseTransitions<InputDrivenDPDA>(input, automaton); - - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, InputDrivenDPDA::getXmlTagName()); - return automaton; -} - -void InputDrivenDPDA::parseTransition(std::deque<sax::Token>::iterator& input, InputDrivenDPDA& automaton) { - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "transition"); - label::Label from = AutomatonFromXMLParser::parseTransitionFrom<label::Label>(input); - alphabet::Symbol inputSymbol = AutomatonFromXMLParser::parseTransitionInputSymbol<alphabet::Symbol>(input); - label::Label to = AutomatonFromXMLParser::parseTransitionTo<label::Label>(input); - sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "transition"); - - automaton.addTransition(std::move(from), std::move(inputSymbol), std::move(to)); -} - -void InputDrivenDPDA::compose(std::deque<sax::Token>& out) const { - out.emplace_back(InputDrivenDPDA::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::composeInitialPushdownStoreSymbol(out, this->getInitialSymbol()); - AutomatonToXMLComposer::composeFinalStates(out, this->getFinalStates()); - AutomatonToXMLComposer::composeInputToPushdownStoreOperation(out, this->getPushdownStoreOperations()); - composeTransitions(out); - - out.emplace_back(InputDrivenDPDA::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); -} - -void InputDrivenDPDA::composeTransitions(std::deque<sax::Token>& out) const { - out.emplace_back("transitions", sax::Token::TokenType::START_ELEMENT); - for(const auto& transition : this->getTransitions()) { - out.emplace_back("transition", sax::Token::TokenType::START_ELEMENT); - - AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); - AutomatonToXMLComposer::composeTransitionInputSymbol(out, transition.first.second); - AutomatonToXMLComposer::composeTransitionTo(out, transition.second); - - out.emplace_back("transition", sax::Token::TokenType::END_ELEMENT); - } - - out.emplace_back("transitions", sax::Token::TokenType::END_ELEMENT); -} - -} /* namespace automaton */ - namespace alib { -auto inputDivenDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::InputDrivenDPDA>(); -auto inputDivenDPDAParserRegister2 = xmlApi<alib::Object>::ParserRegister<automaton::InputDrivenDPDA>(); +auto inputDivenDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::InputDrivenDPDA < > >(); +auto inputDivenDPDAParserRegister2 = xmlApi<alib::Object>::ParserRegister<automaton::InputDrivenDPDA< > >(); } /* namespace alib */ diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index c05677fcaefac2df54706b34ebc49201c914de8e..fda88351246a434ccaa3ccc45fc12be03614b9fc 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -8,13 +8,20 @@ #ifndef INPUT_DRIVEN_DPDA_H_ #define INPUT_DRIVEN_DPDA_H_ -#include "../AutomatonException.h" #include <map> #include <vector> +#include <ostream> +#include <sstream> +#include <algorithm> + #include <core/components.hpp> +#include <sax/FromXMLParserHelper.h> + #include "../AutomatonBase.h" -#include "../../alphabet/Symbol.h" -#include "../../label/Label.h" +#include "../AutomatonFeatures.h" +#include "../AutomatonException.h" +#include "../common/AutomatonFromXMLParser.h" +#include "../common/AutomatonToXMLComposer.h" namespace automaton { @@ -29,116 +36,117 @@ class InitialState; * Represents Finite Automaton. * Can store nondeterministic finite automaton without epsilon transitions. */ -class InputDrivenDPDA : public AutomatonBase, public std::Components < InputDrivenDPDA, alphabet::Symbol, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < InitialSymbol >, label::Label, std::tuple < States, FinalStates >, std::tuple < InitialState > > { +template < class SymbolType, class StateType > +class InputDrivenDPDA : public AutomatonBase, public std::Components < InputDrivenDPDA < SymbolType, StateType >, SymbolType, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < InitialSymbol >, StateType, std::tuple < States, FinalStates >, std::tuple < InitialState > > { protected: - std::map < std::pair < label::Label, alphabet::Symbol >, label::Label > transitions; - std::map < alphabet::Symbol, std::pair < std::vector < alphabet::Symbol >, std::vector < alphabet::Symbol > > > inputSymbolToPushdownStoreOperation; + std::map < std::pair < StateType, SymbolType >, StateType > transitions; + std::map < SymbolType, std::pair < std::vector < SymbolType >, std::vector < SymbolType > > > inputSymbolToPushdownStoreOperation; - void checkPushdownStoreOperation ( const alphabet::Symbol & input, const std::vector < alphabet::Symbol > & pop, const std::vector < alphabet::Symbol > & push ); + void checkPushdownStoreOperation ( const SymbolType & input, const std::vector < SymbolType > & pop, const std::vector < SymbolType > & push ); public: - explicit InputDrivenDPDA ( std::set < label::Label > states, std::set < alphabet::Symbol > inputAlphabet, std::set < alphabet::Symbol > pushdownStoreSymbol, label::Label initialState, alphabet::Symbol initialPushdownSymbol, std::set < label::Label > finalStates ); - explicit InputDrivenDPDA ( label::Label initialState, alphabet::Symbol initialPushdownSymbol ); + explicit InputDrivenDPDA ( std::set < StateType > states, std::set < SymbolType > inputAlphabet, std::set < SymbolType > pushdownStoreSymbol, StateType initialState, SymbolType initialPushdownSymbol, std::set < StateType > finalStates ); + explicit InputDrivenDPDA ( StateType initialState, SymbolType initialPushdownSymbol ); 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 & getInitialSymbol ( ) const { - return accessElement < InitialSymbol > ( ).get ( ); + const SymbolType & getInitialSymbol ( ) const { + return this->template accessElement < InitialSymbol > ( ).get ( ); } - bool setInitialSymbol ( alphabet::Symbol symbol ) { - return accessElement < InitialSymbol > ( ).set ( std::move ( symbol ) ); + bool setInitialSymbol ( SymbolType symbol ) { + return this->template accessElement < InitialSymbol > ( ).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 ); } - bool setPushdownStoreOperation ( alphabet::Symbol input, std::vector < alphabet::Symbol > pop, std::vector < alphabet::Symbol > push ); + bool setPushdownStoreOperation ( SymbolType input, std::vector < SymbolType > pop, std::vector < SymbolType > push ); - void setPushdownStoreOperations ( std::map < alphabet::Symbol, std::pair < std::vector < alphabet::Symbol >, std::vector < alphabet::Symbol > > > operations ); + void setPushdownStoreOperations ( std::map < SymbolType, std::pair < std::vector < SymbolType >, std::vector < SymbolType > > > operations ); - bool clearPushdownStoreOperation ( const alphabet::Symbol & input ); + bool clearPushdownStoreOperation ( const SymbolType & input ); - const std::map < alphabet::Symbol, std::pair < std::vector < alphabet::Symbol >, std::vector < alphabet::Symbol > > > & getPushdownStoreOperations ( ) const; + const std::map < SymbolType, std::pair < std::vector < SymbolType >, std::vector < SymbolType > > > & getPushdownStoreOperations ( ) const; /** * Adds transition defined by parameters to the automaton. @@ -147,23 +155,23 @@ public: * @param next next state * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton */ - bool addTransition ( label::Label current, alphabet::Symbol input, label::Label next ); + bool addTransition ( StateType current, SymbolType input, StateType next ); /** * Removes transition from the automaton. * @param transition transition to remove * @throws AutomatonException when transition doesn't exists. */ - bool removeTransition ( const label::Label & current, const alphabet::Symbol & input, const label::Label & next ); + bool removeTransition ( const StateType & current, const SymbolType & input, const StateType & next ); /** * @return automaton transitions */ - const std::map < std::pair < label::Label, alphabet::Symbol >, label::Label > & getTransitions ( ) const; + const std::map < std::pair < StateType, SymbolType >, StateType > & getTransitions ( ) const; - std::map < std::pair < label::Label, alphabet::Symbol >, label::Label > getTransitionsFromState ( const label::Label & from ) const; + std::map < std::pair < StateType, SymbolType >, StateType > getTransitionsFromState ( const StateType & from ) const; - std::map < std::pair < label::Label, alphabet::Symbol >, label::Label > getTransitionsToState ( const label::Label & to ) const; + std::map < std::pair < StateType, SymbolType >, StateType > getTransitionsToState ( const StateType & to ) const; /** * Determines whether InputDrivenDPDA is deterministic. @@ -200,33 +208,280 @@ public: void composeTransitions ( std::deque < sax::Token > & out ) const; }; +template < class SymbolType, class StateType > +InputDrivenDPDA < SymbolType, StateType >::InputDrivenDPDA ( std::set < StateType > states, std::set < SymbolType > inputAlphabet, std::set < SymbolType > pushdownStoreAlphabet, StateType initialState, SymbolType initialSymbol, std::set < StateType > finalStates ) : std::Components < InputDrivenDPDA, SymbolType, std::tuple < InputAlphabet, PushdownStoreAlphabet >, std::tuple < InitialSymbol >, StateType, std::tuple < States, FinalStates >, std::tuple < InitialState > > ( std::make_tuple ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ) ), std::make_tuple ( std::move ( initialSymbol ) ), std::make_tuple ( std::move ( states ), std::move ( finalStates ) ), std::make_tuple ( std::move ( initialState ) ) ) { +} + +template < class SymbolType, class StateType > +InputDrivenDPDA < SymbolType, StateType >::InputDrivenDPDA(StateType initialState, SymbolType initialPushdownSymbol) : InputDrivenDPDA ( std::set < StateType > { initialState }, std::set < SymbolType > { }, std::set < SymbolType > { initialPushdownSymbol }, initialState, initialPushdownSymbol, std::set < StateType > { }) { +} + +template < class SymbolType, class StateType > +AutomatonBase* InputDrivenDPDA < SymbolType, StateType >::clone() const { + return new InputDrivenDPDA(*this); +} + +template < class SymbolType, class StateType > +AutomatonBase* InputDrivenDPDA < SymbolType, StateType >::plunder() && { + return new InputDrivenDPDA(std::move(*this)); +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::checkPushdownStoreOperation(const SymbolType& input, const std::vector<SymbolType>& pop, const std::vector<SymbolType>& push) { + if (! getInputAlphabet().count(input)) { + throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); + } + + for(const SymbolType& popSymbol : pop) { + if (! getPushdownStoreAlphabet().count(popSymbol)) { + throw AutomatonException("Pushdown store symbol \"" + std::to_string ( popSymbol ) + "\" doesn't exist."); + } + } + + for(const SymbolType& pushSymbol : push) { + if (! getPushdownStoreAlphabet().count(pushSymbol)) { + throw AutomatonException("Pushdown store symbol \"" + std::to_string ( pushSymbol ) + "\" doesn't exist."); + } + } +} + +template < class SymbolType, class StateType > +bool InputDrivenDPDA < SymbolType, StateType >::setPushdownStoreOperation(SymbolType input, std::vector<SymbolType> pop, std::vector<SymbolType> push) { + checkPushdownStoreOperation(input, pop, push); + return inputSymbolToPushdownStoreOperation.insert(std::make_pair(std::move(input), std::make_pair(std::move(pop), std::move(push)))).second; +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::setPushdownStoreOperations(std::map<SymbolType, std::pair<std::vector<SymbolType>, std::vector<SymbolType>>> operations) { + std::set<SymbolType> removed; + std::set_difference(getInputAlphabet().begin(), getInputAlphabet().end(), key_begin(operations), key_end(operations), std::inserter(removed, removed.end())); + + for(const SymbolType& removedSymbol : removed) { + clearPushdownStoreOperation(removedSymbol); + } + + for(const auto& added : operations) { + checkPushdownStoreOperation(added.first, added.second.first, added.second.second); + } + + inputSymbolToPushdownStoreOperation = std::move(operations); +} + +template < class SymbolType, class StateType > +bool InputDrivenDPDA < SymbolType, StateType >::clearPushdownStoreOperation(const SymbolType& input) { + for (const std::pair<const std::pair<StateType, SymbolType>, StateType>& transition : transitions) { + if (transition.first.second == input) + throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" is used."); + } + + return inputSymbolToPushdownStoreOperation.erase(input); +} + +template < class SymbolType, class StateType > +const std::map<SymbolType, std::pair<std::vector<SymbolType>, std::vector<SymbolType>>>& InputDrivenDPDA < SymbolType, StateType >::getPushdownStoreOperations() const { + return inputSymbolToPushdownStoreOperation; +} + +template < class SymbolType, class StateType > +bool InputDrivenDPDA < SymbolType, StateType >::addTransition(StateType from, SymbolType input, StateType to) { + if (!getStates().count(from)) + throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist."); + + if (!getInputAlphabet().count(input)) + throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); + + if (! getPushdownStoreOperations().count(input)) + throw AutomatonException("Input symbol \"" + std::to_string ( input ) + "\" doesn't exist."); + + if (! getStates().count(to)) + throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist."); + + std::pair<StateType, SymbolType> key = std::make_pair(std::move(from), std::move(input)); + + if (transitions.find(key) != transitions.end()) { + if(transitions.find(key)->second == to) + return false; + else + throw AutomatonException( "Transition from this state and symbol already exists (\"" + std::to_string ( key.first ) + "\", \"" + std::to_string ( key.second ) + "\") -> \"" + std::to_string ( to ) + "\"." ); + } + + transitions.insert(std::make_pair(std::move(key), std::move(to))); + return true; +} + +template < class SymbolType, class StateType > +bool InputDrivenDPDA < SymbolType, StateType >::removeTransition(const StateType& from, const SymbolType& input, const StateType& to) { + std::pair<StateType, SymbolType> key = std::make_pair(from, input); + + if (transitions.find(key) == transitions.end()) + return false; + + if(transitions.find(key)->second != to) + throw AutomatonException( "Transition (\"" + std::to_string ( from ) + "\", \"" + std::to_string ( input ) + "\") -> \"" + std::to_string ( to ) + "\" doesn't exist."); + + transitions.erase(key); + return true; +} + +template < class SymbolType, class StateType > +const std::map<std::pair<StateType, SymbolType>, StateType>& InputDrivenDPDA < SymbolType, StateType >::getTransitions() const { + return transitions; +} + +template < class SymbolType, class StateType > +std::map<std::pair<StateType, SymbolType>, StateType > InputDrivenDPDA < SymbolType, StateType >::getTransitionsFromState(const StateType& from) const { + if( ! getStates().count(from)) + throw AutomatonException("State \"" + std::to_string ( from ) + "\" doesn't exist"); + + std::map<std::pair<StateType, SymbolType>, StateType> transitionsFromState; + for (const std::pair<const std::pair<StateType, SymbolType>, StateType>& transition : transitions) { + if (transition.first.first == from) { + transitionsFromState.insert(transition); + } + } + + return transitionsFromState; +} + +template < class SymbolType, class StateType > +std::map<std::pair<StateType, SymbolType>, StateType> InputDrivenDPDA < SymbolType, StateType >::getTransitionsToState(const StateType& to) const { + if( ! getStates().count(to)) + throw AutomatonException("State \"" + std::to_string ( to ) + "\" doesn't exist"); + + std::map<std::pair<StateType, SymbolType>, StateType> transitionsToState; + for (const std::pair<const std::pair<StateType, SymbolType>, StateType>& transition : transitions) { + if (transition.second == to) { + transitionsToState.insert(transition); + } + } + + return transitionsToState; +} + +template < class SymbolType, class StateType > +int InputDrivenDPDA < SymbolType, StateType >::compare(const InputDrivenDPDA& other) const { + auto first = std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getInitialSymbol(), getPushdownStoreOperations(), transitions); + auto second = std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.getPushdownStoreOperations(), other.transitions); + + std::compare<decltype(first)> comp; + return comp(first, second); +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::operator>>(std::ostream& out) const { + out << "(InputDrivenDPDA " + << " states = " << getStates() + << " inputAlphabet = " << getInputAlphabet() + << " initialState = " << getInitialState() + << " finalStates = " << getFinalStates() + << " pushdownStoreAlphabet = " << getPushdownStoreAlphabet() + << " initialSymbol = " << getInitialSymbol() + << " transitions = " << transitions + << " inputSymbolToPushdownStoreOperation = " << getPushdownStoreOperations() + << ")"; +} + +template < class SymbolType, class StateType > +InputDrivenDPDA < SymbolType, StateType >::operator std::string () const { + std::stringstream ss; + ss << *this; + return ss.str(); +} + +template < class SymbolType, class StateType > +InputDrivenDPDA < SymbolType, StateType > InputDrivenDPDA < SymbolType, StateType >::parse(std::deque<sax::Token>::iterator& input) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, InputDrivenDPDA::getXmlTagName()); + + std::set<StateType> states = AutomatonFromXMLParser::parseStates<StateType>(input); + std::set<SymbolType> inputSymbols = AutomatonFromXMLParser::parseInputAlphabet<SymbolType>(input); + std::set<SymbolType> pushdownStoreSymbols = AutomatonFromXMLParser::parsePushdownStoreAlphabet<SymbolType>(input); + StateType initialState = AutomatonFromXMLParser::parseInitialState<StateType>(input); + SymbolType initialPushdownStoreSymbol = AutomatonFromXMLParser::parseInitialPushdownStoreSymbol<SymbolType>(input); + std::set<StateType> finalStates = AutomatonFromXMLParser::parseFinalStates<StateType>(input); + + InputDrivenDPDA < SymbolType, StateType > automaton(std::move(initialState), std::move(initialPushdownStoreSymbol)); + automaton.setStates(std::move(states)); + automaton.setInputAlphabet(std::move(inputSymbols)); + automaton.setPushdownStoreAlphabet(std::move(pushdownStoreSymbols)); + automaton.setFinalStates(std::move(finalStates)); + + automaton.setPushdownStoreOperations(AutomatonFromXMLParser::parseInputToPushdownStoreOperation<SymbolType>(input)); + AutomatonFromXMLParser::parseTransitions<InputDrivenDPDA>(input, automaton); + + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, InputDrivenDPDA::getXmlTagName()); + return automaton; +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::parseTransition(std::deque<sax::Token>::iterator& input, InputDrivenDPDA& automaton) { + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::START_ELEMENT, "transition"); + StateType from = AutomatonFromXMLParser::parseTransitionFrom<StateType>(input); + SymbolType inputSymbol = AutomatonFromXMLParser::parseTransitionInputSymbol<SymbolType>(input); + StateType to = AutomatonFromXMLParser::parseTransitionTo<StateType>(input); + sax::FromXMLParserHelper::popToken(input, sax::Token::TokenType::END_ELEMENT, "transition"); + + automaton.addTransition(std::move(from), std::move(inputSymbol), std::move(to)); +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::compose(std::deque<sax::Token>& out) const { + out.emplace_back(InputDrivenDPDA::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::composeInitialPushdownStoreSymbol(out, this->getInitialSymbol()); + AutomatonToXMLComposer::composeFinalStates(out, this->getFinalStates()); + AutomatonToXMLComposer::composeInputToPushdownStoreOperation(out, this->getPushdownStoreOperations()); + composeTransitions(out); + + out.emplace_back(InputDrivenDPDA::getXmlTagName(), sax::Token::TokenType::END_ELEMENT); +} + +template < class SymbolType, class StateType > +void InputDrivenDPDA < SymbolType, StateType >::composeTransitions(std::deque<sax::Token>& out) const { + out.emplace_back("transitions", sax::Token::TokenType::START_ELEMENT); + for(const auto& transition : this->getTransitions()) { + out.emplace_back("transition", sax::Token::TokenType::START_ELEMENT); + + AutomatonToXMLComposer::composeTransitionFrom(out, transition.first.first); + AutomatonToXMLComposer::composeTransitionInputSymbol(out, transition.first.second); + AutomatonToXMLComposer::composeTransitionTo(out, transition.second); + + out.emplace_back("transition", sax::Token::TokenType::END_ELEMENT); + } + + out.emplace_back("transitions", sax::Token::TokenType::END_ELEMENT); +} + } /* namespace automaton */ namespace std { -template < > -class ComponentConstraint< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InputAlphabet > { +template < class SymbolType, class StateType > +class ComponentConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, SymbolType, automaton::InputAlphabet > { public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<label::Label, alphabet::Symbol>, label::Label>& transition : automaton.getTransitions()) + static bool used ( const automaton::InputDrivenDPDA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { + for (const std::pair<const std::pair<StateType, SymbolType>, StateType>& transition : automaton.getTransitions()) if (transition.first.second == symbol) return true; return false; } - static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const SymbolType & ) { return true; } - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const SymbolType & ) { } }; -template < > -class ComponentConstraint< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +template < class SymbolType, class StateType > +class ComponentConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, SymbolType, automaton::PushdownStoreAlphabet > { public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { + static bool used ( const automaton::InputDrivenDPDA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) return true; @@ -240,73 +495,73 @@ public: return false; } - static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const SymbolType & ) { return true; } - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const SymbolType & ) { } }; -template < > -class ElementConstraint< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InitialSymbol > { +template < class SymbolType, class StateType > +class ElementConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, SymbolType, automaton::InitialSymbol > { public: - static bool available ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > & automaton, const SymbolType & symbol ) { + return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); } - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const SymbolType & ) { } }; -template < > -class ComponentConstraint< automaton::InputDrivenDPDA, label::Label, automaton::States > { +template < class SymbolType, class StateType > +class ComponentConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, StateType, automaton::States > { public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const label::Label & state ) { + static bool used ( const automaton::InputDrivenDPDA < SymbolType, 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, alphabet::Symbol>, label::Label>& t : automaton.getTransitions()) + for (const std::pair<const std::pair<StateType, SymbolType>, StateType>& t : automaton.getTransitions()) if (t.first.first == state || t.second == state) return true; return false; } - static bool available ( const automaton::InputDrivenDPDA &, const label::Label & ) { + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const StateType & ) { return true; } - static void valid ( const automaton::InputDrivenDPDA &, const label::Label & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const StateType & ) { } }; -template < > -class ComponentConstraint< automaton::InputDrivenDPDA, label::Label, automaton::FinalStates > { +template < class SymbolType, class StateType > +class ComponentConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, StateType, automaton::FinalStates > { public: - static bool used ( const automaton::InputDrivenDPDA &, const label::Label & ) { + static bool used ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const StateType & ) { return false; } - static bool available ( const automaton::InputDrivenDPDA & automaton, const label::Label & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } - static void valid ( const automaton::InputDrivenDPDA &, const label::Label & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const StateType & ) { } }; -template < > -class ElementConstraint< automaton::InputDrivenDPDA, label::Label, automaton::InitialState > { +template < class SymbolType, class StateType > +class ElementConstraint< automaton::InputDrivenDPDA < SymbolType, StateType >, StateType, automaton::InitialState > { public: - static bool available ( const automaton::InputDrivenDPDA & automaton, const label::Label & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + static bool available ( const automaton::InputDrivenDPDA < SymbolType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } - static void valid ( const automaton::InputDrivenDPDA &, const label::Label & ) { + static void valid ( const automaton::InputDrivenDPDA < SymbolType, StateType > &, const StateType & ) { } };