diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index b548c7d252ad8e7cebbb1ead20b3d89fb3ba3000..f5117a7c74ee385f69c306eda428fb70e5783bd8 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -1,5 +1,21 @@ /* - * INPUT_DRIVEN_DPDA.h + * InputDrivenDPDA.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: Mar 25, 2013 * Author: Jan Travnicek @@ -39,210 +55,536 @@ class FinalStates; class InitialState; /** - * Represents Finite Automaton. - * Can store nondeterministic finite automaton without epsilon transitions. + * \brief + * Deterministic input driven pushdown automaton. Accepts subset of context free languages. + + * \details + * Definition is similar to the deterministic finite automata extended with pushdown store. + * A = (Q, T, G, I, \delta, \zeta, 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, + * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA + * I (InitialState) = initial state, + * \delta = transition function of the form A \times a -> B, where A, B \in Q and a \in T, + * \zeta = mapping function of the form a -> ( \alpha, \beta ) where a \in T and \alpha, \beta \in G* + * F (FinalStates) = set of final states + * + * 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 PushdownSymbolType used for the pushdown store alphabet + * \tparam StateType used to the states, and the initial state of the automaton. */ template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > class InputDrivenDPDA final : public AutomatonBase, 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: + /** + * Transition function as mapping from a state times an input symbol on the left hand side to a state. + */ ext::map < ext::pair < StateType, InputSymbolType >, StateType > transitions; + + /** + * Pushdown store operation as mapping from a input symbol to the pop and push pushdown store operations. + */ ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > inputSymbolToPushdownStoreOperation; + /* + * Helper function to validate pop and push pushdown store operaion maped to input symbol. + * + * \param input the input symbol + * \param pop the vector of symbols to be poped + * \param push the vector of symbols to be pushed + */ void checkPushdownStoreOperation ( const InputSymbolType & input, const ext::vector < PushdownStoreSymbolType > & pop, const ext::vector < PushdownStoreSymbolType > & push ); public: - explicit InputDrivenDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); + /** + * \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 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 InputDrivenDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, 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 InputDrivenDPDA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); - virtual AutomatonBase * clone ( ) const; + /** + * @copydoc automaton::AutomatonBase::clone() + */ + virtual AutomatonBase * clone ( ) const override; - virtual AutomatonBase * plunder ( ) &&; + /** + * @copydoc automaton::AutomatonBase::plunder() + */ + virtual AutomatonBase * plunder ( ) && override; + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ const StateType & getInitialState ( ) const & { - return this->template accessComponent < InitialState > ( ).get ( ); + 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 ( ) ); + 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 ) ); + 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 ( ); + 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 ( ) ); + 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 ) ); + 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 ) ); + 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 ); + 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 ( ); + 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 ( ) ); + 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 ) ); + 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 ) ); + 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 ); + 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 ( ); + 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 ( ) ); + 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 ) ); + return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder of 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 ) ); + 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 ) ); + 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 ); + this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); } + /** + * Setter of pushdown store operation + * + * Pushdown store operation is a mapping from a input symbol to the pop and push pushdown store operations + * \param input the input symbol + * \param pop the vector of pushdown store symbols to pop from pushdown store + * \param push the vector of pushdown store symbol to push to pushdown store + * + * \returns true if the operation was set + */ bool setPushdownStoreOperation ( InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, ext::vector < PushdownStoreSymbolType > push ); + /** + * Setter of pushdown store operations + * + * Pushdown store operation is a mapping from a input symbol to the pop and push pushdown store operations + * \param operations represented by mapping from input symbol to pair of vectors of pushdown store symbols to pop and pop respectively + */ void setPushdownStoreOperations ( ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > operations ); + /** + * Clearer of pushdown store operation + * + * \param input the input symbol for which to clear the pushdown store operation + * \return true if the pushdown store operaion was cleared + */ bool clearPushdownStoreOperation ( const InputSymbolType & input ); + /** + * Get the pushdown store operations. + * + * \return the pushdown store operaions + */ const ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > & getPushdownStoreOperations ( ) const &; + /** + * Get the pushdown store operations. + * + * \return the pushdown store operaions + */ ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && getPushdownStoreOperations ( ) &&; /** - * Adds transition defined by parameters to the automaton. - * @param current current state - * @param input input symbol - * @param next next state - * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * + * \param current the source state (A) + * \param input the input symbol (a) + * \param next the target state (B) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components, or when the pushdown store operation is not set for the input symbol + * + * \returns true if the transition was indeed added */ bool addTransition ( StateType current, InputSymbolType input, StateType next ); /** - * Removes transition from the automaton. - * @param transition transition to remove - * @throws AutomatonException when transition doesn't exists. + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * + * \param current the source state (A) + * \param input the input symbol (a) + * \param next the target state (B) + * + * \returns true if the transition was indeed removed */ bool removeTransition ( const StateType & current, const InputSymbolType & input, const StateType & next ); /** - * @return automaton transitions + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton */ const ext::map < ext::pair < StateType, InputSymbolType >, StateType > & getTransitions ( ) const &; + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ ext::map < ext::pair < StateType, InputSymbolType >, StateType > && getTransitions ( ) &&; + /** + * Get a subset of the transition function of the automaton, with the source state fixed as a view to the internal 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::pair < StateType, InputSymbolType >, StateType > getTransitionsFromState ( const StateType & from ) const; + /** + * Get the transition function of the automaton, with the target state fixed in the transitions natural representation. + * + * \param to filter the transition function based on this state as a source state + * + * \returns a subset of the transition function of the automaton with the target state fixed + */ ext::map < ext::pair < StateType, InputSymbolType >, StateType > getTransitionsToState ( const StateType & to ) const; /** - * Determines whether InputDrivenDPDA is deterministic. - * FA is deterministic if and only if: - * \li \c contains only 1 initial state. - * \li \c is epsilon free. Trivial for this class - * \li \c size of transition function \delta (from state, input symbol) \leq 1 - * @return true when automaton is deterministic, false otherwise + * @copydoc alib::CommonBase<ObjectBase>::compare ( const ObjectBase & ) */ - bool isDeterministic ( ) const; - - virtual int compare ( const ObjectBase & other ) const { + virtual int compare ( const ObjectBase & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } - virtual int compare ( const InputDrivenDPDA & other ) const; + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same automata instances + */ + int compare ( const InputDrivenDPDA & other ) const; - virtual void operator >>( std::ostream & os ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator >> ( std::ostream & ) + */ + virtual void operator >>( std::ostream & os ) const override; - virtual explicit operator std::string ( ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; + /** + * \brief The XML tag name of class. + * + * \details Intentionaly a static member function to be safe in the initialisation before the main function starts. + * + * \returns string representing the XML tag name of the class + */ static const std::string & getXmlTagName() { static std::string xmlTagName = "InputDrivenDPDA"; return xmlTagName; } + /** + * Parsing from a sequence of xml tokens helper. + * + * \params input the iterator to sequence of xml tokens to parse from + * + * \returns the new instance of the automaton + */ static InputDrivenDPDA parse ( ext::deque < sax::Token >::iterator & input ); + + /** + * Helper for parsing of individual transitions of the automaton from a sequence of xml tokens. + * + * \params input the iterator to sequence of xml tokens to parse from + * \params automaton the automaton to add the rule to + */ static void parseTransition ( ext::deque < sax::Token >::iterator & input, InputDrivenDPDA & automaton ); + /** + * Composing to a sequence of xml tokens helper. + * + * \param out the sink for new xml tokens representing the automaton + * \param automaton the automaton to compose + */ static void compose ( ext::deque < sax::Token > & out, const InputDrivenDPDA & automaton ); + + /** + * Helper for composing transitions of the automaton to a sequence of xml tokens. + * + * \param out the sink for xml tokens representing the rules of the automaton + * \param automaton the automaton to compose + */ static void composeTransitions ( ext::deque < sax::Token > & out, const InputDrivenDPDA & automaton ); - virtual object::ObjectBase * inc ( ) &&; + /** + * @copydoc alib::GrammarBase::inc() + */ + virtual object::ObjectBase * inc ( ) && override; + /** + * Type of normalized automaton. + */ typedef InputDrivenDPDA < > normalized_type; }; @@ -512,9 +854,24 @@ object::ObjectBase* InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, 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 PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { for ( const std::pair<const ext::pair<StateType, InputSymbolType>, StateType>& transition : automaton.getTransitions()) if (transition.first.second == symbol) @@ -523,17 +880,46 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) @@ -548,28 +934,78 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store initial element. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal states component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { if ( automaton.getInitialState ( ) == state ) return true; @@ -584,36 +1020,100 @@ public: 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::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal final states component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { 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::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal initial state element. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, 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::InputDrivenDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.h b/alib2data/src/automaton/PDA/InputDrivenNPDA.h index bcbd1c5e451e37e07c798edbcee9515a2b14496c..63b6a2c8821918540eac8faf0e01f3fa3396b24c 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.h @@ -39,219 +39,561 @@ class FinalStates; class InitialState; /** - * Represents Finite Automaton. - * Can store nondeterministic finite automaton without epsilon transitions. + * \brief + * Nondeterministic input driven pushdown automaton. Accepts subset of context free languages. + + * \details + * Definition is similar to the deterministic finite automata extended with pushdown store. + * A = (Q, T, G, I, \delta, \zeta, 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, + * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to NFA + * I (InitialState) = initial state, + * \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, + * \zeta = mapping function of the form a -> ( \alpha, \beta ) where a \in T and \alpha, \beta \in G* + * F (FinalStates) = set of final states + * + * 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 PushdownSymbolType used for the pushdown store alphabet + * \tparam StateType used to the states, and the initial state of the automaton. */ template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > class InputDrivenNPDA final : public AutomatonBase, 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: + /** + * Transition function as mapping from a state times an input symbol on the left hand side to a set of states. + */ ext::map < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > transitions; + + /** + * Pushdown store operation as mapping from a input symbol to the pop and push pushdown store operations. + */ ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > inputSymbolToPushdownStoreOperation; + /* + * Helper function to validate pop and push pushdown store operaion maped to input symbol. + * + * \param input the input symbol + * \param pop the vector of symbols to be poped + * \param push the vector of symbols to be pushed + */ void checkPushdownStoreOperation ( const InputSymbolType & input, const ext::vector < PushdownStoreSymbolType > & pop, const ext::vector < PushdownStoreSymbolType > & push ); public: - explicit InputDrivenNPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); + /** + * \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 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 InputDrivenNPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAphabet, 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 InputDrivenNPDA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); - virtual AutomatonBase * clone ( ) const; + /** + * @copydoc automaton::AutomatonBase::clone() + */ + virtual AutomatonBase * clone ( ) const override; - virtual AutomatonBase * plunder ( ) &&; + /** + * @copydoc automaton::AutomatonBase::plunder() + */ + virtual AutomatonBase * plunder ( ) && override; + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ const StateType & getInitialState ( ) const & { - return this->template accessComponent < InitialState > ( ).get ( ); + 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 ( ) ); + 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 ) ); + 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 ( ); + 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 ( ) ); + 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 ) ); + 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 ) ); + 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 ); + 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 ( ); + 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 ( ) ); + 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 ) ); + 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 ) ); + 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 ); + 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 ( ); + 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 ( ) ); + 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 ) ); + return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder of 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 ) ); + 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 ) ); + 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 ); + this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); } + /** + * Setter of pushdown store operation + * + * Pushdown store operation is a mapping from a input symbol to the pop and push pushdown store operations + * \param input the input symbol + * \param pop the vector of pushdown store symbols to pop from pushdown store + * \param push the vector of pushdown store symbol to push to pushdown store + * + * \returns true if the operation was set + */ bool setPushdownStoreOperation ( InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, ext::vector < PushdownStoreSymbolType > push ); + /** + * Setter of pushdown store operations + * + * Pushdown store operation is a mapping from a input symbol to the pop and push pushdown store operations + * \param operations represented by mapping from input symbol to pair of vectors of pushdown store symbols to pop and pop respectively + */ void setPushdownStoreOperations ( ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > operations ); + /** + * Clearer of pushdown store operation + * + * \param input the input symbol for which to clear the pushdown store operation + * \return true if the pushdown store operaion was cleared + */ bool clearPushdownStoreOperation ( const InputSymbolType & input ); + /** + * Get the pushdown store operations. + * + * \return the pushdown store operaions + */ const ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > & getPushdownStoreOperations ( ) const &; + /** + * Get the pushdown store operations. + * + * \return the pushdown store operaions + */ ext::map < InputSymbolType, ext::pair < ext::vector < PushdownStoreSymbolType >, ext::vector < PushdownStoreSymbolType > > > && getPushdownStoreOperations ( ) &&; /** - * Adds transition defined by parameters to the automaton. - * @param current current state - * @param input input symbol - * @param next next state - * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * + * \param current the source state (A) + * \param input the input symbol (a) + * \param next the target state (B) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components, or when the pushdown store operation is not set for the input symbol + * + * \returns true if the transition was indeed added */ bool addTransition ( StateType current, InputSymbolType input, StateType next ); /** - * Adds transition defined by parameters to the automaton. - * @param current current state - * @param input input symbol - * @param next next state - * @throws AutomatonException when transition already exists or when transition contains state or symbol not present in the automaton + * \brief Adds transitions to the automaton. + * + * \details The transition is in a form A times a -> B | C | ... , where A, B, C, ... \in Q and a \in T + * + * \param current the source state (A) + * \param input the input symbol (a) + * \param next the set of target states (B, C, D) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components, or when the pushdown store operation is not set for the input symbol + * + * \returns true if the transition was indeed added */ void addTransitions ( StateType current, InputSymbolType input, ext::set < StateType > next ); /** - * Removes transition from the automaton. - * @param transition transition to remove - * @throws AutomatonException when transition doesn't exists. + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * + * \param current the source state (A) + * \param input the input symbol (a) + * \param next the target state (B) + * + * \returns true if the transition was indeed removed */ bool removeTransition ( const StateType & current, const InputSymbolType & input, const StateType & next ); /** - * @return automaton transitions + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton */ const ext::map < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > & getTransitions ( ) const &; + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ ext::map < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > && getTransitions ( ) &&; + /** + * Get a subset of the transition function of the automaton, with the source state fixed as a view to the internal 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::pair < StateType, InputSymbolType >, ext::set < StateType > > getTransitionsFromState ( const StateType & from ) const; + /** + * Get the transition function of the automaton, with the target state fixed in the transitions natural representation. + * + * \param to filter the transition function based on this state as a source state + * + * \returns a subset of the transition function of the automaton with the target state fixed + */ ext::map < ext::pair < StateType, InputSymbolType >, ext::set < StateType > > getTransitionsToState ( const StateType & to ) const; /** - * Determines whether InputDrivenNPDA is deterministic. - * FA is deterministic if and only if: - * \li \c contains only 1 initial state. - * \li \c is epsilon free. Trivial for this class + * \brief Determines whether the automaton is deterministic. + * + * the automaton is deterministic if and only if: * \li \c size of transition function \delta (from state, input symbol) \leq 1 - * @return true when automaton is deterministic, false otherwise + * + * \return true if the automaton is deterministic, false otherwise */ bool isDeterministic ( ) const; - virtual int compare ( const ObjectBase & other ) const { + /** + * @copydoc alib::CommonBase<ObjectBase>::compare ( const ObjectBase & ) + */ + virtual int compare ( const ObjectBase & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } - virtual int compare ( const InputDrivenNPDA & other ) const; + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same automata instances + */ + int compare ( const InputDrivenNPDA & other ) const; - virtual void operator >>( std::ostream & os ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator >> ( std::ostream & ) + */ + virtual void operator >>( std::ostream & os ) const override; - virtual explicit operator std::string ( ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; + /** + * \brief The XML tag name of class. + * + * \details Intentionaly a static member function to be safe in the initialisation before the main function starts. + * + * \returns string representing the XML tag name of the class + */ static const std::string & getXmlTagName() { static std::string xmlTagName = "InputDrivenNPDA"; return xmlTagName; } + /** + * Parsing from a sequence of xml tokens helper. + * + * \params input the iterator to sequence of xml tokens to parse from + * + * \returns the new instance of the automaton + */ static InputDrivenNPDA parse ( ext::deque < sax::Token >::iterator & input ); + + /** + * Helper for parsing of individual transitions of the automaton from a sequence of xml tokens. + * + * \params input the iterator to sequence of xml tokens to parse from + * \params automaton the automaton to add the rule to + */ static void parseTransition ( ext::deque < sax::Token >::iterator & input, InputDrivenNPDA & automaton ); + /** + * Composing to a sequence of xml tokens helper. + * + * \param out the sink for new xml tokens representing the automaton + * \param automaton the automaton to compose + */ static void compose ( ext::deque < sax::Token > & out, const InputDrivenNPDA & automaton ); + + /** + * Helper for composing transitions of the automaton to a sequence of xml tokens. + * + * \param out the sink for xml tokens representing the rules of the automaton + * \param automaton the automaton to compose + */ static void composeTransitions ( ext::deque < sax::Token > & out, const InputDrivenNPDA & automaton ); - virtual object::ObjectBase * inc ( ) &&; + /** + * @copydoc alib::GrammarBase::inc() + */ + virtual object::ObjectBase * inc ( ) && override; + /** + * Type of normalized automaton. + */ typedef InputDrivenNPDA < > normalized_type; }; @@ -537,9 +879,24 @@ object::ObjectBase* InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, 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 PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { for ( const std::pair<const ext::pair<StateType, InputSymbolType>, ext::set<StateType >>& transition : automaton.getTransitions()) if (transition.first.second == symbol) @@ -548,17 +905,46 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) @@ -573,28 +959,78 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store initial element. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal states component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { if ( automaton.getInitialState ( ) == state ) return true; @@ -609,36 +1045,100 @@ public: 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::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal final states component. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { 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::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal initial state element. + * + * \tparam SymbolType used for the terminal alphabet of 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 PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, 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::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } };