Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
VisiblyPushdownDPDA.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26
27#include <ext/algorithm>
28
29#include <alib/map>
30#include <alib/set>
31#include <alib/vector>
32
33#include <core/components.hpp>
34
37
39
40#include <core/normalize.hpp>
43
44namespace automaton {
45
46class CallAlphabet;
47class ReturnAlphabet;
48class LocalAlphabet;
49class PushdownStoreAlphabet;
50class BottomOfTheStackSymbol;
51class States;
52class FinalStates;
53class InitialState;
54
85template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType >
86class VisiblyPushdownDPDA final : public core::Components < VisiblyPushdownDPDA < InputSymbolTypeT, PushdownStoreSymbolTypeT, StateTypeT >, ext::set < InputSymbolTypeT >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolTypeT >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolTypeT, component::Value, BottomOfTheStackSymbol, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > {
87public:
88 typedef InputSymbolTypeT InputSymbolType;
89 typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType;
90 typedef StateTypeT StateType;
91
92private:
97
102
107
108public:
113
118
131 explicit VisiblyPushdownDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > callAlphabet, ext::set < InputSymbolType > returnAlphabet, ext::set < InputSymbolType > localAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates );
132
139 explicit VisiblyPushdownDPDA ( StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol );
140
146 const StateType & getInitialState ( ) const & {
147 return this-> template accessComponent < InitialState > ( ).get ( );
148 }
149
156 return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) );
157 }
158
166 bool setInitialState ( StateType state ) {
167 return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) );
168 }
169
175 const ext::set < StateType > & getStates ( ) const & {
176 return this-> template accessComponent < States > ( ).get ( );
177 }
178
185 return std::move ( this-> template accessComponent < States > ( ).get ( ) );
186 }
187
195 bool addState ( StateType state ) {
196 return this-> template accessComponent < States > ( ).add ( std::move ( state ) );
197 }
198
205 this-> template accessComponent < States > ( ).set ( std::move ( states ) );
206 }
207
215 bool removeState ( const StateType & state ) {
216 return this-> template accessComponent < States > ( ).remove ( state );
217 }
218
225 return this-> template accessComponent < FinalStates > ( ).get ( );
226 }
227
234 return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) );
235 }
236
244 bool addFinalState ( StateType state ) {
245 return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
246 }
247
254 this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
255 }
256
264 bool removeFinalState ( const StateType & state ) {
265 return this-> template accessComponent < FinalStates > ( ).remove ( state );
266 }
267
274 return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( );
275 }
276
283 return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) );
284 }
285
294 return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
295 }
296
303 this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
304 }
305
312 this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
313 }
314
323 return this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
324 }
325
332 return this->template accessComponent < BottomOfTheStackSymbol > ( ).get ( );
333 }
334
341 return std::move ( this->template accessComponent < BottomOfTheStackSymbol > ( ).get ( ) );
342 }
343
352 return this->template accessComponent < BottomOfTheStackSymbol > ( ).set ( std::move ( symbol ) );
353 }
354
361 return this->template accessComponent < CallAlphabet > ( ).get ( );
362 }
363
370 return std::move ( this->template accessComponent < CallAlphabet > ( ).get ( ) );
371 }
372
381 return this->template accessComponent < CallAlphabet > ( ).add ( std::move ( symbol ) );
382 }
383
390 this->template accessComponent < CallAlphabet > ( ).add ( std::move ( symbols ) );
391 }
392
399 this->template accessComponent < CallAlphabet > ( ).set ( std::move ( symbols ) );
400 }
401
409 bool removeCallInputSymbol ( const InputSymbolType & symbol ) {
410 return this->template accessComponent < CallAlphabet > ( ).remove ( symbol );
411 }
412
419 return this->template accessComponent < ReturnAlphabet > ( ).get ( );
420 }
421
428 return std::move ( this->template accessComponent < ReturnAlphabet > ( ).get ( ) );
429 }
430
439 return this->template accessComponent < ReturnAlphabet > ( ).add ( std::move ( symbol ) );
440 }
441
448 this->template accessComponent < ReturnAlphabet > ( ).add ( std::move ( symbols ) );
449 }
450
457 this->template accessComponent < ReturnAlphabet > ( ).set ( std::move ( symbols ) );
458 }
459
467 bool removeReturnInputSymbol ( const InputSymbolType & symbol ) {
468 return this->template accessComponent < ReturnAlphabet > ( ).remove ( symbol );
469 }
470
477 return this->template accessComponent < LocalAlphabet > ( ).get ( );
478 }
479
486 return std::move ( this->template accessComponent < LocalAlphabet > ( ).get ( ) );
487 }
488
497 return this->template accessComponent < LocalAlphabet > ( ).add ( std::move ( symbol ) );
498 }
499
506 this->template accessComponent < LocalAlphabet > ( ).add ( std::move ( symbols ) );
507 }
508
515 this->template accessComponent < LocalAlphabet > ( ).set ( std::move ( symbols ) );
516 }
517
525 bool removeLocalInputSymbol ( const InputSymbolType & symbol ) {
526 return this->template accessComponent < LocalAlphabet > ( ).remove ( symbol );
527 }
528
536 bool removeInputSymbol(const InputSymbolType& symbol) {
537 return removeCallInputSymbol(symbol) || removeReturnInputSymbol(symbol) || removeLocalInputSymbol(symbol);
538 }
539
555
571
585 bool addLocalTransition ( StateType from, InputSymbolType input, StateType to );
586
601 bool removeCallTransition ( const StateType & from, const InputSymbolType & input, const StateType & to, const PushdownStoreSymbolType & push );
602
617 bool removeReturnTransition ( const StateType & from, const InputSymbolType & input, const PushdownStoreSymbolType & pop, const StateType & to );
618
632 bool removeLocalTransition ( const StateType & from, const InputSymbolType & input, const StateType & to );
633
640
647
653 const ext::map < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > & getReturnTransitions ( ) const &;
654
661
667 const ext::map < ext::pair < StateType, InputSymbolType >, StateType > & getLocalTransitions ( ) const &;
668
674 ext::map < ext::pair < StateType, InputSymbolType >, StateType > && getLocalTransitions ( ) &&;
675
683 auto operator <=> ( const VisiblyPushdownDPDA & other ) const {
684 return std::tie(getStates(), getCallInputAlphabet(), getReturnInputAlphabet(), getLocalInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) <=> std::tie(other.getStates(), other.getCallInputAlphabet(), other.getReturnInputAlphabet(), other.getLocalInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
685 }
686
694 bool operator == ( const VisiblyPushdownDPDA & other ) const {
695 return std::tie(getStates(), getCallInputAlphabet(), getReturnInputAlphabet(), getLocalInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) == std::tie(other.getStates(), other.getCallInputAlphabet(), other.getReturnInputAlphabet(), other.getLocalInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
696 }
697
706 friend ext::ostream & operator << ( ext::ostream & out, const VisiblyPushdownDPDA & instance ) {
707 return out << "(VisiblyPushdownDPDA"
708 << " states = " << instance.getStates ( )
709 << " callAlphabet = " << instance.getCallInputAlphabet ( )
710 << " returnAlphabet = " << instance.getReturnInputAlphabet ( )
711 << " localAlphabet = " << instance.getLocalInputAlphabet ( )
712 << " initialState = " << instance.getInitialState ( )
713 << " finalStates = " << instance.getFinalStates ( )
714 << " pushdownStoreAlphabet = " << instance.getPushdownStoreAlphabet ( )
715 << " bottomOfTheStackSymbol = " << instance.getBottomOfTheStackSymbol ( )
716 << " callTransitions = " << instance.getCallTransitions ( )
717 << " returnTransitions = " << instance.getReturnTransitions ( )
718 << " localTransitions = " << instance.getLocalTransitions ( )
719 << ")";
720 }
721};
722
723template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
724VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::VisiblyPushdownDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > callAlphabet, ext::set < InputSymbolType > returnAlphabet, ext::set < InputSymbolType > localAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates ) : core::Components < VisiblyPushdownDPDA, ext::set < InputSymbolType >, component::Set, std::tuple < CallAlphabet, ReturnAlphabet, LocalAlphabet >, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, BottomOfTheStackSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > ( std::move ( callAlphabet ), std::move ( returnAlphabet ), std::move ( localAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( bottomOfTheStackSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) {
725}
726
727template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
729}
730
731template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
733 if (!getStates().count(from)) {
734 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
735 }
736
737 if (!getCallInputAlphabet().count(input)) {
738 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
739 }
740
741 if (!getStates().count(to)) {
742 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
743 }
744
745 if (!getPushdownStoreAlphabet().count(push)) {
746 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( push ) + "\" doesn't exist.");
747 }
748
749 ext::pair<StateType, InputSymbolType> key(std::move(from), std::move(input));
750 ext::pair<StateType, PushdownStoreSymbolType> value = ext::make_pair(std::move(to), std::move(push));
751
752 if(callTransitions.find(key) != callTransitions.end() && callTransitions.find(key)->second == value)
753 return false;
754
755 for(const auto& transition : callTransitions)
756 if(transition.first.first == key.first && transition.first.second == key.second)
757 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
758
759 for(const auto& transition : returnTransitions)
760 if(std::get<0>(transition.first) == key.first && std::get<1>(transition.first) == key.second)
761 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
762
763 for(const auto& transition : localTransitions)
764 if(transition.first.first == key.first && transition.first.second == key.second)
765 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
766
767 callTransitions.insert ( std::move(key), std::move(value) );
768 return true;
769}
770
771template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
773 if (!getStates().count(from)) {
774 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
775 }
776
777 if (!getReturnInputAlphabet().count(input)) {
778 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
779 }
780
781 if (!getStates().count(to)) {
782 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
783 }
784
785 if (!getPushdownStoreAlphabet().count(pop)) {
786 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( pop ) + "\" doesn't exist.");
787 }
788
789 ext::tuple<StateType, InputSymbolType, PushdownStoreSymbolType> key(std::move(from), std::move(input), std::move(pop));
790
791 if(returnTransitions.find(key) != returnTransitions.end() && returnTransitions.find(key)->second == to)
792 return false;
793
794 for(const auto& transition : callTransitions)
795 if(transition.first.first == std::get<0>(key) && transition.first.second == std::get<1>(key))
796 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + ext::to_string ( std::get<1>(key) ) + "\" is present.");
797
798 for(const auto& transition : returnTransitions)
799 if(std::get<0>(transition.first) == std::get<0>(key) && std::get<1>(transition.first) == std::get<1>(key) && std::get<2>(transition.first) == std::get<2>(key))
800 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + ext::to_string ( std::get<1>(key) ) + "\" is present.");
801
802 for(const auto& transition : localTransitions)
803 if(transition.first.first == std::get<0>(key) && transition.first.second == std::get<1>(key))
804 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when transition reading \"" + ext::to_string ( std::get<1>(key) ) + "\" is present.");
805
806 returnTransitions.insert ( std::move(key), std::move(to) );
807 return true;
808}
809
810template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
812 if (!getStates().count(from)) {
813 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
814 }
815
816 if (!getLocalInputAlphabet().count(input)) {
817 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
818 }
819
820 if (!getStates().count(to)) {
821 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
822 }
823
824 ext::pair<StateType, InputSymbolType> key(std::move(from), std::move(input));
825
826 if(localTransitions.find(key) != localTransitions.end() && localTransitions.find(key)->second == to)
827 return false;
828
829 for(const auto& transition : callTransitions)
830 if(transition.first.first == key.first && transition.first.second == key.second)
831 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
832
833 for(const auto& transition : returnTransitions)
834 if(std::get<0>(transition.first) == key.first && std::get<1>(transition.first) == key.second)
835 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
836
837 for(const auto& transition : localTransitions)
838 if(transition.first.first == key.first && transition.first.second == key.second)
839 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
840
841 localTransitions.insert ( std::move ( key ), std::move ( to ) );
842 return true;
843}
844
845template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
849
850 if (callTransitions.find(key) == callTransitions.end())
851 return false;
852
853 if(callTransitions.find(key)->second != value)
854 throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
855
856 callTransitions.erase(key);
857 return true;
858}
859
860template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
863
864 if (returnTransitions.find(key) == returnTransitions.end())
865 return false;
866
867 if(returnTransitions.find(key)->second != to)
868 throw AutomatonException( "Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
869
870 returnTransitions.erase(key);
871 return true;
872}
873
874template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
877
878 if (localTransitions.find(key) == localTransitions.end())
879 return false;
880
881 if(localTransitions.find(key)->second != to)
882 throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
883
884 localTransitions.erase(key);
885 return true;
886}
887
888template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
890 return callTransitions;
891}
892
893template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
895 return std::move ( callTransitions );
896}
897
898template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
900 return returnTransitions;
901}
902
903template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
905 return std::move ( returnTransitions );
906}
907
908template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
910 return localTransitions;
911}
912
913template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
915 return std::move ( localTransitions );
916}
917
918} /* namespace automaton */
919
920namespace core {
921
929template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
930class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::CallAlphabet > {
931public:
941 for ( const std::pair<const ext::pair<StateType, InputSymbolType>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
942 if (symbol == callTransition.first.second)
943 return true;
944
945 return false;
946 }
947
957 return true;
958 }
959
967 if(automaton.getLocalInputAlphabet().count(symbol))
968 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in local alphabet");
969 if(automaton.getReturnInputAlphabet().count(symbol))
970 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in return alphabet");
971 }
972};
973
981template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
982class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::ReturnAlphabet > {
983public:
993 for ( const std::pair<const ext::tuple<StateType, InputSymbolType, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
994 if (symbol == std::get<1>(returnTransition.first))
995 return true;
996
997 return false;
998 }
999
1009 return true;
1010 }
1011
1019 if(automaton.getLocalInputAlphabet().count(symbol))
1020 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in local alphabet");
1021 if(automaton.getCallInputAlphabet().count(symbol))
1022 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in call alphabet");
1023 }
1024};
1025
1033template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1034class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::LocalAlphabet > {
1035public:
1045 for ( const std::pair<const ext::pair<StateType, InputSymbolType>, StateType>& localTransition : automaton.getLocalTransitions())
1046 if (symbol == localTransition.first.second)
1047 return true;
1048
1049 return false;
1050 }
1051
1061 return true;
1062 }
1063
1071 if(automaton.getReturnInputAlphabet().count(symbol))
1072 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in return alphabet");
1073 if(automaton.getCallInputAlphabet().count(symbol))
1074 throw automaton::AutomatonException("Input symbol " + ext::to_string ( symbol ) + " already in call alphabet");
1075 }
1076};
1077
1085template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1086class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
1087public:
1097 for ( const std::pair<const ext::pair<StateType, InputSymbolType>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
1098 if (symbol == callTransition.second.second)
1099 return true;
1100
1101 for ( const std::pair<const ext::tuple<StateType, InputSymbolType, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
1102 if (symbol == std::get<2>(returnTransition.first))
1103 return true;
1104
1105 if(automaton.getBottomOfTheStackSymbol() == symbol)
1106 return true;
1107
1108 return false;
1109 }
1110
1120 return true;
1121 }
1122
1130 }
1131};
1132
1140template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1141class ElementConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::BottomOfTheStackSymbol > {
1142public:
1152 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
1153 }
1154
1162 }
1163};
1164
1172template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1173class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > {
1174public:
1184 if ( automaton.getInitialState ( ) == state )
1185 return true;
1186
1187 if ( automaton.getFinalStates ( ).count ( state ) )
1188 return true;
1189
1190 for ( const std::pair<const ext::pair<StateType, InputSymbolType>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
1191 if (state == callTransition.first.first || callTransition.second.first == state)
1192 return true;
1193
1194 for ( const std::pair<const ext::tuple<StateType, InputSymbolType, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
1195 if (state == std::get<0>(returnTransition.first) || returnTransition.second == state)
1196 return true;
1197
1198 for ( const std::pair<const ext::pair<StateType, InputSymbolType>, StateType>& localTransition : automaton.getLocalTransitions())
1199 if (state == localTransition.first.first || localTransition.second == state)
1200 return true;
1201
1202 return false;
1203 }
1204
1214 return true;
1215 }
1216
1224 }
1225};
1226
1234template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1235class SetConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > {
1236public:
1246 return false;
1247 }
1248
1258 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1259 }
1260
1268 }
1269};
1270
1278template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1279class ElementConstraint< automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > {
1280public:
1290 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1291 }
1292
1300 }
1301};
1302
1308template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1309struct normalize < automaton::VisiblyPushdownDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
1311 ext::set < DefaultSymbolType > call_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getCallInputAlphabet ( ) );
1312 ext::set < DefaultSymbolType > return_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getReturnInputAlphabet ( ) );
1313 ext::set < DefaultSymbolType > local_alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getLocalInputAlphabet ( ) );
1314 ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) );
1315 DefaultSymbolType initialSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getBottomOfTheStackSymbol ( ) );
1316 ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) );
1317 DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) );
1318 ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) );
1319
1320 automaton::VisiblyPushdownDPDA < > res ( std::move ( states ), std::move ( call_alphabet ), std::move ( return_alphabet ), std::move ( local_alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( initialSymbol ), std::move ( finalStates ) );
1321
1322 for ( std::pair < ext::pair < StateType, InputSymbolType >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_mover ( std::move ( value ).getCallTransitions ( ) ) ) {
1323 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) );
1324 DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) );
1325
1326 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1327 DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) );
1328
1329 res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) );
1330 }
1331
1332 for ( std::pair < ext::tuple < StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > && transition : ext::make_mover ( std::move ( value ).getReturnTransitions ( ) ) ) {
1333 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1334
1335 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) );
1336 DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 1 > ( transition.first ) ) );
1337 DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) );
1338
1339 res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) );
1340 }
1341
1342 for ( std::pair < ext::pair < StateType, InputSymbolType >, StateType > && transition : ext::make_mover ( std::move ( value ).getLocalTransitions ( ) ) ) {
1343 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1344
1345 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1346 DefaultSymbolType input = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.first.second ) );
1347
1348 res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) );
1349 }
1350
1351 return res;
1352 }
1353};
1354
1355} /* namespace core */
1356
1357extern template class automaton::VisiblyPushdownDPDA < >;
1358
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 DefaultStateType normalizeState(StateType &&state)
Definition: AutomatonNormalize.h:76
static ext::multiset< DefaultStateType > normalizeStates(ext::multiset< StateType > &&states)
Definition: AutomatonNormalize.h:49
Deterministic visibly pushdown automaton. Accepts subset of context free languages.
Definition: VisiblyPushdownDPDA.h:86
const PushdownStoreSymbolType & getBottomOfTheStackSymbol() const &
Definition: VisiblyPushdownDPDA.h:331
bool removeInputSymbol(const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:536
ext::set< InputSymbolType > && getCallInputAlphabet() &&
Definition: VisiblyPushdownDPDA.h:369
bool addLocalInputSymbol(InputSymbolType symbol)
Definition: VisiblyPushdownDPDA.h:496
const ext::set< InputSymbolType > & getCallInputAlphabet() const &
Definition: VisiblyPushdownDPDA.h:360
const ext::map< ext::tuple< StateType, InputSymbolType, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: VisiblyPushdownDPDA.h:899
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:302
bool setInitialState(StateType state)
Definition: VisiblyPushdownDPDA.h:166
ext::set< StateType > && getFinalStates() &&
Definition: VisiblyPushdownDPDA.h:233
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: VisiblyPushdownDPDA.h:282
const ext::map< ext::pair< StateType, InputSymbolType >, StateType > & getLocalTransitions() const &
Definition: VisiblyPushdownDPDA.h:909
void setFinalStates(ext::set< StateType > states)
Definition: VisiblyPushdownDPDA.h:253
bool addReturnTransition(StateType from, InputSymbolType input, PushdownStoreSymbolType pop, StateType to)
Adds a return transition to the automaton.
Definition: VisiblyPushdownDPDA.h:772
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:311
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: VisiblyPushdownDPDA.h:89
bool addCallInputSymbol(InputSymbolType symbol)
Definition: VisiblyPushdownDPDA.h:380
const ext::set< StateType > & getFinalStates() const &
Definition: VisiblyPushdownDPDA.h:224
bool removeCallTransition(const StateType &from, const InputSymbolType &input, const StateType &to, const PushdownStoreSymbolType &push)
Removes a call transition from the automaton.
Definition: VisiblyPushdownDPDA.h:846
void setLocalInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:514
bool removeReturnInputSymbol(const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:467
bool removeCallInputSymbol(const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:409
StateType StateType_t
Definition: VisiblyPushdownDPDA.h:112
bool operator==(const VisiblyPushdownDPDA &other) const
Definition: VisiblyPushdownDPDA.h:694
void setStates(ext::set< StateType > states)
Definition: VisiblyPushdownDPDA.h:204
bool setBottomOfTheStackSymbol(PushdownStoreSymbolType symbol)
Definition: VisiblyPushdownDPDA.h:351
bool removeReturnTransition(const StateType &from, const InputSymbolType &input, const PushdownStoreSymbolType &pop, const StateType &to)
Removes a return transition from the automaton.
Definition: VisiblyPushdownDPDA.h:861
ext::set< StateType > && getStates() &&
Definition: VisiblyPushdownDPDA.h:184
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: VisiblyPushdownDPDA.h:293
bool removeLocalInputSymbol(const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:525
const ext::set< InputSymbolType > & getLocalInputAlphabet() const &
Definition: VisiblyPushdownDPDA.h:476
PushdownStoreSymbolType PushdownStoreSymbolType_t
Definition: VisiblyPushdownDPDA.h:117
void setReturnInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:456
VisiblyPushdownDPDA(ext::set< StateType > states, ext::set< InputSymbolType > callAlphabet, ext::set< InputSymbolType > returnAlphabet, ext::set< InputSymbolType > localAlphabet, ext::set< PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set< StateType > finalStates)
Creates a new instance of the automaton with a concrete set of states, call, return,...
Definition: VisiblyPushdownDPDA.h:724
void addCallInputSymbols(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:389
friend ext::ostream & operator<<(ext::ostream &out, const VisiblyPushdownDPDA &instance)
Definition: VisiblyPushdownDPDA.h:706
void addReturnInputSymbols(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:447
const ext::map< ext::pair< StateType, InputSymbolType >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: VisiblyPushdownDPDA.h:889
bool addLocalTransition(StateType from, InputSymbolType input, StateType to)
Adds a local transition to the automaton.
Definition: VisiblyPushdownDPDA.h:811
const ext::set< StateType > & getStates() const &
Definition: VisiblyPushdownDPDA.h:175
bool addReturnInputSymbol(InputSymbolType symbol)
Definition: VisiblyPushdownDPDA.h:438
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: VisiblyPushdownDPDA.h:273
bool removeFinalState(const StateType &state)
Definition: VisiblyPushdownDPDA.h:264
bool removeLocalTransition(const StateType &from, const InputSymbolType &input, const StateType &to)
Removes a local transition from the automaton.
Definition: VisiblyPushdownDPDA.h:875
bool addFinalState(StateType state)
Definition: VisiblyPushdownDPDA.h:244
ext::set< InputSymbolType > && getReturnInputAlphabet() &&
Definition: VisiblyPushdownDPDA.h:427
bool addCallTransition(StateType from, InputSymbolType input, StateType to, PushdownStoreSymbolType push)
Adds a call transition to the automaton.
Definition: VisiblyPushdownDPDA.h:732
StateType && getInitialState() &&
Definition: VisiblyPushdownDPDA.h:155
InputSymbolTypeT InputSymbolType
Definition: VisiblyPushdownDPDA.h:88
bool removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:322
bool removeState(const StateType &state)
Definition: VisiblyPushdownDPDA.h:215
void addLocalInputSymbols(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:505
const ext::set< InputSymbolType > & getReturnInputAlphabet() const &
Definition: VisiblyPushdownDPDA.h:418
PushdownStoreSymbolType && getBottomOfTheStackSymbol() &&
Definition: VisiblyPushdownDPDA.h:340
StateTypeT StateType
Definition: VisiblyPushdownDPDA.h:90
void setCallInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: VisiblyPushdownDPDA.h:398
bool addState(StateType state)
Definition: VisiblyPushdownDPDA.h:195
const StateType & getInitialState() const &
Definition: VisiblyPushdownDPDA.h:146
ext::set< InputSymbolType > && getLocalInputAlphabet() &&
Definition: VisiblyPushdownDPDA.h:485
Definition: components.hpp:181
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: VisiblyPushdownDPDA.h:1289
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: VisiblyPushdownDPDA.h:1299
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:1151
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: VisiblyPushdownDPDA.h:1161
Definition: components.hpp:25
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:1070
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:1044
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: VisiblyPushdownDPDA.h:1060
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: VisiblyPushdownDPDA.h:1223
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: VisiblyPushdownDPDA.h:1183
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: VisiblyPushdownDPDA.h:1213
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:940
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:966
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: VisiblyPushdownDPDA.h:956
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: VisiblyPushdownDPDA.h:1008
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:992
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:1018
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: VisiblyPushdownDPDA.h:1096
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: VisiblyPushdownDPDA.h:1119
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: VisiblyPushdownDPDA.h:1129
static bool available(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: VisiblyPushdownDPDA.h:1257
static bool used(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: VisiblyPushdownDPDA.h:1245
static void valid(const automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: VisiblyPushdownDPDA.h:1267
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
Definition: ostream.h:14
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: set.hpp:44
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
Definition: Object.h:16
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 &param)
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
static automaton::VisiblyPushdownDPDA< > eval(automaton::VisiblyPushdownDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &&value)
Definition: VisiblyPushdownDPDA.h:1310
Definition: normalize.hpp:13