28#include <ext/algorithm>
29#include <ext/iterator>
31#include <alib/multimap>
49class PushdownStoreAlphabet;
78template <
class InputSymbolTypeT = DefaultSymbolType,
class PushdownStoreSymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
79class InputDrivenNPDA final :
public core::Components < InputDrivenNPDA < 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 > {
132 return this->
template accessComponent < InitialState > ( ).get ( );
141 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
152 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
161 return this->
template accessComponent < States > ( ).get ( );
170 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
181 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
190 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
201 this->
template accessComponent < States > ( ).remove ( state );
210 return this->
template accessComponent < FinalStates > ( ).get ( );
219 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
230 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
239 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
250 this->
template accessComponent < FinalStates > ( ).remove ( state );
259 return this->
template accessComponent < PushdownStoreAlphabet > ( ).get ( );
268 return std::move ( this->
template accessComponent < PushdownStoreAlphabet > ( ).
get ( ) );
279 return this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
288 this->
template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
297 this->
template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
308 this->
template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
317 return this->
template accessComponent < InitialSymbol > ( ).get ( );
326 return std::move ( this->
template accessComponent < InitialSymbol > ( ).
get ( ) );
337 return this->
template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) );
346 return this->
template accessComponent < InputAlphabet > ( ).get ( );
355 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
366 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
375 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
384 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
395 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
518 return std::tie(
getStates(),
getInputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(),
getPushdownStoreOperations(), transitions) <=>
std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getInitialSymbol(), other.getPushdownStoreOperations(), other.transitions);
529 return std::tie(
getStates(),
getInputAlphabet(),
getInitialState(),
getFinalStates(),
getPushdownStoreAlphabet(),
getInitialSymbol(),
getPushdownStoreOperations(), transitions) ==
std::tie(other.
getStates(), other.
getInputAlphabet(), other.
getInitialState(), other.
getFinalStates(), other.
getPushdownStoreAlphabet(), other.
getInitialSymbol(), other.
getPushdownStoreOperations(), other.transitions);
541 return out <<
"(InputDrivenNPDA"
542 <<
" states = " << instance.
getStates ( )
554template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
555InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::InputDrivenNPDA (
ext::set < StateType > states,
ext::set < InputSymbolType > inputAlphabet,
ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet,
StateType initialState,
PushdownStoreSymbolType initialSymbol,
ext::set < StateType > finalStates ) :
core::Components <
InputDrivenNPDA,
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 ) ) {
558template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
562template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
564 if (! getInputAlphabet().count(input)) {
565 throw AutomatonException(
"Input symbol \"" +
ext::to_string ( input ) +
"\" doesn't exist.");
568 for(
const PushdownStoreSymbolType& popSymbol : pop) {
569 if (! getPushdownStoreAlphabet().count(popSymbol)) {
570 throw AutomatonException(
"Pushdown store symbol \"" +
ext::to_string ( popSymbol ) +
"\" doesn't exist.");
574 for(
const PushdownStoreSymbolType& pushSymbol : push) {
575 if (! getPushdownStoreAlphabet().count(pushSymbol)) {
576 throw AutomatonException(
"Pushdown store symbol \"" +
ext::to_string ( pushSymbol ) +
"\" doesn't exist.");
581template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
583 checkPushdownStoreOperation(input, pop, push);
584 return inputSymbolToPushdownStoreOperation.insert ( input,
ext::make_pair( pop, push ) ).second;
587template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
593 clearPushdownStoreOperation(removedSymbol);
596 for(
const auto& added : operations) {
597 checkPushdownStoreOperation(added.first, added.second.first, added.second.second);
600 inputSymbolToPushdownStoreOperation = std::move(operations);
603template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
606 if (transition.first.second == input)
610 return inputSymbolToPushdownStoreOperation.erase(input);
613template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
615 return inputSymbolToPushdownStoreOperation;
618template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
620 return std::move ( inputSymbolToPushdownStoreOperation );
623template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
625 if (! getStates().count(from))
628 if (! getInputAlphabet().count(input))
631 if (! getPushdownStoreOperations().count(input))
634 if (! getStates().count(to))
637 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input ) );
638 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input ) );
639 auto iter = std::lower_bound ( lower_bound, upper_bound, to, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
640 if ( iter != upper_bound && to >= iter->second )
644 transitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( to ) ) );
648template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
650 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input ) );
651 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input ) );
652 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second == to; } );
653 if ( iter == upper_bound )
656 transitions.erase ( iter );
660template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
665template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
667 return std::move ( transitions );
670template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
672 if (! getStates().count(from))
677 if (transition.first.first == from) {
678 transitionsFromState.
insert ( transition.first, transition.second );
682 return transitionsFromState;
685template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
687 if (! getStates().count(to))
692 if (transition.second == to ) {
693 transitionsToState.
insert ( transition.first, transition.second );
697 return transitionsToState;
700template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
702 if ( transitions.empty ( ) )
705 for (
auto iter = transitions.begin ( ); std::next ( iter ) != transitions.end ( ); ++ iter )
706 if ( iter->first == std::next ( iter )->first )
723template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
724class SetConstraint<
automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
736 if (transition.first.second == symbol)
771template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
772class SetConstraint<
automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
783 for (
const auto& pushdownStoreOperation :
automaton.getPushdownStoreOperations()) {
784 if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end())
786 if (std::find(pushdownStoreOperation.second.second.begin(), pushdownStoreOperation.second.second.end(), symbol) != pushdownStoreOperation.second.second.end())
790 if(
automaton.getInitialSymbol() == symbol)
825template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
826class ElementConstraint<
automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > {
837 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
857template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
869 if (
automaton.getInitialState ( ) == state )
872 if (
automaton.getFinalStates ( ).count ( state ) )
876 if (transition.first.first == state || transition.second == state )
911template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
935 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
955template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
967 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
985template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
986struct normalize <
automaton::InputDrivenNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
1002 res.setPushdownStoreOperation ( std::move ( target ), std::move ( pop ), std::move ( push ) );
1011 res.addTransition ( std::move ( from ), std::move ( input ), std::move ( targets ) );
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 DefaultStateType normalizeState(StateType &&state)
Definition: AutomatonNormalize.h:76
static ext::multiset< DefaultStateType > normalizeStates(ext::multiset< StateType > &&states)
Definition: AutomatonNormalize.h:49
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
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 pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
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: 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
key_iterator< map_type > key_begin(const map_type &m)
Definition: iterator.hpp:1027
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
key_iterator< map_type > key_end(const map_type &m)
Definition: iterator.hpp:1041
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void end()
Definition: measurements.cpp:19
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
Definition: normalize.hpp:13