27#include <ext/algorithm>
30#include <alib/multimap>
47class PushdownStoreAlphabet;
71template <
class InputSymbolTypeT = DefaultSymbolType,
class PushdownStoreSymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
72class SinglePopNPDA final :
public core::Components < SinglePopNPDA < 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 > {
111 return this->
template accessComponent < InitialState > ( ).get ( );
120 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
131 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
140 return this->
template accessComponent < States > ( ).get ( );
149 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
160 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
169 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
180 this->
template accessComponent < States > ( ).remove ( state );
189 return this->
template accessComponent < FinalStates > ( ).get ( );
198 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
209 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
218 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
229 this->
template accessComponent < FinalStates > ( ).remove ( state );
238 return this->
template accessComponent < PushdownStoreAlphabet > ( ).get ( );
247 return std::move ( this->
template accessComponent < PushdownStoreAlphabet > ( ).
get ( ) );
258 return this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
267 this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
276 this->
template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
287 this->
template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
296 return this->
template accessComponent < InitialSymbol > ( ).get ( );
305 return std::move ( this->
template accessComponent < InitialSymbol > ( ).
get ( ) );
316 return this->
template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) );
325 return this->
template accessComponent < InputAlphabet > ( ).get ( );
334 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
345 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
354 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
363 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
374 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
499 return std::tie(
getStates(),
getInputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(), transitions) <=>
std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.transitions);
510 return std::tie(
getStates(),
getInputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(), transitions) ==
std::tie(other.
getStates(), other.
getInputAlphabet(), other.
getInitialState(), other.
getFinalStates(), other.
getPushdownStoreAlphabet(), other.
getInitialSymbol(), other.transitions);
522 return out <<
"(SinglePopNPDA"
523 <<
" states = " << instance.
getStates ( )
534template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
535SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::SinglePopNPDA (
ext::set < StateType > states,
ext::set < InputSymbolType > inputAlphabet,
ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet,
StateType initialState,
PushdownStoreSymbolType initialSymbol,
ext::set < StateType > finalStates ) :
core::Components <
SinglePopNPDA,
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 > ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( initialSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) {
538template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
542template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
544 if (! getStates().count(from)) {
548 if ( ! input.is_epsilon ( ) && ! getInputAlphabet().count(input.getSymbol ( ) ) ) {
552 if (! getStates().count(to)) {
556 if (! getPushdownStoreAlphabet().count(pop)) {
561 if (! getPushdownStoreAlphabet().count(pushSymbol)) {
566 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input, pop ) );
567 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input, pop ) );
571 auto iter = std::lower_bound ( lower_bound, upper_bound, value, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
572 if ( iter != upper_bound && value >= iter->second )
576 transitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( value ) ) );
580template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
583 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push));
586template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
589 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push));
592template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
594 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input, pop ) );
595 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input, pop ) );
596 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second.first == to && transition.second.second == push; } );
597 if ( iter == upper_bound )
600 transitions.erase ( iter );
604template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
607 return removeTransition(from, inputVariant, pop, to, push);
610template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
613 return removeTransition(from, inputVariant, pop, to, push);
616template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
621template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
623 return std::move ( transitions );
637template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
638class SetConstraint<
automaton::SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
650 if ( ! std::get<1>(transition.first).is_epsilon ( ) && symbol == std::get<1>(transition.first).getSymbol ( ) )
685template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
686class SetConstraint<
automaton::SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
697 if(
automaton.getInitialSymbol() == symbol)
701 if (symbol == std::get<2>(transition.first))
704 if (std::find(transition.second.second.begin(), transition.second.second.end(), symbol) != transition.second.second.end())
740template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
741class ElementConstraint<
automaton::SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > {
752 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
772template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
784 if (
automaton.getInitialState ( ) == state )
787 if (
automaton.getFinalStates ( ).count ( state ) )
791 if (state == std::get<0>(transition.first))
794 if(transition.second.first == state)
830template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
854 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
874template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
886 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
904template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
905struct normalize <
automaton::SinglePopNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
914 automaton::SinglePopNPDA < > res ( std::move ( states ), std::move (
alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) );
924 res.addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ) );
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static ext::vector< DefaultSymbolType > normalizeSymbols(ext::vector< SymbolType > &&symbols)
Definition: SymbolNormalize.h:86
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Definition: AutomatonException.h:15
static common::symbol_or_epsilon< DefaultSymbolType > normalizeSymbolEpsilon(common::symbol_or_epsilon< SymbolType > &&symbol)
Definition: AutomatonNormalize.h:81
static DefaultStateType normalizeState(StateType &&state)
Definition: AutomatonNormalize.h:76
static ext::multiset< DefaultStateType > normalizeStates(ext::multiset< StateType > &&states)
Definition: AutomatonNormalize.h:49
Definition: SinglePopNPDA.h:72
const StateType & getInitialState() const &
Definition: SinglePopNPDA.h:110
void addInputSymbols(ext::set< InputSymbolType > symbols)
Definition: SinglePopNPDA.h:353
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: SinglePopNPDA.h:75
void removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: SinglePopNPDA.h:286
void setFinalStates(ext::set< StateType > states)
Definition: SinglePopNPDA.h:217
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: SinglePopNPDA.h:324
void removeInputSymbol(const InputSymbolType &symbol)
Definition: SinglePopNPDA.h:373
StateTypeT StateType
Definition: SinglePopNPDA.h:76
void setStates(ext::set< StateType > states)
Definition: SinglePopNPDA.h:168
bool setInitialSymbol(PushdownStoreSymbolType symbol)
Definition: SinglePopNPDA.h:315
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: SinglePopNPDA.h:237
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: SinglePopNPDA.h:295
bool addTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, PushdownStoreSymbolType pop, StateType to, ext::vector< PushdownStoreSymbolType > push)
Adds a transition to the automaton.
Definition: SinglePopNPDA.h:543
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: SinglePopNPDA.h:257
void removeFinalState(const StateType &state)
Definition: SinglePopNPDA.h:228
ext::set< StateType > && getStates() &&
Definition: SinglePopNPDA.h:148
void setInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: SinglePopNPDA.h:362
SinglePopNPDA(ext::set< StateType > states, ext::set< InputSymbolType > inputAlphabet, ext::set< PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType initialSymbol, ext::set< StateType > finalStates)
Creates a new instance of the automaton with a concrete set of states, input alphabet,...
Definition: SinglePopNPDA.h:535
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: SinglePopNPDA.h:246
bool operator==(const SinglePopNPDA &other) const
Definition: SinglePopNPDA.h:509
bool addFinalState(StateType state)
Definition: SinglePopNPDA.h:208
bool removeTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const PushdownStoreSymbolType &pop, const StateType &to, const ext::vector< PushdownStoreSymbolType > &push)
Removes a transition from the automaton.
Definition: SinglePopNPDA.h:593
bool setInitialState(StateType state)
Definition: SinglePopNPDA.h:130
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: SinglePopNPDA.h:266
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: SinglePopNPDA.h:617
const ext::set< StateType > & getStates() const &
Definition: SinglePopNPDA.h:139
StateType && getInitialState() &&
Definition: SinglePopNPDA.h:119
ext::set< InputSymbolType > && getInputAlphabet() &&
Definition: SinglePopNPDA.h:333
friend ext::ostream & operator<<(ext::ostream &out, const SinglePopNPDA &instance)
Definition: SinglePopNPDA.h:521
bool addInputSymbol(InputSymbolType symbol)
Definition: SinglePopNPDA.h:344
const ext::set< StateType > & getFinalStates() const &
Definition: SinglePopNPDA.h:188
bool addState(StateType state)
Definition: SinglePopNPDA.h:159
ext::set< StateType > && getFinalStates() &&
Definition: SinglePopNPDA.h:197
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: SinglePopNPDA.h:275
PushdownStoreSymbolType && getInitialSymbol() &&
Definition: SinglePopNPDA.h:304
void removeState(const StateType &state)
Definition: SinglePopNPDA.h:179
InputSymbolTypeT InputSymbolType
Definition: SinglePopNPDA.h:74
Definition: symbol_or_epsilon.hpp:24
Definition: components.hpp:181
Definition: components.hpp:25
Definition: setComponents.hpp:26
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Definition: BarSymbol.cpp:12
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
Definition: Permutation.hpp:18
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T ¶m)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
Definition: normalize.hpp:13