27#include <ext/algorithm>
29#include <alib/multimap>
47class PushdownStoreAlphabet;
48class BottomOfTheStackSymbol;
75template <
class InputSymbolTypeT = DefaultSymbolType,
class PushdownStoreSymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
76class RealTimeHeightDeterministicNPDA final :
public core::Components < RealTimeHeightDeterministicNPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, InitialStates, FinalStates > > {
127 return this->
template accessComponent < States > ( ).get ( );
136 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
147 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
156 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
167 return this->
template accessComponent < States > ( ).remove ( state );
176 return this->
template accessComponent < InitialStates > ( ).get ( );
185 return std::move ( this->
template accessComponent < InitialStates > ( ).
get ( ) );
196 return this->
template accessComponent < InitialStates > ( ).add ( std::move ( state ) );
205 this->
template accessComponent < InitialStates > ( ).set ( std::move ( states ) );
216 return this->
template accessComponent < InitialStates > ( ).remove ( state );
225 return this->
template accessComponent < FinalStates > ( ).get ( );
234 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
245 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
254 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
265 return this->
template accessComponent < FinalStates > ( ).remove ( state );
274 return this->
template accessComponent < PushdownStoreAlphabet > ( ).get ( );
283 return std::move ( this->
template accessComponent < PushdownStoreAlphabet > ( ).
get ( ) );
294 return this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
303 this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
312 this->
template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
323 return this->
template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
332 return this->
template accessComponent < BottomOfTheStackSymbol > ( ).get ( );
341 return std::move ( this->
template accessComponent < BottomOfTheStackSymbol > ( ).
get ( ) );
352 return this->
template accessComponent < BottomOfTheStackSymbol > ( ).set ( std::move ( symbol ) );
361 return this->
template accessComponent < InputAlphabet > ( ).get ( );
370 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
381 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
390 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
399 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
410 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
739 return std::tie(
getStates(),
getInputAlphabet(),
getInitialStates(),
getFinalStates(),
getPushdownStoreAlphabet(),
getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) <=>
std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialStates(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
750 return std::tie(
getStates(),
getInputAlphabet(),
getInitialStates(),
getFinalStates(),
getPushdownStoreAlphabet(),
getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) ==
std::tie(other.
getStates(), other.
getInputAlphabet(), other.
getInitialStates(), other.
getFinalStates(), other.
getPushdownStoreAlphabet(), other.
getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
762 return out <<
"(RealTimeHeightDeterministicNPDA"
763 <<
" states = " << instance.
getStates ( )
776template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
777RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::RealTimeHeightDeterministicNPDA (
ext::set < StateType > states,
ext::set < InputSymbolType > inputAlphabet,
ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet,
ext::set < StateType > initialStates,
PushdownStoreSymbolType bottomOfTheStackSymbol,
ext::set < StateType > finalStates ) :
core::Components <
RealTimeHeightDeterministicNPDA,
ext::set < InputSymbolType >, component::Set, InputAlphabet,
ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet,
PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol,
ext::set < StateType >, component::Set, std::tuple < States, InitialStates, FinalStates > > ( std::move ( inputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( bottomOfTheStackSymbol ), std::move ( states ), std::move ( initialStates ), std::move ( finalStates ) ) {
780template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
784template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
786 if (! getStates().count(from)) {
790 if ( ! input.is_epsilon ( ) && ! getInputAlphabet().count(input.getSymbol ( ))) {
794 if (! getStates().count(to)) {
798 if (! getPushdownStoreAlphabet().count(push)) {
802 auto upper_bound = callTransitions.upper_bound (
ext::tie ( from, input ) );
803 auto lower_bound = callTransitions.lower_bound (
ext::tie ( from, input ) );
807 auto iter = std::lower_bound ( lower_bound, upper_bound, value, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
808 if ( iter != upper_bound && value >= iter->second )
813 callTransitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( value ) ) );
817template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
820 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
823template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
826 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
829template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
831 if (! getStates().count(from)) {
835 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ))) {
839 if (! getStates().count(to)) {
843 if (! getPushdownStoreAlphabet().count(pop)) {
847 auto upper_bound = returnTransitions.upper_bound (
ext::tie ( from, input, pop ) );
848 auto lower_bound = returnTransitions.lower_bound (
ext::tie ( from, input, pop ) );
850 auto iter = std::lower_bound ( lower_bound, upper_bound, to, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
851 if ( iter != upper_bound && to >= iter->second )
856 returnTransitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( to ) ) );
860template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
863 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
866template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
869 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
872template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
874 if (! getStates().count(from)) {
878 if ( ! input.is_epsilon ( ) && ! getInputAlphabet().count(input.getSymbol ( ))) {
882 if (! getStates().count(to)) {
886 auto upper_bound = localTransitions.upper_bound (
ext::tie ( from, input ) );
887 auto lower_bound = localTransitions.lower_bound (
ext::tie ( from, input ) );
889 auto iter = std::lower_bound ( lower_bound, upper_bound, to, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
890 if ( iter != upper_bound && to >= iter->second )
895 localTransitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( to ) ) );
899template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
902 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
905template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
908 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
911template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
913 auto upper_bound = callTransitions.upper_bound (
ext::tie ( from, input ) );
914 auto lower_bound = callTransitions.lower_bound (
ext::tie ( from, input ) );
915 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second.first == to && transition.second.second == push; } );
916 if ( iter == upper_bound )
919 callTransitions.erase ( iter );
923template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
926 return removeCallTransition(from, inputVariant, to, push);
929template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
932 return removeCallTransition(from, inputVariant, to, push);
935template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
937 auto upper_bound = returnTransitions.upper_bound (
ext::tie ( from, input, pop ) );
938 auto lower_bound = returnTransitions.lower_bound (
ext::tie ( from, input, pop ) );
939 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second == to; } );
940 if ( iter == upper_bound )
943 returnTransitions.erase ( iter );
947template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
950 return removeReturnTransition(from, inputVariant, pop, to);
953template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
956 return removeReturnTransition(from, inputVariant, pop, to);
959template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
961 auto upper_bound = localTransitions.upper_bound (
ext::tie ( from, input ) );
962 auto lower_bound = localTransitions.lower_bound (
ext::tie ( from, input ) );
963 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second == to; } );
964 if ( iter == upper_bound )
967 localTransitions.erase ( iter );
971template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
974 return removeLocalTransition(from, inputVariant, to);
977template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
980 return removeLocalTransition(from, inputVariant, to);
983template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
985 return callTransitions;
988template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
990 return std::move ( callTransitions );
993template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
995 return returnTransitions;
998template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1000 return std::move ( returnTransitions );
1003template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1005 return localTransitions;
1008template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1010 return std::move ( localTransitions );
1024template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1025class SetConstraint<
automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
1037 if ( ! callTransition.first.second.is_epsilon ( ) && symbol == callTransition.first.second.getSymbol ( ))
1041 if ( ! std::get<1>(returnTransition.first).is_epsilon ( ) && symbol == std::get<1>(returnTransition.first).getSymbol ( ))
1045 if ( ! localTransition.first.second.is_epsilon ( ) && symbol == localTransition.first.second.getSymbol ( ))
1080template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1081class SetConstraint<
automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
1092 if(
automaton.getBottomOfTheStackSymbol() == symbol)
1096 if (symbol == callTransition.second.second)
1100 if (symbol == std::get<2>(returnTransition.first))
1135template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1136class ElementConstraint<
automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::BottomOfTheStackSymbol > {
1147 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
1167template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1179 if (
automaton.getInitialStates ( ).count ( state ) )
1182 if (
automaton.getFinalStates ( ).count ( state ) )
1186 if (state == callTransition.first.first)
1189 if(callTransition.second.first == state)
1194 if (state == std::get<0>(returnTransition.first))
1197 if(returnTransition.second == state)
1202 if (state == localTransition.first.first)
1205 if(localTransition.second == state)
1241template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1265 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1285template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1309 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1327template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
1328struct normalize <
automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
1345 res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) );
1355 res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) );
1364 res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) );
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
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
Nondeterministic real time height deterministic pushdown automaton. Accepts subset of context free la...
Definition: RealTimeHeightDeterministicNPDA.h:76
const ext::set< StateType > & getInitialStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:175
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: RealTimeHeightDeterministicNPDA.h:293
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: RealTimeHeightDeterministicNPDA.h:273
bool removeInitialState(const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:215
ext::set< InputSymbolType > && getInputAlphabet() &&
Definition: RealTimeHeightDeterministicNPDA.h:369
void setInitialStates(ext::set< StateType > states)
Definition: RealTimeHeightDeterministicNPDA.h:204
const PushdownStoreSymbolType & getBottomOfTheStackSymbol() const &
Definition: RealTimeHeightDeterministicNPDA.h:331
PushdownStoreSymbolType && getBottomOfTheStackSymbol() &&
Definition: RealTimeHeightDeterministicNPDA.h:340
bool removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicNPDA.h:322
bool setBottomOfTheStackSymbol(PushdownStoreSymbolType symbol)
Definition: RealTimeHeightDeterministicNPDA.h:351
bool addState(StateType state)
Definition: RealTimeHeightDeterministicNPDA.h:146
bool addInitialState(StateType state)
Definition: RealTimeHeightDeterministicNPDA.h:195
bool removeState(const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:166
void removeInputSymbol(const InputSymbolType &symbol)
Definition: RealTimeHeightDeterministicNPDA.h:409
bool removeReturnTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const PushdownStoreSymbolType &pop, const StateType &to)
Removes a return transition from the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:936
const ext::set< StateType > & getStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:126
void setStates(ext::set< StateType > states)
Definition: RealTimeHeightDeterministicNPDA.h:155
InputSymbolTypeT InputSymbolType
Definition: RealTimeHeightDeterministicNPDA.h:78
ext::set< StateType > && getStates() &&
Definition: RealTimeHeightDeterministicNPDA.h:135
StateTypeT StateType
Definition: RealTimeHeightDeterministicNPDA.h:80
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:1004
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:984
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: RealTimeHeightDeterministicNPDA.h:311
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: RealTimeHeightDeterministicNPDA.h:302
void addInputSymbols(ext::set< InputSymbolType > symbols)
Definition: RealTimeHeightDeterministicNPDA.h:389
ext::set< StateType > && getFinalStates() &&
Definition: RealTimeHeightDeterministicNPDA.h:233
bool addCallTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, StateType to, PushdownStoreSymbolType push)
Adds a call transition to the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:785
bool addFinalState(StateType state)
Definition: RealTimeHeightDeterministicNPDA.h:244
bool operator==(const RealTimeHeightDeterministicNPDA &other) const
Definition: RealTimeHeightDeterministicNPDA.h:749
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicNPDA.h:224
ext::set< StateType > && getInitialStates() &&
Definition: RealTimeHeightDeterministicNPDA.h:184
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicNPDA.h:994
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: RealTimeHeightDeterministicNPDA.h:360
bool addInputSymbol(InputSymbolType symbol)
Definition: RealTimeHeightDeterministicNPDA.h:380
bool addReturnTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, PushdownStoreSymbolType pop, StateType to)
Adds a return transition to the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:830
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: RealTimeHeightDeterministicNPDA.h:79
void setFinalStates(ext::set< StateType > states)
Definition: RealTimeHeightDeterministicNPDA.h:253
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: RealTimeHeightDeterministicNPDA.h:282
RealTimeHeightDeterministicNPDA(ext::set< StateType > states, ext::set< InputSymbolType > inputAlphabet, ext::set< PushdownStoreSymbolType > pushdownStoreAlphabet, ext::set< StateType > initialStates, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set< StateType > finalStates)
Creates a new instance of the automaton with a concrete set of states, call, return,...
Definition: RealTimeHeightDeterministicNPDA.h:777
void setInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: RealTimeHeightDeterministicNPDA.h:398
bool removeFinalState(const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:264
bool removeLocalTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const StateType &to)
Removes a local transition from the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:960
bool addLocalTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, StateType to)
Adds a local transition to the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:873
friend ext::ostream & operator<<(ext::ostream &out, const RealTimeHeightDeterministicNPDA &instance)
Definition: RealTimeHeightDeterministicNPDA.h:761
bool removeCallTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const StateType &to, const PushdownStoreSymbolType &push)
Removes a call transition from the automaton.
Definition: RealTimeHeightDeterministicNPDA.h:912
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
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