27#include <ext/algorithm>
30#include <alib/multimap>
48class PushdownStoreAlphabet;
74template <
class InputSymbolTypeT = DefaultSymbolType,
class OutputSymbolTypeT = DefaultSymbolType,
class PushdownStoreSymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
75class NPDTA final :
public core::Components < NPDTA < InputSymbolTypeT, OutputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < OutputSymbolTypeT >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, InitialSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > {
116 return this->
template accessComponent < InitialState > ( ).get ( );
125 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
136 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
145 return this->
template accessComponent < States > ( ).get ( );
154 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
165 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
174 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
185 this->
template accessComponent < States > ( ).remove ( state );
194 return this->
template accessComponent < FinalStates > ( ).get ( );
203 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
214 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
223 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
234 this->
template accessComponent < FinalStates > ( ).remove ( state );
243 return this->
template accessComponent < PushdownStoreAlphabet > ( ).get ( );
252 return std::move ( this->
template accessComponent < PushdownStoreAlphabet > ( ).
get ( ) );
263 return this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
272 this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
281 this->
template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
292 this->
template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
301 return this->
template accessComponent < InitialSymbol > ( ).get ( );
310 return std::move ( this->
template accessComponent < InitialSymbol > ( ).
get ( ) );
321 return this->
template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) );
330 return this->
template accessComponent < InputAlphabet > ( ).get ( );
339 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
350 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
359 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
368 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
379 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
388 return this->
template accessComponent < OutputAlphabet > ( ).get ( );
397 return std::move ( this->
template accessComponent < OutputAlphabet > ( ).
get ( ) );
408 return this->
template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbol ) );
417 this->
template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbols ) );
426 this->
template accessComponent < OutputAlphabet > ( ).set ( std::move ( symbols ) );
437 this->
template accessComponent < OutputAlphabet > ( ).remove ( symbol );
576 auto operator <=> ( const
NPDTA & other )
const {
577 return std::tie(
getStates(),
getInputAlphabet(),
getOutputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(), transitions) <=>
std::tie(other.getStates(), other.getInputAlphabet(), other.getOutputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.transitions);
588 return std::tie(
getStates(),
getInputAlphabet(),
getOutputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(), transitions) ==
std::tie(other.
getStates(), other.
getInputAlphabet(), other.
getOutputAlphabet(), other.
getInitialState(), other.
getFinalStates(), other.
getPushdownStoreAlphabet(), other.
getInitialSymbol(), other.transitions);
600 return out <<
"(NPDTA"
601 <<
" states = " << instance.
getStates ( )
613template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
614NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >::NPDTA (
ext::set < StateType > states,
ext::set < InputSymbolType > inputAlphabet,
ext::set < OutputSymbolType > outputAlphabet,
ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet,
StateType initialState,
PushdownStoreSymbolType initialSymbol,
ext::set < StateType > finalStates ) :
core::Components <
NPDTA,
ext::set < InputSymbolType >, component::Set, InputAlphabet,
ext::set < OutputSymbolType >, component::Set, OutputAlphabet,
ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet,
PushdownStoreSymbolType, component::Value, InitialSymbol,
ext::set < StateType >, component::Set, std::tuple < States, FinalStates >,
StateType, component::Value, InitialState > ( std::move ( inputAlphabet ), std::move ( outputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( initialSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) {
617template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
618NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >::NPDTA(
StateType initialState,
PushdownStoreSymbolType initialPushdownSymbol) :
NPDTA (
ext::set < StateType > { initialState },
ext::set < InputSymbolType > { },
ext::set < OutputSymbolType > { },
ext::set < PushdownStoreSymbolType > { initialPushdownSymbol }, initialState, initialPushdownSymbol,
ext::set < StateType > { }) {
621template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
623 if (!getStates().count(from)) {
627 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ) ) ) {
631 if (!getStates().count(to)) {
636 if (!getPushdownStoreAlphabet().count(popSymbol)) {
642 if (!getPushdownStoreAlphabet().count(pushSymbol)) {
648 if (!getOutputAlphabet().count(outputSymbol)) {
653 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input, pop ) );
654 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input, pop ) );
658 auto iter = std::lower_bound ( lower_bound, upper_bound, value, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
659 if ( iter != upper_bound && value >= iter->second )
663 transitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( value ) ) );
667template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
670 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output));
673template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
676 return addTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to), std::move(push), std::move(output));
679template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
681 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input, pop ) );
682 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input, pop ) );
683 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return std::get < 0 > ( transition.second ) == to && std::get < 1 > ( transition.second ) == push && std::get < 2 > ( transition.second ) == output; } );
684 if ( iter == upper_bound )
687 transitions.erase ( iter );
691template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
694 return removeTransition(from, inputVariant, pop, to, push, output);
697template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
700 return removeTransition(from, inputVariant, pop, to, push, output);
703template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
708template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
710 return std::move ( transitions );
713template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
715 if( !getStates().count(from))
719 for (
const auto & transition: transitions ) {
720 if ( std::get<0>(transition.first) == from ) {
721 transitionsFromState.
insert ( transition );
725 return transitionsFromState;
740template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
741class SetConstraint<
automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
753 if ( ! std::get<1>(transition.first).is_epsilon ( ) && symbol == std::get<1>(transition.first).getSymbol ( ) )
789template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
790class SetConstraint<
automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >, OutputSymbolType, automaton::OutputAlphabet > {
802 if (std::find(std::get<2>(transition.second).begin(), std::get<2>(transition.second).end(), symbol) != std::get<2>(transition.second).end())
838template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
839class SetConstraint<
automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
850 if(
automaton.getInitialSymbol() == symbol)
854 for (
const PushdownStoreSymbolType& popSymbol : std::get<2>(transition.first))
855 if (symbol == popSymbol)
858 if (std::find(std::get<1>(transition.second).begin(), std::get<1>(transition.second).end(), symbol) != std::get<1>(transition.second).end())
895template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
896class ElementConstraint<
automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > {
907 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
928template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
940 if (
automaton.getInitialState ( ) == state )
943 if (
automaton.getFinalStates ( ).count ( state ) )
947 if (state == std::get<0>(transition.first))
950 if(std::get<0>(transition.second) == state)
987template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1011 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1032template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1044 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1062template <
class InputSymbolType,
class OutputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1063struct normalize <
automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType > > {
1073 automaton::NPDTA < > res ( std::move ( states ), std::move (
alphabet ), std::move ( pushdownAlphabet ), std::move ( outputAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) );
1085 res.addTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ), std::move ( push ), std::move ( output ) );
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
ext::set< OutputSymbolType > && getOutputAlphabet() &&
Definition: NPDTA.h:396
void setOutputAlphabet(ext::set< OutputSymbolType > symbols)
Definition: NPDTA.h:425
void addOutputSymbols(ext::set< OutputSymbolType > symbols)
Definition: NPDTA.h:416
const ext::set< StateType > & getFinalStates() const &
Definition: NPDTA.h:193
const StateType & getInitialState() const &
Definition: NPDTA.h:115
bool addTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, ext::vector< PushdownStoreSymbolType > pop, StateType to, ext::vector< PushdownStoreSymbolType > push, ext::vector< OutputSymbolType > output)
Adds a transition to the automaton.
Definition: NPDTA.h:622
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: NPDTA.h:242
OutputSymbolTypeT OutputSymbolType
Definition: NPDTA.h:78
void removeState(const StateType &state)
Definition: NPDTA.h:184
bool setInitialSymbol(PushdownStoreSymbolType symbol)
Definition: NPDTA.h:320
ext::set< StateType > && getStates() &&
Definition: NPDTA.h:153
const ext::set< OutputSymbolType > & getOutputAlphabet() const &
Definition: NPDTA.h:387
void removeInputSymbol(const InputSymbolType &symbol)
Definition: NPDTA.h:378
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: NPDTA.h:262
friend ext::ostream & operator<<(ext::ostream &out, const NPDTA &instance)
Definition: NPDTA.h:599
NPDTA(ext::set< StateType > states, ext::set< InputSymbolType > inputAlphabet, ext::set< OutputSymbolType > outputAlphabet, ext::set< PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType initialSymbol, ext::set< StateType > finalStates)
Creates a new instance of the automaton with a concrete set of states, input alphabet,...
Definition: NPDTA.h:614
InputSymbolTypeT InputSymbolType
Definition: NPDTA.h:77
void removeFinalState(const StateType &state)
Definition: NPDTA.h:233
void setInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: NPDTA.h:367
bool addInputSymbol(InputSymbolType symbol)
Definition: NPDTA.h:349
ext::set< StateType > && getFinalStates() &&
Definition: NPDTA.h:202
bool addState(StateType state)
Definition: NPDTA.h:164
PushdownStoreSymbolType && getInitialSymbol() &&
Definition: NPDTA.h:309
StateTypeT StateType
Definition: NPDTA.h:80
void setStates(ext::set< StateType > states)
Definition: NPDTA.h:173
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, const ext::vector< OutputSymbolType > &output)
Removes a transition from the automaton.
Definition: NPDTA.h:680
bool setInitialState(StateType state)
Definition: NPDTA.h:135
bool addFinalState(StateType state)
Definition: NPDTA.h:213
void removeOutputSymbol(const OutputSymbolType &symbol)
Definition: NPDTA.h:436
const ext::set< StateType > & getStates() const &
Definition: NPDTA.h:144
ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::tuple< StateType, ext::vector< PushdownStoreSymbolType >, ext::vector< OutputSymbolType > > > getTransitionsFromState(const StateType &from) const
Definition: NPDTA.h:714
bool operator==(const NPDTA &other) const
Definition: NPDTA.h:587
bool addOutputSymbol(OutputSymbolType symbol)
Definition: NPDTA.h:407
ext::set< InputSymbolType > && getInputAlphabet() &&
Definition: NPDTA.h:338
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: NPDTA.h:79
void addInputSymbols(ext::set< InputSymbolType > symbols)
Definition: NPDTA.h:358
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: NPDTA.h:329
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: NPDTA.h:280
void setFinalStates(ext::set< StateType > states)
Definition: NPDTA.h:222
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::tuple< StateType, ext::vector< PushdownStoreSymbolType >, ext::vector< OutputSymbolType > > > & getTransitions() const &
Definition: NPDTA.h:704
void removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: NPDTA.h:291
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: NPDTA.h:300
StateType && getInitialState() &&
Definition: NPDTA.h:124
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: NPDTA.h:251
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: NPDTA.h:271
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
iterator insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: multimap.hpp:118
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