From 8feefbbb6f14f2f5e370ffbac3861064fe2f6c7d Mon Sep 17 00:00:00 2001 From: Jan Travnicek <jan.travnicek@.fit.cvut.cz> Date: Thu, 4 Apr 2019 15:51:36 +0200 Subject: [PATCH] add typedef fields to automata datatypes for template parameters --- alib2data/src/automaton/Automaton.h | 4 +- alib2data/src/automaton/FSM/CompactDFA.h | 13 +- alib2data/src/automaton/FSM/CompactNFA.h | 13 +- alib2data/src/automaton/FSM/DFA.h | 13 +- alib2data/src/automaton/FSM/EpsilonNFA.h | 16 +- alib2data/src/automaton/FSM/ExtendedNFA.h | 13 +- .../FSM/MultiInitialStateEpsilonNFA.h | 16 +- .../src/automaton/FSM/MultiInitialStateNFA.h | 13 +- alib2data/src/automaton/FSM/NFA.h | 13 +- alib2data/src/automaton/PDA/DPDA.h | 20 +- alib2data/src/automaton/PDA/InputDrivenDPDA.h | 17 +- alib2data/src/automaton/PDA/InputDrivenNPDA.h | 17 +- alib2data/src/automaton/PDA/NPDA.h | 19 +- alib2data/src/automaton/PDA/NPDTA.h | 2376 +++++++++-------- .../PDA/RealTimeHeightDeterministicDPDA.h | 20 +- .../PDA/RealTimeHeightDeterministicNPDA.h | 20 +- alib2data/src/automaton/PDA/SinglePopDPDA.h | 20 +- alib2data/src/automaton/PDA/SinglePopNPDA.h | 20 +- .../src/automaton/PDA/VisiblyPushdownDPDA.h | 17 +- .../src/automaton/PDA/VisiblyPushdownNPDA.h | 19 +- alib2data/src/automaton/TA/DFTA.h | 16 +- alib2data/src/automaton/TA/NFTA.h | 16 +- alib2data/src/automaton/TM/OneTapeDTM.h | 15 +- 23 files changed, 1425 insertions(+), 1301 deletions(-) diff --git a/alib2data/src/automaton/Automaton.h b/alib2data/src/automaton/Automaton.h index 0e3dc4df43..6762d341c6 100644 --- a/alib2data/src/automaton/Automaton.h +++ b/alib2data/src/automaton/Automaton.h @@ -18,10 +18,10 @@ namespace automaton { class Automaton; template < class T > -using SymbolTypeOfAutomaton = typename std::decay < decltype (std::declval<T>().getInputAlphabet()) >::type::value_type; +using SymbolTypeOfAutomaton = typename T::SymbolType; template < class T > -using StateTypeOfAutomaton = typename std::decay < decltype (std::declval<T>().getStates()) >::type::value_type; +using StateTypeOfAutomaton = typename T::StateType; } /* namespace automaton */ diff --git a/alib2data/src/automaton/FSM/CompactDFA.h b/alib2data/src/automaton/FSM/CompactDFA.h index e23cfc24b9..ebf6bd470b 100644 --- a/alib2data/src/automaton/FSM/CompactDFA.h +++ b/alib2data/src/automaton/FSM/CompactDFA.h @@ -68,11 +68,16 @@ class InitialState; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T*, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class CompactDFA final : public ext::CompareOperators < CompactDFA < SymbolType, StateType > >, public core::Components < CompactDFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class CompactDFA final : public ext::CompareOperators < CompactDFA < SymbolTypeT, StateTypeT > >, public core::Components < CompactDFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times a list of input symbols on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index f119086212..51dcad7fbd 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -73,11 +73,16 @@ class InitialState; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T*, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class CompactNFA final : public ext::CompareOperators < CompactNFA < SymbolType, StateType > >, public core::Components < CompactNFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class CompactNFA final : public ext::CompareOperators < CompactNFA < SymbolTypeT, StateTypeT > >, public core::Components < CompactNFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times a list of input symbols on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index fce57c8a9d..0849a868de 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -66,11 +66,16 @@ class InitialState; * Note that target state of a transition is required. * This class is used to store minimal, total, ... variants of deterministic finite automata. * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class DFA final : public ext::CompareOperators < DFA < SymbolType, StateType > >, public core::Components < DFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class DFA final : public ext::CompareOperators < DFA < SymbolTypeT, StateTypeT > >, public core::Components < DFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol on the left hand side to a state. */ diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index 1f160d17bb..04b472d5f3 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -70,12 +70,18 @@ class InitialState; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T \cup \{\epsilon\}, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam EpsilonType used for the epislon in the automaton. - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam EpsilonTypeT used for the epislon in the automaton. + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class StateType = DefaultStateType > -class EpsilonNFA final : public ext::CompareOperators < EpsilonNFA < SymbolType, EpsilonType, StateType > >, public core::Components < EpsilonNFA < SymbolType, EpsilonType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class StateTypeT = DefaultStateType > +class EpsilonNFA final : public ext::CompareOperators < EpsilonNFA < SymbolTypeT, EpsilonTypeT, StateTypeT > >, public core::Components < EpsilonNFA < SymbolTypeT, EpsilonTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + typedef EpsilonTypeT EpsilonType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index d9434a9075..28095bf5c1 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -75,11 +75,16 @@ class InitialState; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in RegExpsOver(T), and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class ExtendedNFA final : public ext::CompareOperators < ExtendedNFA < SymbolType, StateType > >, public core::Components < ExtendedNFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class ExtendedNFA final : public ext::CompareOperators < ExtendedNFA < SymbolTypeT, StateTypeT > >, public core::Components < ExtendedNFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times a regular expression on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h index e45830d498..8cc26fcf57 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateEpsilonNFA.h @@ -72,12 +72,18 @@ class InitialStates; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T \cup \{\epsilon\}, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam EpsilonType used for the epislon in the automaton. - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam EpsilonTypeT used for the epislon in the automaton. + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class StateType = DefaultStateType > -class MultiInitialStateEpsilonNFA final : public ext::CompareOperators < MultiInitialStateEpsilonNFA < SymbolType, EpsilonType, StateType > >, public core::Components < MultiInitialStateEpsilonNFA < SymbolType, EpsilonType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +template < class SymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class StateTypeT = DefaultStateType > +class MultiInitialStateEpsilonNFA final : public ext::CompareOperators < MultiInitialStateEpsilonNFA < SymbolTypeT, EpsilonTypeT, StateTypeT > >, public core::Components < MultiInitialStateEpsilonNFA < SymbolTypeT, EpsilonTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + typedef EpsilonTypeT EpsilonType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h index 2833d28176..fe872870bf 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h @@ -65,11 +65,16 @@ class InitialStates; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class MultiInitialStateNFA final : public ext::CompareOperators < MultiInitialStateNFA < SymbolType, StateType > >, public core::Components < MultiInitialStateNFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class MultiInitialStateNFA final : public ext::CompareOperators < MultiInitialStateNFA < SymbolTypeT, StateTypeT > >, public core::Components < MultiInitialStateNFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index ab8a87d187..ce93f57ad7 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -61,11 +61,16 @@ class InitialState; * \delta = transition function of the form A \times a -> P(Q), where A \in Q, a \in T, and P(Q) is a powerset of states, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class NFA final : public ext::CompareOperators < NFA < SymbolType, StateType > >, public core::Components < NFA < SymbolType, StateType >, ext::set < SymbolType >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class NFA final : public ext::CompareOperators < NFA < SymbolTypeT, StateTypeT > >, public core::Components < NFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/PDA/DPDA.h b/alib2data/src/automaton/PDA/DPDA.h index d7a87e1b1c..ea1de656c2 100644 --- a/alib2data/src/automaton/PDA/DPDA.h +++ b/alib2data/src/automaton/PDA/DPDA.h @@ -73,14 +73,20 @@ class InitialState; * if $\delta (q, a, \alpha) \neq \emptyset$, $\delta (q, a, \beta) \neq \emptyset$ and $\alpha \neq \beta$, then $\alpha$ is not suffix of $\beta$ and $\beta$ is not suffix of $\alpha$ (formally $\gamma \alpha \neq \beta and \alpha \neq \gamma \beta$). * if $\delta(q, a, \alpha) \neq \emptyset$, $\delta (q, \varepsilon, \beta) \neq \emptyset$, then $\alpha$ is not suffix of $\beta$ and $\beta$ is not suffix of $\alpha$ (fornally $\gamma \alpha \neq \beta and \alpha \neq \gamma \beta$). * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class DPDA final : public ext::CompareOperators < DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class DPDA final : public ext::CompareOperators < DPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < DPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols. */ diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index cf781409f4..37ec6096af 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -72,13 +72,18 @@ class InitialState; * Note that target state of a transition is required. * This class is used to store minimal, total, ... variants of deterministic finite automata. * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class InputDrivenDPDA final : public ext::CompareOperators < InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > >, public core::Components < InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class InputDrivenDPDA final : public ext::CompareOperators < InputDrivenDPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < InputDrivenDPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol on the left hand side to a state. */ diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.h b/alib2data/src/automaton/PDA/InputDrivenNPDA.h index 75856e4331..72bf30c797 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.h @@ -72,13 +72,18 @@ class InitialState; * Note that target state of a transition is required. * This class is used to store minimal, total, ... variants of deterministic finite automata. * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class InputDrivenNPDA final : public ext::CompareOperators < InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > >, public core::Components < InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class InputDrivenNPDA final : public ext::CompareOperators < InputDrivenNPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < InputDrivenNPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/PDA/NPDA.h b/alib2data/src/automaton/PDA/NPDA.h index e709a6daa5..7d896485a7 100644 --- a/alib2data/src/automaton/PDA/NPDA.h +++ b/alib2data/src/automaton/PDA/NPDA.h @@ -68,13 +68,20 @@ class InitialState; * \delta = transition function of the form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G*, * F (FinalStates) = set of final states * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class NPDA final : public ext::CompareOperators < NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class NPDA final : public ext::CompareOperators < NPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < NPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols. */ diff --git a/alib2data/src/automaton/PDA/NPDTA.h b/alib2data/src/automaton/PDA/NPDTA.h index 856e132257..1447297ae0 100644 --- a/alib2data/src/automaton/PDA/NPDTA.h +++ b/alib2data/src/automaton/PDA/NPDTA.h @@ -1,1184 +1,1192 @@ -/* - * NPDTA.h - * - * This file is part of Algorithms library toolkit. - * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz) - - * Algorithms library toolkit is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * Algorithms library toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>. - * - * Created on: 10. 5. 2016 - * Author: Jakub Doupal - */ - -#ifndef NPDTA_H_ -#define NPDTA_H_ - -#include <sstream> - -#include <alib/set> -#include <alib/map> -#include <alib/vector> -#include <alib/variant> -#include <alib/algorithm> - -#include <core/components.hpp> - -#include <common/DefaultStateType.h> -#include <common/DefaultEpsilonType.h> -#include <common/DefaultSymbolType.h> - -#include <automaton/AutomatonException.h> - -#include <core/normalize.hpp> -#include <alphabet/common/SymbolNormalize.h> -#include <automaton/common/AutomatonNormalize.h> - -namespace automaton { - -class InputAlphabet; -class OutputAlphabet; -class PushdownStoreAlphabet; -class InitialSymbol; -class States; -class FinalStates; -class InitialState; - -/** - * Nondeterministic Pushdown Translation Automaton. Translates context free languages. - * - * \details - * Definition - * A = (Q, T, D, G, I, Z, \delta, F), - * Q (States) = nonempty finite set of states, - * T (TerminalAlphabet) = finite set of terminal symbols - having this empty won't let automaton do much though, - * T (OutputAlphabet) = finite set of output symbols - having this empty won't let automaton do translation at all, - * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA - * I (InitialState) = initial state, - * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol - * \delta = transition function of the form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D*, - * F (FinalStates) = set of final states - * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam OutputSymbolType used for the output alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. - */ -template < class InputSymbolType = DefaultSymbolType, class OutputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class NPDTA final : public ext::CompareOperators < NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < OutputSymbolType >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { - /** - * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols times string of output symbols. - */ - ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > transitions; - -public: - /** - * \brief Creates a new instance of the automaton with a concrete set of states, input alphabet, pushdown store alphabet, initial state, initial pushdown symbol and a set of final states. - * - * \param states the initial set of states of the automaton - * \param inputAlphabet the initial input alphabet - * \param outputAlphabet the initial output alphabet - * \param pushdownStoreAlphabet the initial set of symbols used in the pushdown store by the automaton - * \param initialState the initial state of the automaton - * \param initialPushdownSymbol the initial pushdown symbol of the automaton - * \param finalStates the initial set of final states of the automaton - */ - explicit NPDTA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < OutputSymbolType > outputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); - - /** - * \brief Creates a new instance of the automaton with a concrete initial state and initial pushdown store symbol. - * - * \param initialState the initial state of the automaton - * \param initialPushdownSymbol the initial pushdown symbol of the automaton - */ - explicit NPDTA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); - - /** - * Getter of the initial state. - * - * \returns the initial state of the automaton - */ - const StateType & getInitialState ( ) const & { - return this-> template accessComponent < InitialState > ( ).get ( ); - } - - /** - * Getter of the initial state. - * - * \returns the initial state of the automaton - */ - StateType && getInitialState ( ) && { - return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) ); - } - - /** - * Setter of the initial state. - * - * \param state new initial state of the automaton - * - * \returns true if the initial state was indeed changed - */ - bool setInitialState ( StateType state ) { - return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) ); - } - - /** - * Getter of states. - * - * \returns the states of the automaton - */ - const ext::set < StateType > & getStates ( ) const & { - return this-> template accessComponent < States > ( ).get ( ); - } - - /** - * Getter of states. - * - * \returns the states of the automaton - */ - ext::set < StateType > && getStates ( ) && { - return std::move ( this-> template accessComponent < States > ( ).get ( ) ); - } - - /** - * Adder of a state. - * - * \param state the new state to be added to a set of states - * - * \returns true if the state was indeed added - */ - bool addState ( StateType state ) { - return this-> template accessComponent < States > ( ).add ( std::move ( state ) ); - } - - /** - * Setter of states. - * - * \param states completely new set of states - */ - void setStates ( ext::set < StateType > states ) { - this-> template accessComponent < States > ( ).set ( std::move ( states ) ); - } - - /** - * Remover of a state. - * - * \param state a state to be removed from a set of states - * - * \returns true if the state was indeed removed - */ - void removeState ( const StateType & state ) { - this-> template accessComponent < States > ( ).remove ( state ); - } - - /** - * Getter of final states. - * - * \returns the final states of the automaton - */ - const ext::set < StateType > & getFinalStates ( ) const & { - return this-> template accessComponent < FinalStates > ( ).get ( ); - } - - /** - * Getter of final states. - * - * \returns the final states of the automaton - */ - ext::set < StateType > && getFinalStates ( ) && { - return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) ); - } - - /** - * Adder of a final state. - * - * \param state the new state to be added to a set of final states - * - * \returns true if the state was indeed added - */ - bool addFinalState ( StateType state ) { - return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); - } - - /** - * Setter of final states. - * - * \param states completely new set of final states - */ - void setFinalStates ( ext::set < StateType > states ) { - this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); - } - - /** - * Remover of a final state. - * - * \param state a state to be removed from a set of final states - * - * \returns true if the state was indeed removed - */ - void removeFinalState ( const StateType & state ) { - this-> template accessComponent < FinalStates > ( ).remove ( state ); - } - - /** - * Getter of the pushdown store alphabet. - * - * \returns the pushdown store alphabet of the automaton - */ - const ext::set < PushdownStoreSymbolType > & getPushdownStoreAlphabet ( ) const & { - return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ); - } - - /** - * Getter of the pushdown store alphabet. - * - * \returns the pushdown store alphabet of the automaton - */ - ext::set < PushdownStoreSymbolType > && getPushdownStoreAlphabet ( ) && { - return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ); - } - - /** - * Adder of a pushdown store symbol. - * - * \param symbol the new symbol to be added to a pushdown store alphabet - * - * \returns true if the symbol was indeed added - */ - bool addPushdownStoreSymbol ( PushdownStoreSymbolType symbol ) { - return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); - } - - /** - * Adder of pushdown store symbols. - * - * \param symbols new symbols to be added to a pushdown store alphabet - */ - void addPushdownStoreSymbols ( ext::set < PushdownStoreSymbolType > symbols ) { - this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); - } - - /** - * Setter of a pushdown store alphabet. - * - * \param symbols completely new pushdown store alphabet - */ - void setPushdownStoreAlphabet ( ext::set < PushdownStoreSymbolType > symbols ) { - this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); - } - - /** - * Remover of an pushdown store symbol. - * - * \param symbol a symbol to be removed from a pushdown store alphabet - * - * \returns true if the symbol was indeed removed - */ - void removePushdownStoreSymbol ( const PushdownStoreSymbolType & symbol ) { - this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); - } - - /** - * Getter of the initial pushdown store symbol. - * - * \returns the initial pushdown store symbol of the automaton - */ - const PushdownStoreSymbolType & getInitialSymbol ( ) const & { - return this->template accessComponent < InitialSymbol > ( ).get ( ); - } - - /** - * Getter of the initial pushdown store symbol. - * - * \returns the initial pushdown store symbol of the automaton - */ - PushdownStoreSymbolType && getInitialSymbol ( ) && { - return std::move ( this->template accessComponent < InitialSymbol > ( ).get ( ) ); - } - - /** - * Setter of the initial pushdown store symbol. - * - * \param symbol new initial pushdown store symbol of the automaton - * - * \returns true if the initial pushdown store symbol was indeed changed - */ - bool setInitialSymbol ( PushdownStoreSymbolType symbol ) { - return this->template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) ); - } - - /** - * Getter of the input alphabet. - * - * \returns the input alphabet of the automaton - */ - const ext::set < InputSymbolType > & getInputAlphabet ( ) const & { - return this-> template accessComponent < InputAlphabet > ( ).get ( ); - } - - /** - * Getter of the input alphabet. - * - * \returns the input alphabet of the automaton - */ - ext::set < InputSymbolType > && getInputAlphabet ( ) && { - return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) ); - } - - /** - * Adder of a input symbol. - * - * \param symbol the new symbol to be added to an input alphabet - * - * \returns true if the symbol was indeed added - */ - bool addInputSymbol ( InputSymbolType symbol ) { - return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); - } - - /** - * Adder to an input symbols. - * - * \param symbols new symbols to be added to an input alphabet - */ - void addInputSymbols ( ext::set < InputSymbolType > symbols ) { - this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); - } - - /** - * Setter of input alphabet. - * - * \param symbols completely new input alphabet - */ - void setInputAlphabet ( ext::set < InputSymbolType > symbols ) { - this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); - } - - /** - * Remover of an input symbol. - * - * \param symbol a symbol to be removed from an input alphabet - * - * \returns true if the symbol was indeed removed - */ - void removeInputSymbol ( const InputSymbolType & symbol ) { - this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); - } - - /** - * Getter of the input alphabet. - * - * \returns the input alphabet of the automaton - */ - const ext::set < OutputSymbolType > & getOutputAlphabet ( ) const & { - return this->template accessComponent < OutputAlphabet > ( ).get ( ); - } - - /** - * Getter of the input alphabet. - * - * \returns the input alphabet of the automaton - */ - ext::set < OutputSymbolType > && getOutputAlphabet ( ) && { - return std::move ( this->template accessComponent < OutputAlphabet > ( ).get ( ) ); - } - - /** - * Adder to an output symbol. - * - * \param symbol the new symbol to be added to an output alphabet - * - * \returns true if the symbol was indeed added - */ - bool addOutputSymbol ( OutputSymbolType symbol ) { - return this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbol ) ); - } - - /** - * Adder to an output symbols. - * - * \param symbols new symbols to be added to an output alphabet - */ - void addOutputSymbols ( ext::set < OutputSymbolType > symbols ) { - this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbols ) ); - } - - /** - * Setter of an output alphabet. - * - * \param symbols completely new output alphabet - */ - void setOutputAlphabet ( ext::set < OutputSymbolType > symbols ) { - this->template accessComponent < OutputAlphabet > ( ).set ( std::move ( symbols ) ); - } - - /** - * Remover of an output symbol. - * - * \param symbol a symbol to be removed from an output alphabet - * - * \returns true if the symbol was indeed removed - */ - void removeOutputSymbol ( const OutputSymbolType & symbol ) { - this->template accessComponent < OutputAlphabet > ( ).remove ( symbol ); - } - - /** - * \brief Adds a transition to the automaton. - * - * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma in D* - * - * \param from the source state (A) - * \param input the input symbol or epsilon (a) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols to be pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - * - * \returns true if the transition was indeed added - */ - bool addTransition ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); - - /** - * \brief Adds a transition to the automaton. - * - * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma in D* - * - * \param from the source state (A) - * \param input the input symbol (a) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols to be pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - * - * \returns true if the transition was indeed added - */ - bool addTransition ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); - - /** - * \brief Adds a transition to the automaton. - * - * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, \alpha, \beta \in G*, and \gamma in D* - * - * \param from the source state (A) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols to be pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - * - * \returns true if the transition was indeed added - */ - bool addTransition ( StateType from, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); - - /** - * \brief Adds transitions to the automaton. - * - * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T \cup { \eps }, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* - * - * \param from the source state (A) - * \param input the input symbol or epsilon (a) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - */ - void addTransitions ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); - - /** - * \brief Adds transitions to the automaton. - * - * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* - * - * \param from the source state (A) - * \param input the input symbol (a) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - */ - void addTransitions ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); - - /** - * \brief Adds transitions to the automaton. - * - * \details The transitions are in a form A \times \eps \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* - * - * \param from the source state (A) - * \param pop symbols to be poped from pushdown store on the transition use (\alpha) - * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) - * - * \throws AutomatonException when transition contains state or symbol not present in the automaton components - */ - void addTransitions ( StateType from, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); - - /** - * \brief Removes a transition from the automaton. - * - * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D* - * - * \param from the source state (A) - * \param input the input symbol or epsilon (a) - * \param pop symbols poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. - * - * \returns true if the transition was indeed removed - */ - bool removeTransition ( const StateType & from, const ext::variant < EpsilonType, InputSymbolType > & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); - - /** - * \brief Removes a transition from the automaton. - * - * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* - * - * \param from the source state (A) - * \param input the input symbol (a) - * \param pop symbols poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. - * - * \returns true if the transition was indeed removed - */ - bool removeTransition ( const StateType & from, const InputSymbolType & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); - - /** - * \brief Removes a transition from the automaton. - * - * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* - * - * \param from the source state (A) - * \param pop symbols poped from pushdown store on the transition use (\alpha) - * \param to the target state (B) - * \param push symbols pushed to the pushdown store on the transition use (\beta) - * \param output resulting symbols of the transition when used (\gamma) - * - * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. - * - * \returns true if the transition was indeed removed - */ - bool removeTransition ( const StateType & from, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); - - /** - * Get the transition function of the automaton in its natural form. - * - * \returns transition function of the automaton - */ - const ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > & getTransitions ( ) const &; - - /** - * Get the transition function of the automaton in its natural form. - * - * \returns transition function of the automaton - */ - ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && getTransitions ( ) &&; - - /** - * Get a subset of the transition function of the automaton, with the source state fixed in the transitions natural representation. - * - * \param from filter the transition function based on this state as a source state - * - * \returns a subset of the transition function of the automaton with the source state fixed - */ - ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > getTransitionsFromState ( const StateType & from ) const; - - /** - * The actual compare method - * - * \param other the other instance - * - * \returns the actual relation between two by type same automata instances - */ - int compare ( const NPDTA & other ) const; - - /** - * Print this object as raw representation to ostream. - * - * \param out ostream where to print - * \param instance object to print - * - * \returns modified output stream - */ - friend std::ostream & operator << ( std::ostream & out, const NPDTA & instance ) { - return out << "(NPDTA " - << "states = " << instance.getStates ( ) - << "inputAlphabet = " << instance.getInputAlphabet ( ) - << "outputAlphabet = " << instance.getOutputAlphabet ( ) - << "initialState = " << instance.getInitialState ( ) - << "finalStates = " << instance.getFinalStates ( ) - << "pushdownStoreAlphabet = " << instance.getPushdownStoreAlphabet ( ) - << "initialSymbol = " << instance.getInitialSymbol ( ) - << "transitions = " << instance.getTransitions ( ) - << ")"; - } - - /** - * Casts this instance to as compact as possible string representation. - * - * \returns string representation of the object - */ - explicit operator std::string ( ) const; -}; - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::NPDTA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < OutputSymbolType > outputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType initialSymbol, ext::set < StateType > finalStates ) : core::Components < NPDTA, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < OutputSymbolType >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > ( std::move ( inputAlphabet ), std::move ( outputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( initialSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) { -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::NPDTA(StateType initialState, PushdownStoreSymbolType initialPushdownSymbol) : NPDTA ( ext::set < StateType > { initialState }, ext::set < InputSymbolType > { }, ext::set < OutputSymbolType > { }, ext::set < PushdownStoreSymbolType > { initialPushdownSymbol }, initialState, initialPushdownSymbol, ext::set < StateType > { }) { -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { - if (!getStates().count(from)) { - throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist."); - } - - if (input.template is < InputSymbolType >() && !getInputAlphabet().count(input.template get < InputSymbolType >())) { - throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist."); - } - - if (!getStates().count(to)) { - throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist."); - } - - for(const PushdownStoreSymbolType& popSymbol : pop) { - if (!getPushdownStoreAlphabet().count(popSymbol)) { - throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( popSymbol ) + "\" doesn't exist."); - } - } - - for(const PushdownStoreSymbolType& pushSymbol : push) { - if (!getPushdownStoreAlphabet().count(pushSymbol)) { - throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( pushSymbol ) + "\" doesn't exist."); - } - } - - for(const OutputSymbolType& outputSymbol : output) { - if (!getOutputAlphabet().count(outputSymbol)) { - throw AutomatonException("Output symbol \"" + ext::to_string ( outputSymbol ) + "\" doesn't exist."); - } - } - - ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> > key(std::move(from), std::move(input), std::move(pop)); - ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector<OutputSymbolType> > value(std::move(to), std::move(push), std::move(output)); - - return transitions[std::move(key)].insert(std::move(value)).second; -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, InputSymbolType input, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { - ext::variant < EpsilonType, InputSymbolType > inputVariant(std::move(input)); - return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output)); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { - auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); - return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output)); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { - if ( ! getStates ( ).count ( from ) ) - throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); - - if ( input.template is < InputSymbolType > ( ) && ! getInputAlphabet ( ).count ( input.template get < InputSymbolType > ( ) ) ) - throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); - - for ( const PushdownStoreSymbolType & popSymbol : pop) - if (!getPushdownStoreAlphabet ( ).count ( popSymbol ) ) - throw AutomatonException ( "Pushdown store symbol \"" + ext::to_string ( popSymbol ) + "\" doesn't exist." ); - - for ( const ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > & target : targets ) { - if ( ! getStates ( ).count ( std::get < 0 > ( target ) ) ) - throw AutomatonException ( "State \"" + ext::to_string ( std::get < 0 > ( target ) ) + "\" doesn't exist." ); - - for ( const PushdownStoreSymbolType& pushSymbol : std::get < 1 > ( target ) ) - if ( ! getPushdownStoreAlphabet ( ).count ( pushSymbol ) ) - throw AutomatonException ( "Pushdown store symbol \"" + ext::to_string ( pushSymbol ) + "\" doesn't exist." ); - - for ( const OutputSymbolType& outputSymbol : std::get < 2 > ( target ) ) - if ( ! getOutputAlphabet ( ).count ( outputSymbol ) ) - throw AutomatonException ( "Output symbol \"" + ext::to_string ( outputSymbol ) + "\" doesn't exist." ); - } - - ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > > key ( std::move ( from ), std::move ( input ), std::move ( pop ) ); - - transitions [ std::move ( key ) ].insert ( ext::make_mover ( targets ).begin ( ), ext::make_mover ( targets ).end ( ) ); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, InputSymbolType input, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { - ext::variant < EpsilonType, InputSymbolType > inputVariant ( std::move ( input ) ); - addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( pop ), std::move ( targets ) ); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { - auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); - addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( pop ), std::move ( targets ) ); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const ext::variant < EpsilonType, InputSymbolType >& input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { - ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> > key(from, input, pop); - ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > value(to, push, output); - - return transitions[key].erase(value); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const InputSymbolType& input, const ext::vector<PushdownStoreSymbolType>& pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { - ext::variant < EpsilonType, InputSymbolType > inputVariant(input); - return removeTransition(from, inputVariant, pop, to, push, output); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const ext::vector<PushdownStoreSymbolType>& pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { - auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); - return removeTransition(from, inputVariant, pop, to, push, output); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -const ext::map<ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > > & NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitions() const & { - return transitions; -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -ext::map<ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > > && NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitions() && { - return std::move ( transitions ); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { - if( !getStates().count(from)) - throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist"); - - ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > transitionsFromState; - for ( auto transition: transitions ) { - for ( auto iter: transition.second ) { - if ( std::get<0>(transition.first) == from ) { - transitionsFromState.insert ( transition.first, iter ); - } - } - } - - return transitionsFromState; -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -int NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::compare(const NPDTA& other) const { - auto first = ext::tie(getStates(), getInputAlphabet(), getOutputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getInitialSymbol(), transitions); - auto second = ext::tie(other.getStates(), other.getInputAlphabet(), other.getOutputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.transitions); - - static ext::compare<decltype(first)> comp; - return comp(first, second); -} - -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::operator std::string ( ) const { - std::stringstream ss; - ss << *this; - return ss.str(); -} - -} /* namespace automaton */ - -namespace core { - -/** - * Helper class specifying constraints for the automaton's internal input alphabet component. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > { -public: - /** - * Returns true if the symbol is still used in some transition of the automaton. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true if the symbol is used, false othervise - */ - static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { - for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).template is < InputSymbolType >() && symbol == std::get<1>(transition.first).template get < InputSymbolType >()) - return true; - - return false; - } - - /** - * Returns true as all symbols are possibly available to be elements of the input alphabet. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { - return true; - } - - /** - * All symbols are valid as input symbols. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, OutputSymbolType, automaton::OutputAlphabet > { -public: - /** - * Returns true if the symbol is still used in some transition of the automaton. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true if the symbol is used, false othervise - */ - static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const OutputSymbolType & symbol ) { - for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) - for(const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) - if (std::find(std::get<2>(target).begin(), std::get<2>(target).end(), symbol) != std::get<2>(target).end()) - return true; - - return false; - } - - /** - * Returns true as all symbols are possibly available to be elements of the output alphabet. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { - return true; - } - - /** - * All symbols are valid as output symbols. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > { -public: - /** - * Returns true if the symbol is still used in some transition of the automaton. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true if the symbol is used, false othervise - */ - static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { - if(automaton.getInitialSymbol() == symbol) - return true; - - for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) { - for (const PushdownStoreSymbolType& popSymbol : std::get<2>(transition.first)) - if (symbol == popSymbol) - return true; - - for (const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) - if (std::find(std::get<1>(target).begin(), std::get<1>(target).end(), symbol) != std::get<1>(target).end()) - return true; - } - - return false; - } - - /** - * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { - return true; - } - - /** - * All symbols are valid as pushdown store symbols. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal pushdown store initial element. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > { -public: - /** - * Determines whether the initial pushdown store symbol is available in the automaton's pushdown store alphabet. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - * - * \returns true if the pushdown store symbol is already in the pushdown store alphabet of the automaton - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { - return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - /** - * All pushdown store symbols are valid as an initial pusdown store symbol of the automaton. - * - * \param automaton the tested automaton - * \param symbol the tested symbol - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal states component. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > { -public: - /** - * Returns true if the state is still used in some transition of the automaton. - * - * \param automaton the tested automaton - * \param state the tested state - * - * \returns true if the state is used, false othervise - */ - static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) { - if (state == std::get<0>(transition.first)) - return true; - - for(const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) - if(std::get<0>(target) == state) - return true; - } - - return false; - } - - /** - * Returns true as all states are possibly available to be elements of the states. - * - * \param automaton the tested automaton - * \param state the tested state - * - * \returns true - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { - return true; - } - - /** - * All states are valid as a state of the automaton. - * - * \param automaton the tested automaton - * \param state the tested state - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal final states component. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { -public: - /** - * Returns false. Final state is only a mark that the automaton itself does require further. - * - * \param automaton the tested automaton - * \param state the tested state - * - * \returns false - */ - static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { - return false; - } - - /** - * Determines whether the state is available in the automaton's states set. - * - * \param automaton the tested automaton - * \param state the tested state - * - * \returns true if the state is already in the set of states of the automaton - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - /** - * All states are valid as a final state of the automaton. - * - * \param automaton the tested automaton - * \param state the tested state - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { - } -}; - -/** - * Helper class specifying constraints for the automaton's internal initial state element. - * - * \tparam InputSymbolType used for the terminal alphabet of the automaton. - * \tparam OutputSymbolType used for the output alphabet of the automaton. - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. - * \tparam StateType used for the terminal alphabet of the automaton. - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > { -public: - /** - * Determines whether the state is available in the automaton's states set. - * - * \param automaton the tested automaton - * \param state the tested state - * - * \returns true if the state is already in the set of states of the automaton - */ - static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { - return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - /** - * All states are valid as an initial state of the automaton. - * - * \param automaton the tested automaton - * \param state the tested state - */ - static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { - } -}; - -/** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. - * - * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones - */ -template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > -struct normalize < automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > > { - static automaton::NPDTA < > eval ( automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); - ext::set < DefaultSymbolType > outputAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getOutputAlphabet ( ) ); - ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); - DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); - ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); - DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); - ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); - - automaton::NPDTA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( outputAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); - - for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && transition : ext::make_mover ( std::move ( value ).getTransitions ( ) ) ) { - ext::set < ext::tuple < DefaultStateType, ext::vector < DefaultSymbolType >, ext::vector < DefaultSymbolType > > > targets; - for ( ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > && target : ext::make_mover ( transition.second ) ) - targets.insert ( ext::make_tuple ( automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 1 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( target ) ) ) ) ); - - ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); - DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); - ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); - - res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); - } - - return res; - } -}; - - -} /* namespace core */ - -#endif /* NPDTA_H_ */ +/* + * NPDTA.h + * + * This file is part of Algorithms library toolkit. + * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz) + + * Algorithms library toolkit is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * Algorithms library toolkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>. + * + * Created on: 10. 5. 2016 + * Author: Jakub Doupal + */ + +#ifndef NPDTA_H_ +#define NPDTA_H_ + +#include <sstream> + +#include <alib/set> +#include <alib/map> +#include <alib/vector> +#include <alib/variant> +#include <alib/algorithm> + +#include <core/components.hpp> + +#include <common/DefaultStateType.h> +#include <common/DefaultEpsilonType.h> +#include <common/DefaultSymbolType.h> + +#include <automaton/AutomatonException.h> + +#include <core/normalize.hpp> +#include <alphabet/common/SymbolNormalize.h> +#include <automaton/common/AutomatonNormalize.h> + +namespace automaton { + +class InputAlphabet; +class OutputAlphabet; +class PushdownStoreAlphabet; +class InitialSymbol; +class States; +class FinalStates; +class InitialState; + +/** + * Nondeterministic Pushdown Translation Automaton. Translates context free languages. + * + * \details + * Definition + * A = (Q, T, D, G, I, Z, \delta, F), + * Q (States) = nonempty finite set of states, + * T (TerminalAlphabet) = finite set of terminal symbols - having this empty won't let automaton do much though, + * T (OutputAlphabet) = finite set of output symbols - having this empty won't let automaton do translation at all, + * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA + * I (InitialState) = initial state, + * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol + * \delta = transition function of the form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D*, + * F (FinalStates) = set of final states + * + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam OutputSymbolTypeT used for the output alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. + */ +template < class InputSymbolTypeT = DefaultSymbolType, class OutputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class NPDTA final : public ext::CompareOperators < NPDTA < InputSymbolTypeT, OutputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < NPDTA < InputSymbolTypeT, OutputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < OutputSymbolTypeT >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef OutputSymbolTypeT OutputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: + /** + * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols times string of output symbols. + */ + ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > transitions; + +public: + /** + * \brief Creates a new instance of the automaton with a concrete set of states, input alphabet, pushdown store alphabet, initial state, initial pushdown symbol and a set of final states. + * + * \param states the initial set of states of the automaton + * \param inputAlphabet the initial input alphabet + * \param outputAlphabet the initial output alphabet + * \param pushdownStoreAlphabet the initial set of symbols used in the pushdown store by the automaton + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + * \param finalStates the initial set of final states of the automaton + */ + explicit NPDTA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < OutputSymbolType > outputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); + + /** + * \brief Creates a new instance of the automaton with a concrete initial state and initial pushdown store symbol. + * + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + */ + explicit NPDTA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); + + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ + const StateType & getInitialState ( ) const & { + return this-> template accessComponent < InitialState > ( ).get ( ); + } + + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ + StateType && getInitialState ( ) && { + return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) ); + } + + /** + * Setter of the initial state. + * + * \param state new initial state of the automaton + * + * \returns true if the initial state was indeed changed + */ + bool setInitialState ( StateType state ) { + return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) ); + } + + /** + * Getter of states. + * + * \returns the states of the automaton + */ + const ext::set < StateType > & getStates ( ) const & { + return this-> template accessComponent < States > ( ).get ( ); + } + + /** + * Getter of states. + * + * \returns the states of the automaton + */ + ext::set < StateType > && getStates ( ) && { + return std::move ( this-> template accessComponent < States > ( ).get ( ) ); + } + + /** + * Adder of a state. + * + * \param state the new state to be added to a set of states + * + * \returns true if the state was indeed added + */ + bool addState ( StateType state ) { + return this-> template accessComponent < States > ( ).add ( std::move ( state ) ); + } + + /** + * Setter of states. + * + * \param states completely new set of states + */ + void setStates ( ext::set < StateType > states ) { + this-> template accessComponent < States > ( ).set ( std::move ( states ) ); + } + + /** + * Remover of a state. + * + * \param state a state to be removed from a set of states + * + * \returns true if the state was indeed removed + */ + void removeState ( const StateType & state ) { + this-> template accessComponent < States > ( ).remove ( state ); + } + + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ + const ext::set < StateType > & getFinalStates ( ) const & { + return this-> template accessComponent < FinalStates > ( ).get ( ); + } + + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ + ext::set < StateType > && getFinalStates ( ) && { + return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) ); + } + + /** + * Adder of a final state. + * + * \param state the new state to be added to a set of final states + * + * \returns true if the state was indeed added + */ + bool addFinalState ( StateType state ) { + return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); + } + + /** + * Setter of final states. + * + * \param states completely new set of final states + */ + void setFinalStates ( ext::set < StateType > states ) { + this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); + } + + /** + * Remover of a final state. + * + * \param state a state to be removed from a set of final states + * + * \returns true if the state was indeed removed + */ + void removeFinalState ( const StateType & state ) { + this-> template accessComponent < FinalStates > ( ).remove ( state ); + } + + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ + const ext::set < PushdownStoreSymbolType > & getPushdownStoreAlphabet ( ) const & { + return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ); + } + + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ + ext::set < PushdownStoreSymbolType > && getPushdownStoreAlphabet ( ) && { + return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ); + } + + /** + * Adder of a pushdown store symbol. + * + * \param symbol the new symbol to be added to a pushdown store alphabet + * + * \returns true if the symbol was indeed added + */ + bool addPushdownStoreSymbol ( PushdownStoreSymbolType symbol ) { + return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); + } + + /** + * Adder of pushdown store symbols. + * + * \param symbols new symbols to be added to a pushdown store alphabet + */ + void addPushdownStoreSymbols ( ext::set < PushdownStoreSymbolType > symbols ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); + } + + /** + * Setter of a pushdown store alphabet. + * + * \param symbols completely new pushdown store alphabet + */ + void setPushdownStoreAlphabet ( ext::set < PushdownStoreSymbolType > symbols ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); + } + + /** + * Remover of an pushdown store symbol. + * + * \param symbol a symbol to be removed from a pushdown store alphabet + * + * \returns true if the symbol was indeed removed + */ + void removePushdownStoreSymbol ( const PushdownStoreSymbolType & symbol ) { + this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); + } + + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ + const PushdownStoreSymbolType & getInitialSymbol ( ) const & { + return this->template accessComponent < InitialSymbol > ( ).get ( ); + } + + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ + PushdownStoreSymbolType && getInitialSymbol ( ) && { + return std::move ( this->template accessComponent < InitialSymbol > ( ).get ( ) ); + } + + /** + * Setter of the initial pushdown store symbol. + * + * \param symbol new initial pushdown store symbol of the automaton + * + * \returns true if the initial pushdown store symbol was indeed changed + */ + bool setInitialSymbol ( PushdownStoreSymbolType symbol ) { + return this->template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) ); + } + + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ + const ext::set < InputSymbolType > & getInputAlphabet ( ) const & { + return this-> template accessComponent < InputAlphabet > ( ).get ( ); + } + + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ + ext::set < InputSymbolType > && getInputAlphabet ( ) && { + return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) ); + } + + /** + * Adder of a input symbol. + * + * \param symbol the new symbol to be added to an input alphabet + * + * \returns true if the symbol was indeed added + */ + bool addInputSymbol ( InputSymbolType symbol ) { + return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); + } + + /** + * Adder to an input symbols. + * + * \param symbols new symbols to be added to an input alphabet + */ + void addInputSymbols ( ext::set < InputSymbolType > symbols ) { + this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); + } + + /** + * Setter of input alphabet. + * + * \param symbols completely new input alphabet + */ + void setInputAlphabet ( ext::set < InputSymbolType > symbols ) { + this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); + } + + /** + * Remover of an input symbol. + * + * \param symbol a symbol to be removed from an input alphabet + * + * \returns true if the symbol was indeed removed + */ + void removeInputSymbol ( const InputSymbolType & symbol ) { + this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); + } + + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ + const ext::set < OutputSymbolType > & getOutputAlphabet ( ) const & { + return this->template accessComponent < OutputAlphabet > ( ).get ( ); + } + + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ + ext::set < OutputSymbolType > && getOutputAlphabet ( ) && { + return std::move ( this->template accessComponent < OutputAlphabet > ( ).get ( ) ); + } + + /** + * Adder to an output symbol. + * + * \param symbol the new symbol to be added to an output alphabet + * + * \returns true if the symbol was indeed added + */ + bool addOutputSymbol ( OutputSymbolType symbol ) { + return this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbol ) ); + } + + /** + * Adder to an output symbols. + * + * \param symbols new symbols to be added to an output alphabet + */ + void addOutputSymbols ( ext::set < OutputSymbolType > symbols ) { + this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbols ) ); + } + + /** + * Setter of an output alphabet. + * + * \param symbols completely new output alphabet + */ + void setOutputAlphabet ( ext::set < OutputSymbolType > symbols ) { + this->template accessComponent < OutputAlphabet > ( ).set ( std::move ( symbols ) ); + } + + /** + * Remover of an output symbol. + * + * \param symbol a symbol to be removed from an output alphabet + * + * \returns true if the symbol was indeed removed + */ + void removeOutputSymbol ( const OutputSymbolType & symbol ) { + this->template accessComponent < OutputAlphabet > ( ).remove ( symbol ); + } + + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added + */ + bool addTransition ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); + + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added + */ + bool addTransition ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); + + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added + */ + bool addTransition ( StateType from, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); + + /** + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T \cup { \eps }, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + */ + void addTransitions ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); + + /** + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + */ + void addTransitions ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); + + /** + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times \eps \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + */ + void addTransitions ( StateType from, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); + + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ + bool removeTransition ( const StateType & from, const ext::variant < EpsilonType, InputSymbolType > & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); + + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ + bool removeTransition ( const StateType & from, const InputSymbolType & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); + + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ + bool removeTransition ( const StateType & from, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); + + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ + const ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > & getTransitions ( ) const &; + + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ + ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && getTransitions ( ) &&; + + /** + * Get a subset of the transition function of the automaton, with the source state fixed in the transitions natural representation. + * + * \param from filter the transition function based on this state as a source state + * + * \returns a subset of the transition function of the automaton with the source state fixed + */ + ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > getTransitionsFromState ( const StateType & from ) const; + + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same automata instances + */ + int compare ( const NPDTA & other ) const; + + /** + * Print this object as raw representation to ostream. + * + * \param out ostream where to print + * \param instance object to print + * + * \returns modified output stream + */ + friend std::ostream & operator << ( std::ostream & out, const NPDTA & instance ) { + return out << "(NPDTA " + << "states = " << instance.getStates ( ) + << "inputAlphabet = " << instance.getInputAlphabet ( ) + << "outputAlphabet = " << instance.getOutputAlphabet ( ) + << "initialState = " << instance.getInitialState ( ) + << "finalStates = " << instance.getFinalStates ( ) + << "pushdownStoreAlphabet = " << instance.getPushdownStoreAlphabet ( ) + << "initialSymbol = " << instance.getInitialSymbol ( ) + << "transitions = " << instance.getTransitions ( ) + << ")"; + } + + /** + * Casts this instance to as compact as possible string representation. + * + * \returns string representation of the object + */ + explicit operator std::string ( ) const; +}; + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::NPDTA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < OutputSymbolType > outputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType initialSymbol, ext::set < StateType > finalStates ) : core::Components < NPDTA, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < OutputSymbolType >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > ( std::move ( inputAlphabet ), std::move ( outputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( initialSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) { +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::NPDTA(StateType initialState, PushdownStoreSymbolType initialPushdownSymbol) : NPDTA ( ext::set < StateType > { initialState }, ext::set < InputSymbolType > { }, ext::set < OutputSymbolType > { }, ext::set < PushdownStoreSymbolType > { initialPushdownSymbol }, initialState, initialPushdownSymbol, ext::set < StateType > { }) { +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { + if (!getStates().count(from)) { + throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist."); + } + + if (input.template is < InputSymbolType >() && !getInputAlphabet().count(input.template get < InputSymbolType >())) { + throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist."); + } + + if (!getStates().count(to)) { + throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist."); + } + + for(const PushdownStoreSymbolType& popSymbol : pop) { + if (!getPushdownStoreAlphabet().count(popSymbol)) { + throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( popSymbol ) + "\" doesn't exist."); + } + } + + for(const PushdownStoreSymbolType& pushSymbol : push) { + if (!getPushdownStoreAlphabet().count(pushSymbol)) { + throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( pushSymbol ) + "\" doesn't exist."); + } + } + + for(const OutputSymbolType& outputSymbol : output) { + if (!getOutputAlphabet().count(outputSymbol)) { + throw AutomatonException("Output symbol \"" + ext::to_string ( outputSymbol ) + "\" doesn't exist."); + } + } + + ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> > key(std::move(from), std::move(input), std::move(pop)); + ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector<OutputSymbolType> > value(std::move(to), std::move(push), std::move(output)); + + return transitions[std::move(key)].insert(std::move(value)).second; +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, InputSymbolType input, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { + ext::variant < EpsilonType, InputSymbolType > inputVariant(std::move(input)); + return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output)); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransition(StateType from, ext::vector<PushdownStoreSymbolType> pop, StateType to, ext::vector<PushdownStoreSymbolType> push, ext::vector < OutputSymbolType > output) { + auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); + return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output)); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { + if ( ! getStates ( ).count ( from ) ) + throw AutomatonException ( "State \"" + ext::to_string ( from ) + "\" doesn't exist." ); + + if ( input.template is < InputSymbolType > ( ) && ! getInputAlphabet ( ).count ( input.template get < InputSymbolType > ( ) ) ) + throw AutomatonException ( "Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist." ); + + for ( const PushdownStoreSymbolType & popSymbol : pop) + if (!getPushdownStoreAlphabet ( ).count ( popSymbol ) ) + throw AutomatonException ( "Pushdown store symbol \"" + ext::to_string ( popSymbol ) + "\" doesn't exist." ); + + for ( const ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > & target : targets ) { + if ( ! getStates ( ).count ( std::get < 0 > ( target ) ) ) + throw AutomatonException ( "State \"" + ext::to_string ( std::get < 0 > ( target ) ) + "\" doesn't exist." ); + + for ( const PushdownStoreSymbolType& pushSymbol : std::get < 1 > ( target ) ) + if ( ! getPushdownStoreAlphabet ( ).count ( pushSymbol ) ) + throw AutomatonException ( "Pushdown store symbol \"" + ext::to_string ( pushSymbol ) + "\" doesn't exist." ); + + for ( const OutputSymbolType& outputSymbol : std::get < 2 > ( target ) ) + if ( ! getOutputAlphabet ( ).count ( outputSymbol ) ) + throw AutomatonException ( "Output symbol \"" + ext::to_string ( outputSymbol ) + "\" doesn't exist." ); + } + + ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > > key ( std::move ( from ), std::move ( input ), std::move ( pop ) ); + + transitions [ std::move ( key ) ].insert ( ext::make_mover ( targets ).begin ( ), ext::make_mover ( targets ).end ( ) ); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, InputSymbolType input, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { + ext::variant < EpsilonType, InputSymbolType > inputVariant ( std::move ( input ) ); + addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( pop ), std::move ( targets ) ); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +void NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::addTransitions ( StateType from, ext::vector<PushdownStoreSymbolType> pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ) { + auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); + addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( pop ), std::move ( targets ) ); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const ext::variant < EpsilonType, InputSymbolType >& input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { + ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> > key(from, input, pop); + ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > value(to, push, output); + + return transitions[key].erase(value); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const InputSymbolType& input, const ext::vector<PushdownStoreSymbolType>& pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { + ext::variant < EpsilonType, InputSymbolType > inputVariant(input); + return removeTransition(from, inputVariant, pop, to, push, output); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +bool NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::removeTransition(const StateType& from, const ext::vector<PushdownStoreSymbolType>& pop, const StateType& to, const ext::vector<PushdownStoreSymbolType>& push, const ext::vector < OutputSymbolType > & output) { + auto inputVariant = ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ); + return removeTransition(from, inputVariant, pop, to, push, output); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +const ext::map<ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > > & NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitions() const & { + return transitions; +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +ext::map<ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > > && NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitions() && { + return std::move ( transitions ); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::getTransitionsFromState ( const StateType & from ) const { + if( !getStates().count(from)) + throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist"); + + ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > transitionsFromState; + for ( auto transition: transitions ) { + for ( auto iter: transition.second ) { + if ( std::get<0>(transition.first) == from ) { + transitionsFromState.insert ( transition.first, iter ); + } + } + } + + return transitionsFromState; +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +int NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::compare(const NPDTA& other) const { + auto first = ext::tie(getStates(), getInputAlphabet(), getOutputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getInitialSymbol(), transitions); + auto second = ext::tie(other.getStates(), other.getInputAlphabet(), other.getOutputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.transitions); + + static ext::compare<decltype(first)> comp; + return comp(first, second); +} + +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >::operator std::string ( ) const { + std::stringstream ss; + ss << *this; + return ss.str(); +} + +} /* namespace automaton */ + +namespace core { + +/** + * Helper class specifying constraints for the automaton's internal input alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > { +public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ + static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { + for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).template is < InputSymbolType >() && symbol == std::get<1>(transition.first).template get < InputSymbolType >()) + return true; + + return false; + } + + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { + return true; + } + + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, OutputSymbolType, automaton::OutputAlphabet > { +public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ + static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const OutputSymbolType & symbol ) { + for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) + for(const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) + if (std::find(std::get<2>(target).begin(), std::get<2>(target).end(), symbol) != std::get<2>(target).end()) + return true; + + return false; + } + + /** + * Returns true as all symbols are possibly available to be elements of the output alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { + return true; + } + + /** + * All symbols are valid as output symbols. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > { +public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ + static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { + if(automaton.getInitialSymbol() == symbol) + return true; + + for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) { + for (const PushdownStoreSymbolType& popSymbol : std::get<2>(transition.first)) + if (symbol == popSymbol) + return true; + + for (const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) + if (std::find(std::get<1>(target).begin(), std::get<1>(target).end(), symbol) != std::get<1>(target).end()) + return true; + } + + return false; + } + + /** + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { + return true; + } + + /** + * All symbols are valid as pushdown store symbols. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal pushdown store initial element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > { +public: + /** + * Determines whether the initial pushdown store symbol is available in the automaton's pushdown store alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the pushdown store symbol is already in the pushdown store alphabet of the automaton + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { + return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + /** + * All pushdown store symbols are valid as an initial pusdown store symbol of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > { +public: + /** + * Returns true if the state is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is used, false othervise + */ + static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) { + if (state == std::get<0>(transition.first)) + return true; + + for(const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) + if(std::get<0>(target) == state) + return true; + } + + return false; + } + + /** + * Returns true as all states are possibly available to be elements of the states. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { + return true; + } + + /** + * All states are valid as a state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal final states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { +public: + /** + * Returns false. Final state is only a mark that the automaton itself does require further. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns false + */ + static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { + return false; + } + + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + /** + * All states are valid as a final state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { + } +}; + +/** + * Helper class specifying constraints for the automaton's internal initial state element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > { +public: + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ + static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { + return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + /** + * All states are valid as an initial state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ + static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { + } +}; + +/** + * Helper for normalisation of types specified by templates used as internal datatypes of symbols and states. + * + * \returns new instance of the automaton with default template parameters or unmodified instance if the template parameters were already the default ones + */ +template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > +struct normalize < automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > > { + static automaton::NPDTA < > eval ( automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > && value ) { + ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) ); + ext::set < DefaultSymbolType > outputAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getOutputAlphabet ( ) ); + ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) ); + DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getInitialSymbol ( ) ); + ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) ); + DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) ); + ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) ); + + automaton::NPDTA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( outputAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) ); + + for ( std::pair < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && transition : ext::make_mover ( std::move ( value ).getTransitions ( ) ) ) { + ext::set < ext::tuple < DefaultStateType, ext::vector < DefaultSymbolType >, ext::vector < DefaultSymbolType > > > targets; + for ( ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > && target : ext::make_mover ( transition.second ) ) + targets.insert ( ext::make_tuple ( automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 1 > ( target ) ) ), alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( target ) ) ) ) ); + + ext::vector < DefaultSymbolType > pop = alphabet::SymbolNormalize::normalizeSymbols ( std::move ( std::get < 2 > ( transition.first ) ) ); + DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) ); + ext::variant < DefaultEpsilonType, DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) ); + + res.addTransitions ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( targets ) ); + } + + return res; + } +}; + + +} /* namespace core */ + +#endif /* NPDTA_H_ */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h index a6c1e62cb9..a6698e931e 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h @@ -84,14 +84,20 @@ class InitialState; * if $|\delta_{return} (q, a, g)|$ == 1 then $|\delta_{call} (q, a)|$ == 0, $|\delta_{call} (q, \eps)|$ == 0, $|\delta_{return} (q, \eps, g)|$ == 0, $|\delta_{local} (q, a)|$ == 0, $|\delta_{local} (q, \eps)|$ == 0, \forall q \in Q, a \in T, and g \in G * if $|\delta_{local} (q, a)|$ == 1 then $|\delta_{call} (q, a)|$ == 0, $|\delta_{call} (q, \eps)|$ == 0, $|\delta_{return} (q, a, g)|$ == 0, $|\delta_{return} (q, \eps, g)|$ == 0, $|\delta_{local} (q, \eps)|$ == 0, \forall q \in Q, a \in T, and g \in G * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class RealTimeHeightDeterministicDPDA final : public ext::CompareOperators < RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < RealTimeHeightDeterministicDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class RealTimeHeightDeterministicDPDA final : public ext::CompareOperators < RealTimeHeightDeterministicDPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < RealTimeHeightDeterministicDPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Call transition function as mapping from a state times an input symbol or epsilon on the left hand side to a state times pushdown store symbol on the right hand side. */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h index 090e4f0296..d114138ece 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h @@ -72,14 +72,20 @@ class InitialStates; * - \delta_{local} of the form A \times a -> B, where A, B \in Q, a \in T \cup { \eps } * F (FinalStates) = set of final states * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class RealTimeHeightDeterministicNPDA final : public ext::CompareOperators < RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < RealTimeHeightDeterministicNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol, ext::set < StateType >, component::Set, std::tuple < States, InitialStates, FinalStates > > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class RealTimeHeightDeterministicNPDA final : public ext::CompareOperators < RealTimeHeightDeterministicNPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < RealTimeHeightDeterministicNPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Call transition function as mapping from a state times an input symbol or epsilon on the left hand side to a state times pushdown store symbol on the right hand side. */ diff --git a/alib2data/src/automaton/PDA/SinglePopDPDA.h b/alib2data/src/automaton/PDA/SinglePopDPDA.h index 72174d34b7..91933494ca 100644 --- a/alib2data/src/automaton/PDA/SinglePopDPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopDPDA.h @@ -73,14 +73,20 @@ class InitialState; * $|\delta (q, a, g)| \leq 1$, $\forall q, a, \gamma, q \in Q, a \in (T \cup \{\varepsilon\}), g \in G.$ * if $\delta(q, a, g) \neq \emptyset$, $\delta (q, \varepsilon, h) \neq \emptyset$, then $g \neq h$). * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class SinglePopDPDA final : public ext::CompareOperators < SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class SinglePopDPDA final : public ext::CompareOperators < SinglePopDPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < SinglePopDPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon times pushdown store symbol on the left hand side to a state times string of pushdown store symbols. */ diff --git a/alib2data/src/automaton/PDA/SinglePopNPDA.h b/alib2data/src/automaton/PDA/SinglePopNPDA.h index 470da84813..d4de8200d4 100644 --- a/alib2data/src/automaton/PDA/SinglePopNPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopNPDA.h @@ -68,14 +68,20 @@ class InitialState; * \delta = transition function of the form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, g \in G, and \beta \in G*, * F (FinalStates) = set of final states * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class EpsilonType = DefaultEpsilonType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class SinglePopNPDA final : public ext::CompareOperators < SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > >, public core::Components < SinglePopNPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class EpsilonTypeT = DefaultEpsilonType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class SinglePopNPDA final : public ext::CompareOperators < SinglePopNPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < SinglePopNPDA < InputSymbolTypeT, EpsilonTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef EpsilonTypeT EpsilonType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state times an input symbol or epsilon times pushdown store symbol on the left hand side to a state times string of pushdown store symbols. */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h index 179a2ecdc2..b65266de80 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h @@ -81,13 +81,18 @@ class InitialState; * $|\delta_{return} (q, r, g)| \leq 1$, $\forall q \in Q, r \in L, g \in G$ * $|\delta_{local} (q, l)| \leq 1$, $\forall q \in Q, l \in R$ * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class VisiblyPushdownDPDA final : public ext::CompareOperators < VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > >, public core::Components < VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class VisiblyPushdownDPDA final : public ext::CompareOperators < VisiblyPushdownDPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < VisiblyPushdownDPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Call transition function as mapping from a state times an input symbol on the left hand side to a state times pushdown store symbol on the right hand side. */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h index 220504b2ea..442401f6be 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h @@ -76,14 +76,19 @@ class InitialStates; * - \delta_{local} of the form A \times l -> B, where A, B \in Q, a \in C * F (FinalStates) = set of final states * - * \tparam InputSymbolType used for the terminal alphabet - * \tparam EpsilonSymbolType used for the epsilon in the automaton - * \tparam PushdownSymbolType used for the pushdown store alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam InputSymbolTypeT used for the terminal alphabet + * \tparam EpsilonSymbolTypeT used for the epsilon in the automaton + * \tparam PushdownSymbolTypeT used for the pushdown store alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class InputSymbolType = DefaultSymbolType, class PushdownStoreSymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class VisiblyPushdownNPDA final : public ext::CompareOperators < VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > >, public core::Components < VisiblyPushdownNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol, ext::set < StateType >, component::Set, std::tuple < States, InitialStates, FinalStates > > { -protected: +template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class VisiblyPushdownNPDA final : public ext::CompareOperators < VisiblyPushdownNPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT > >, public core::Components < VisiblyPushdownNPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, InitialStates, FinalStates > > { +public: + typedef InputSymbolTypeT InputSymbolType; + typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType; + typedef StateTypeT StateType; + +private: /** * Call transition function as mapping from a state times an input symbol on the left hand side to a state times pushdown store symbol on the right hand side. */ diff --git a/alib2data/src/automaton/TA/DFTA.h b/alib2data/src/automaton/TA/DFTA.h index 8ee42d8e39..7fdbb9fe94 100644 --- a/alib2data/src/automaton/TA/DFTA.h +++ b/alib2data/src/automaton/TA/DFTA.h @@ -70,12 +70,18 @@ class FinalStates; * * Elements of the \delta mapping must meet following criteria. The size of the state list must equal the rank of the ranked symbol. * - * \tparam SymbolType used for the symbol part of the ranked symbol - * \tparam RankType used for the rank part of the ranked symbol - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the symbol part of the ranked symbol + * \tparam RankTypeT used for the rank part of the ranked symbol + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class RankType = DefaultRankType, class StateType = DefaultStateType > -class DFTA final : public ext::CompareOperators < DFTA < SymbolType, RankType, StateType > >, public core::Components < DFTA < SymbolType, RankType, StateType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates > > { +template < class SymbolTypeT = DefaultSymbolType, class RankTypeT = DefaultRankType, class StateTypeT = DefaultStateType > +class DFTA final : public ext::CompareOperators < DFTA < SymbolTypeT, RankTypeT, StateTypeT > >, public core::Components < DFTA < SymbolTypeT, RankTypeT, StateTypeT >, ext::set < common::ranked_symbol < SymbolTypeT, RankTypeT > >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates > > { +public: + typedef SymbolTypeT SymbolType; + typedef RankTypeT RankType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a list of states times an input symbol on the left hand side to a state. */ diff --git a/alib2data/src/automaton/TA/NFTA.h b/alib2data/src/automaton/TA/NFTA.h index 8803547885..598d622d93 100644 --- a/alib2data/src/automaton/TA/NFTA.h +++ b/alib2data/src/automaton/TA/NFTA.h @@ -68,12 +68,18 @@ class FinalStates; * * Elements of the \delta mapping must meet following criteria. The size of the state list must equal the rank of the ranked symbol. * - * \tparam SymbolType used for the symbol part of the ranked symbol - * \tparam RankType used for the rank part of the ranked symbol - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the symbol part of the ranked symbol + * \tparam RankTypeT used for the rank part of the ranked symbol + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class RankType = DefaultRankType, class StateType = DefaultStateType > -class NFTA final : public ext::CompareOperators < NFTA < SymbolType, RankType, StateType > >, public core::Components < NFTA < SymbolType, RankType, StateType >, ext::set < common::ranked_symbol < SymbolType, RankType > >, component::Set, InputAlphabet, ext::set < StateType >, component::Set, std::tuple < States, FinalStates > > { +template < class SymbolTypeT = DefaultSymbolType, class RankTypeT = DefaultRankType, class StateTypeT = DefaultStateType > +class NFTA final : public ext::CompareOperators < NFTA < SymbolTypeT, RankTypeT, StateTypeT > >, public core::Components < NFTA < SymbolTypeT, RankTypeT, StateTypeT >, ext::set < common::ranked_symbol < SymbolTypeT, RankTypeT > >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates > > { +public: + typedef SymbolTypeT SymbolType; + typedef RankTypeT RankType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a list of states times an input symbol on the left hand side to a set of states. */ diff --git a/alib2data/src/automaton/TM/OneTapeDTM.h b/alib2data/src/automaton/TM/OneTapeDTM.h index bbdc9d583c..a5d46f9e0e 100644 --- a/alib2data/src/automaton/TM/OneTapeDTM.h +++ b/alib2data/src/automaton/TM/OneTapeDTM.h @@ -69,11 +69,16 @@ class InitialState; * B (BlankSymbol) = blank symbol * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet - * \tparam StateType used to the states, and the initial state of the automaton. + * \tparam SymbolTypeT used for the terminal alphabet + * \tparam StateTypeT used to the states, and the initial state of the automaton. */ -template < class SymbolType = DefaultSymbolType, class StateType = DefaultStateType > -class OneTapeDTM final : public ext::CompareOperators < OneTapeDTM < SymbolType, StateType > >, public core::Components < OneTapeDTM < SymbolType, StateType >, ext::set < SymbolType >, component::Set, std::tuple < TapeAlphabet, InputAlphabet >, SymbolType, component::Value, BlankSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { +template < class SymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType > +class OneTapeDTM final : public ext::CompareOperators < OneTapeDTM < SymbolTypeT, StateTypeT > >, public core::Components < OneTapeDTM < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, std::tuple < TapeAlphabet, InputAlphabet >, SymbolTypeT, component::Value, BlankSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > { +public: + typedef SymbolTypeT SymbolType; + typedef StateTypeT StateType; + +private: /** * Transition function as mapping from a state \times a tape symbol on the left hand side to a state \times tape symbol \times shift on tape. */ @@ -509,7 +514,7 @@ bool OneTapeDTM<SymbolType, StateType>::removeTransition(const StateType& from, return false; ext::tuple<StateType, SymbolType, Shift > value(to, output, shift); - if(transitions.find(key)->second != value) + if(transitions.find(key)->second != value) throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> ? doesn't exists."); transitions.erase(key); -- GitLab