27#include <ext/algorithm>
47class PushdownStoreAlphabet;
77template <
class InputSymbolTypeT = DefaultSymbolType,
class PushdownStoreSymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
78class DPDA final :
public core::Components < DPDA < 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 > {
117 return this->
template accessComponent < InitialState > ( ).get ( );
126 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
137 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
146 return this->
template accessComponent < States > ( ).get ( );
155 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
166 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
175 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
186 this->
template accessComponent < States > ( ).remove ( state );
195 return this->
template accessComponent < FinalStates > ( ).get ( );
204 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
215 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
224 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
235 this->
template accessComponent < FinalStates > ( ).remove ( state );
244 return this->
template accessComponent < PushdownStoreAlphabet > ( ).get ( );
253 return std::move ( this->
template accessComponent < PushdownStoreAlphabet > ( ).
get ( ) );
264 return this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
273 this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
282 this->
template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
293 this->
template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
302 return this->
template accessComponent < InitialSymbol > ( ).get ( );
311 return std::move ( this->
template accessComponent < InitialSymbol > ( ).
get ( ) );
322 return this->
template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) );
331 return this->
template accessComponent < InputAlphabet > ( ).get ( );
340 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
351 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
360 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
369 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
380 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
522 auto operator <=> ( const
DPDA & other )
const {
523 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);
534 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);
546 return out <<
"(DPDA"
547 <<
" states = " << instance.
getStates ( )
558template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
559DPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::DPDA (
ext::set < StateType > states,
ext::set < InputSymbolType > inputAlphabet,
ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet,
StateType initialState,
PushdownStoreSymbolType initialSymbol,
ext::set < StateType > finalStates ) :
core::Components <
DPDA,
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 ) ) {
562template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
566template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
568 if (! getStates().count(from)) {
572 if (! input.is_epsilon ( ) && ! getInputAlphabet().count ( input.getSymbol ( ) ) ) {
576 if (! getStates().count(to)) {
581 if (! getPushdownStoreAlphabet().count(popSymbol)) {
587 if (! getPushdownStoreAlphabet().count(pushSymbol)) {
595 if (transitions.find(key) != transitions.end()) {
596 if(transitions.find(key)->second == value)
602 if(std::get<1>(key).is_epsilon()) {
604 if(std::get<0>(transition.first) == std::get<0>(key)) {
605 const ext::vector<PushdownStoreSymbolType>& alpha = std::get<2>(transition.first);
606 const ext::vector<PushdownStoreSymbolType>& beta = std::get<2>(key);
608 const ext::vector<PushdownStoreSymbolType>& shorter = (alpha.size() < beta.size()) ? alpha : beta;
609 const ext::vector<PushdownStoreSymbolType>& longer = (alpha.size() < beta.size()) ? beta : alpha;
611 for(auto itS = shorter.begin(), itL = longer.begin(); itS != shorter.end(); ++itS, ++itL) {
612 if(*itS != *itL) return false;
621 if(std::get<0>(transition.first) == std::get<0>(key) && ( std::get<1>(transition.first) == std::get<1>(key) || std::get<1>(transition.first).is_epsilon() )) {
622 const ext::vector<PushdownStoreSymbolType>& alpha = std::get<2>(transition.first);
623 const ext::vector<PushdownStoreSymbolType>& beta = std::get<2>(key);
625 const ext::vector<PushdownStoreSymbolType>& shorter = (alpha.size() < beta.size()) ? alpha : beta;
626 const ext::vector<PushdownStoreSymbolType>& longer = (alpha.size() < beta.size()) ? beta : alpha;
628 for(auto itS = shorter.begin(), itL = longer.begin(); itS != shorter.end(); ++itS, ++itL) {
629 if(*itS != *itL) return false;
635 throw AutomatonException(
"Conflicting transition");
638 transitions.insert ( std::move(key), std::move(value) );
642template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
645 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push));
648template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
651 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push));
654template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
659 if (transitions.find(key) == transitions.end())
662 if(transitions.find(key)->second != value)
665 transitions.erase(key);
669template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
672 return removeTransition(from, inputVariant, pop, to, push);
675template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
678 return removeTransition(from, inputVariant, pop, to, push);
681template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
686template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
688 return std::move ( transitions );
691template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
693 if( ! getStates().count(from) )
698 if (std::get<0>(transition.first) == from) {
699 transitionsFromState.
insert ( transition.first, transition.second );
703 return transitionsFromState;
706template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
708 if( ! getStates().count(to))
713 if (transition.second.first == to) {
714 transitionsToState.
insert ( transition.first, transition.second );
718 return transitionsToState;
732template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
733class SetConstraint<
automaton::DPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
745 if ( ! std::get<1>(transition.first).is_epsilon() && symbol == std::get<1>(transition.first).getSymbol())
780template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
781class SetConstraint<
automaton::DPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
792 if(
automaton.getInitialSymbol() == symbol)
796 const auto & popSymbols = std::get<2>(transition.first);
797 const auto & pushSymbols = transition.second.second;
798 if(
ext::contains(popSymbols.begin(), popSymbols.end(), symbol ) ||
ext::contains(pushSymbols.begin(), pushSymbols.end(), symbol))
834template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
835class ElementConstraint<
automaton::DPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > {
846 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
866template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
878 if (
automaton.getInitialState ( ) == state )
881 if (
automaton.getFinalStates ( ).count ( state ) )
885 if ( state == std::get<0>(transition.first) || transition.second.first == state )
920template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
944 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
964template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
976 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
994template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1004 automaton::DPDA < > res ( std::move ( states ), std::move (
alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) );
1014 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
Deterministic pushdown automaton. Accepts subset of context free languages.
Definition: DPDA.h:78
ext::set< StateType > && getFinalStates() &&
Definition: DPDA.h:203
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: DPDA.h:301
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: DPDA.h:243
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: DPDA.h:330
DPDA(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: DPDA.h:559
void setFinalStates(ext::set< StateType > states)
Definition: DPDA.h:223
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: DPDA.h:263
ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > getTransitionsFromState(const StateType &from) const
Definition: DPDA.h:692
void setInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: DPDA.h:368
bool addInputSymbol(InputSymbolType symbol)
Definition: DPDA.h:350
bool operator==(const DPDA &other) const
Definition: DPDA.h:533
bool removeTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const ext::vector< PushdownStoreSymbolType > &pop, const StateType &to, const ext::vector< PushdownStoreSymbolType > &push)
Removes a transition from the automaton.
Definition: DPDA.h:655
ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > getTransitionsToState(const StateType &to) const
Definition: DPDA.h:707
bool addTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, ext::vector< PushdownStoreSymbolType > pop, StateType to, ext::vector< PushdownStoreSymbolType > push)
Adds a transition to the automaton.
Definition: DPDA.h:567
bool setInitialState(StateType state)
Definition: DPDA.h:136
void setStates(ext::set< StateType > states)
Definition: DPDA.h:174
bool addState(StateType state)
Definition: DPDA.h:165
void addInputSymbols(ext::set< InputSymbolType > symbols)
Definition: DPDA.h:359
bool setInitialSymbol(PushdownStoreSymbolType symbol)
Definition: DPDA.h:321
InputSymbolTypeT InputSymbolType
Definition: DPDA.h:80
void removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: DPDA.h:292
StateType && getInitialState() &&
Definition: DPDA.h:125
PushdownStoreSymbolType && getInitialSymbol() &&
Definition: DPDA.h:310
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: DPDA.h:272
void removeState(const StateType &state)
Definition: DPDA.h:185
const ext::set< StateType > & getStates() const &
Definition: DPDA.h:145
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: DPDA.h:252
ext::set< StateType > && getStates() &&
Definition: DPDA.h:154
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: DPDA.h:81
ext::set< InputSymbolType > && getInputAlphabet() &&
Definition: DPDA.h:339
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: DPDA.h:281
void removeInputSymbol(const InputSymbolType &symbol)
Definition: DPDA.h:379
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: DPDA.h:682
friend ext::ostream & operator<<(ext::ostream &out, const DPDA &instance)
Definition: DPDA.h:545
const ext::set< StateType > & getFinalStates() const &
Definition: DPDA.h:194
bool addFinalState(StateType state)
Definition: DPDA.h:214
void removeFinalState(const StateType &state)
Definition: DPDA.h:234
StateTypeT StateType
Definition: DPDA.h:82
const StateType & getInitialState() const &
Definition: DPDA.h:116
Definition: symbol_or_epsilon.hpp:24
Definition: components.hpp:181
Definition: components.hpp:25
Definition: setComponents.hpp:26
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
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
bool contains(InputIt first, InputIt last, const Element &elem)
Linear version of search in a range of values.
Definition: algorithm.hpp:170
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
any_of(T &&...) -> any_of< T... >
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
Definition: normalize.hpp:13