Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RealTimeHeightDeterministicNPDA.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/multimap>
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 InputAlphabet;
47class PushdownStoreAlphabet;
48class BottomOfTheStackSymbol;
49class States;
50class FinalStates;
51class InitialStates;
52
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 > > {
77public:
78 typedef InputSymbolTypeT InputSymbolType;
79 typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType;
80 typedef StateTypeT StateType;
81
82private:
87
92
97
98public:
112
119 explicit RealTimeHeightDeterministicNPDA ( PushdownStoreSymbolType bottomOfTheStackSymbol );
120
126 const ext::set < StateType > & getStates ( ) const & {
127 return this-> template accessComponent < States > ( ).get ( );
128 }
129
136 return std::move ( this-> template accessComponent < States > ( ).get ( ) );
137 }
138
146 bool addState ( StateType state ) {
147 return this-> template accessComponent < States > ( ).add ( std::move ( state ) );
148 }
149
156 this-> template accessComponent < States > ( ).set ( std::move ( states ) );
157 }
158
166 bool removeState ( const StateType & state ) {
167 return this-> template accessComponent < States > ( ).remove ( state );
168 }
169
176 return this->template accessComponent < InitialStates > ( ).get ( );
177 }
178
185 return std::move ( this->template accessComponent < InitialStates > ( ).get ( ) );
186 }
187
195 bool addInitialState ( StateType state ) {
196 return this->template accessComponent < InitialStates > ( ).add ( std::move ( state ) );
197 }
198
205 this->template accessComponent < InitialStates > ( ).set ( std::move ( states ) );
206 }
207
215 bool removeInitialState ( const StateType & state ) {
216 return this->template accessComponent < InitialStates > ( ).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 < InputAlphabet > ( ).get ( );
362 }
363
370 return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) );
371 }
372
381 return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
382 }
383
390 this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
391 }
392
399 this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
400 }
401
409 void removeInputSymbol ( const InputSymbolType & symbol ) {
410 this-> template accessComponent < InputAlphabet > ( ).remove ( symbol );
411 }
412
428
444
459
475
491
506
521
535 bool addLocalTransition ( StateType from, InputSymbolType input, StateType to );
536
549 bool addLocalTransition ( StateType from, StateType to );
550
565 bool removeCallTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const StateType & to, const PushdownStoreSymbolType & push );
566
581 bool removeCallTransition ( const StateType & from, const InputSymbolType & input, const StateType & to, const PushdownStoreSymbolType & push );
582
596 bool removeCallTransition ( const StateType & from, const StateType & to, const PushdownStoreSymbolType & push );
597
612 bool removeReturnTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const PushdownStoreSymbolType & pop, const StateType & to );
613
628 bool removeReturnTransition ( const StateType & from, const InputSymbolType & input, const PushdownStoreSymbolType & pop, const StateType & to );
629
643 bool removeReturnTransition ( const StateType & from, const PushdownStoreSymbolType & pop, const StateType & to );
644
658 bool removeLocalTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const StateType & to );
659
673 bool removeLocalTransition ( const StateType & from, const InputSymbolType & input, const StateType & to );
674
687 bool removeLocalTransition ( const StateType & from, const StateType & to );
688
695
701 ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && getCallTransitions ( ) &&;
702
708 const ext::multimap < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions ( ) const &;
709
715 ext::multimap < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > && getReturnTransitions ( ) &&;
716
722 const ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > & getLocalTransitions ( ) const &;
723
729 ext::multimap < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > && getLocalTransitions ( ) &&;
730
738 auto operator <=> ( const RealTimeHeightDeterministicNPDA & other ) const {
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);
740 }
741
749 bool operator == ( const RealTimeHeightDeterministicNPDA & other ) const {
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);
751 }
752
762 return out << "(RealTimeHeightDeterministicNPDA"
763 << " states = " << instance.getStates ( )
764 << " inputAlphabet = " << instance.getInputAlphabet ( )
765 << " initialStates = " << instance.getInitialStates ( )
766 << " finalStates = " << instance.getFinalStates ( )
767 << " pushdownStoreAlphabet = " << instance.getPushdownStoreAlphabet ( )
768 << " bottomOfTheStackSymbol = " << instance.getBottomOfTheStackSymbol ( )
769 << " callTransitions = " << instance.getCallTransitions ( )
770 << " returnTransitions = " << instance.getReturnTransitions ( )
771 << " localTransitions = " << instance.getLocalTransitions ( )
772 << ")";
773 }
774};
775
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 ) ) {
778}
779
780template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
782}
783
784template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
786 if (! getStates().count(from)) {
787 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
788 }
789
790 if ( ! input.is_epsilon ( ) && ! getInputAlphabet().count(input.getSymbol ( ))) {
791 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
792 }
793
794 if (! getStates().count(to)) {
795 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
796 }
797
798 if (! getPushdownStoreAlphabet().count(push)) {
799 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( push ) + "\" doesn't exist.");
800 }
801
802 auto upper_bound = callTransitions.upper_bound ( ext::tie ( from, input ) );
803 auto lower_bound = callTransitions.lower_bound ( ext::tie ( from, input ) );
804
805 ext::pair < StateType, PushdownStoreSymbolType > value = ext::make_pair ( std::move ( to ), std::move ( push ) );
806
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 )
809 return false;
810
811 ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > key ( std::move ( from ), std::move ( input ) );
812
813 callTransitions.insert ( iter, std::make_pair ( std::move ( key ), std::move ( value ) ) );
814 return true;
815}
816
817template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
819 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
820 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
821}
822
823template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
826 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
827}
828
829template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
831 if (! getStates().count(from)) {
832 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
833 }
834
835 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ))) {
836 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
837 }
838
839 if (! getStates().count(to)) {
840 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
841 }
842
843 if (! getPushdownStoreAlphabet().count(pop)) {
844 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( pop ) + "\" doesn't exist.");
845 }
846
847 auto upper_bound = returnTransitions.upper_bound ( ext::tie ( from, input, pop ) );
848 auto lower_bound = returnTransitions.lower_bound ( ext::tie ( from, input, pop ) );
849
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 )
852 return false;
853
854 ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType > key ( std::move ( from ), std::move ( input ), std::move ( pop ) );
855
856 returnTransitions.insert ( iter, std::make_pair ( std::move ( key ), std::move ( to ) ) );
857 return true;
858}
859
860template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
862 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
863 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
864}
865
866template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
868 common::symbol_or_epsilon < InputSymbolType > inputVariant(std::move(input));
869 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
870}
871
872template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
874 if (! getStates().count(from)) {
875 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
876 }
877
878 if ( ! input.is_epsilon ( ) && ! getInputAlphabet().count(input.getSymbol ( ))) {
879 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
880 }
881
882 if (! getStates().count(to)) {
883 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
884 }
885
886 auto upper_bound = localTransitions.upper_bound ( ext::tie ( from, input ) );
887 auto lower_bound = localTransitions.lower_bound ( ext::tie ( from, input ) );
888
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 )
891 return false;
892
893 ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > > key ( std::move ( from ), std::move ( input ) );
894
895 localTransitions.insert ( iter, std::make_pair ( std::move ( key ), std::move ( to ) ) );
896 return true;
897}
898
899template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
901 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
902 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
903}
904
905template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
907 common::symbol_or_epsilon < InputSymbolType > inputVariant(std::move(input));
908 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
909}
910
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 )
917 return false;
918
919 callTransitions.erase ( iter );
920 return true;
921}
922
923template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
925 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
926 return removeCallTransition(from, inputVariant, to, push);
927}
928
929template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
932 return removeCallTransition(from, inputVariant, to, push);
933}
934
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 )
941 return false;
942
943 returnTransitions.erase ( iter );
944 return true;
945}
946
947template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
949 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
950 return removeReturnTransition(from, inputVariant, pop, to);
951}
952
953template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
956 return removeReturnTransition(from, inputVariant, pop, to);
957}
958
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 )
965 return false;
966
967 localTransitions.erase ( iter );
968 return true;
969}
970
971template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
973 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
974 return removeLocalTransition(from, inputVariant, to);
975}
976
977template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
980 return removeLocalTransition(from, inputVariant, to);
981}
982
983template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
985 return callTransitions;
986}
987
988template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
990 return std::move ( callTransitions );
991}
992
993template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
995 return returnTransitions;
996}
997
998template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1000 return std::move ( returnTransitions );
1001}
1002
1003template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1005 return localTransitions;
1006}
1007
1008template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1010 return std::move ( localTransitions );
1011}
1012
1013} /* namespace automaton */
1014
1015namespace core {
1016
1024template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1025class SetConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
1026public:
1036 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair < StateType, PushdownStoreSymbolType > >& callTransition : automaton.getCallTransitions())
1037 if ( ! callTransition.first.second.is_epsilon ( ) && symbol == callTransition.first.second.getSymbol ( ))
1038 return true;
1039
1040 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType >& returnTransition : automaton.getReturnTransitions())
1041 if ( ! std::get<1>(returnTransition.first).is_epsilon ( ) && symbol == std::get<1>(returnTransition.first).getSymbol ( ))
1042 return true;
1043
1044 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, StateType >& localTransition : automaton.getLocalTransitions())
1045 if ( ! localTransition.first.second.is_epsilon ( ) && symbol == localTransition.first.second.getSymbol ( ))
1046 return true;
1047
1048 return false;
1049 }
1050
1060 return true;
1061 }
1062
1070 }
1071};
1072
1080template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1081class SetConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
1082public:
1092 if(automaton.getBottomOfTheStackSymbol() == symbol)
1093 return true;
1094
1095 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair < StateType, PushdownStoreSymbolType > >& callTransition : automaton.getCallTransitions())
1096 if (symbol == callTransition.second.second)
1097 return true;
1098
1099 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType >& returnTransition : automaton.getReturnTransitions())
1100 if (symbol == std::get<2>(returnTransition.first))
1101 return true;
1102
1103 return false;
1104 }
1105
1115 return true;
1116 }
1117
1125 }
1126};
1127
1135template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1136class ElementConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::BottomOfTheStackSymbol > {
1137public:
1147 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
1148 }
1149
1157 }
1158};
1159
1167template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1168class SetConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > {
1169public:
1179 if ( automaton.getInitialStates ( ).count ( state ) )
1180 return true;
1181
1182 if ( automaton.getFinalStates ( ).count ( state ) )
1183 return true;
1184
1185 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair<StateType, PushdownStoreSymbolType > >& callTransition : automaton.getCallTransitions()) {
1186 if (state == callTransition.first.first)
1187 return true;
1188
1189 if(callTransition.second.first == state)
1190 return true;
1191 }
1192
1193 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType >& returnTransition : automaton.getReturnTransitions()) {
1194 if (state == std::get<0>(returnTransition.first))
1195 return true;
1196
1197 if(returnTransition.second == state)
1198 return true;
1199 }
1200
1201 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, StateType >& localTransition : automaton.getLocalTransitions()) {
1202 if (state == localTransition.first.first)
1203 return true;
1204
1205 if(localTransition.second == state)
1206 return true;
1207 }
1208
1209 return false;
1210 }
1211
1221 return true;
1222 }
1223
1231 }
1232};
1233
1241template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1242class SetConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > {
1243public:
1253 return false;
1254 }
1255
1265 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1266 }
1267
1275 }
1276};
1277
1285template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1286class SetConstraint< automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialStates > {
1287public:
1297 return false;
1298 }
1299
1309 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1310 }
1311
1319 }
1320};
1321
1327template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1328struct normalize < automaton::RealTimeHeightDeterministicNPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
1330 ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) );
1331 ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) );
1332 DefaultSymbolType bottomOfTheStackSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getBottomOfTheStackSymbol ( ) );
1333 ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) );
1334 ext::set < DefaultStateType > initialStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getInitialStates ( ) );
1335 ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) );
1336
1337 automaton::RealTimeHeightDeterministicNPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialStates ), std::move ( bottomOfTheStackSymbol ), std::move ( finalStates ) );
1338
1339 for ( std::pair < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_mover ( std::move ( value ).getCallTransitions ( ) ) ) {
1340 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) );
1341 DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) );
1342
1343 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1345 res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) );
1346 }
1347
1348 for ( std::pair < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > && transition : ext::make_mover ( std::move ( value ).getReturnTransitions ( ) ) ) {
1349 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1350
1351 DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) );
1352 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) );
1353 common::symbol_or_epsilon < DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) );
1354
1355 res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) );
1356 }
1357
1358 for ( std::pair < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > && transition : ext::make_mover ( std::move ( value ).getLocalTransitions ( ) ) ) {
1359 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1360
1361 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1363
1364 res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) );
1365 }
1366
1367 return res;
1368 }
1369};
1370
1371} /* namespace core */
1372
1374
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
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicNPDA.h:1156
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicNPDA.h:1146
Definition: components.hpp:25
static bool used(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:1178
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1220
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1230
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:1264
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1274
static bool used(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1252
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicNPDA.h:1124
static bool used(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicNPDA.h:1091
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicNPDA.h:1114
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: RealTimeHeightDeterministicNPDA.h:1059
static bool used(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: RealTimeHeightDeterministicNPDA.h:1035
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: RealTimeHeightDeterministicNPDA.h:1069
static bool used(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1296
static void valid(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicNPDA.h:1318
static bool available(const automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicNPDA.h:1308
Definition: setComponents.hpp:26
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.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
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 &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::RealTimeHeightDeterministicNPDA< > eval(automaton::RealTimeHeightDeterministicNPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &&value)
Definition: RealTimeHeightDeterministicNPDA.h:1329
Definition: normalize.hpp:13