Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RealTimeHeightDeterministicDPDA.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 InputAlphabet;
47class PushdownStoreAlphabet;
48class BottomOfTheStackSymbol;
49class States;
50class FinalStates;
51class InitialState;
52
88template < class InputSymbolTypeT = DefaultSymbolType, class PushdownStoreSymbolTypeT = DefaultSymbolType, class StateTypeT = DefaultStateType >
89class RealTimeHeightDeterministicDPDA final : public core::Components < RealTimeHeightDeterministicDPDA < 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, FinalStates >, StateTypeT, component::Value, InitialState > {
90public:
91 typedef InputSymbolTypeT InputSymbolType;
92 typedef PushdownStoreSymbolTypeT PushdownStoreSymbolType;
93 typedef StateTypeT StateType;
94
95private:
100
105
110
111public:
116
121
134 explicit RealTimeHeightDeterministicDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates );
135
142 explicit RealTimeHeightDeterministicDPDA ( StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol );
143
149 const StateType & getInitialState ( ) const & {
150 return this-> template accessComponent < InitialState > ( ).get ( );
151 }
152
159 return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) );
160 }
161
169 bool setInitialState ( StateType state ) {
170 return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) );
171 }
172
178 const ext::set < StateType > & getStates ( ) const & {
179 return this-> template accessComponent < States > ( ).get ( );
180 }
181
188 return std::move ( this-> template accessComponent < States > ( ).get ( ) );
189 }
190
198 bool addState ( StateType state ) {
199 return this-> template accessComponent < States > ( ).add ( std::move ( state ) );
200 }
201
208 this-> template accessComponent < States > ( ).set ( std::move ( states ) );
209 }
210
218 bool removeState ( const StateType & state ) {
219 return this-> template accessComponent < States > ( ).remove ( state );
220 }
221
228 return this-> template accessComponent < FinalStates > ( ).get ( );
229 }
230
237 return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) );
238 }
239
247 bool addFinalState ( StateType state ) {
248 return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
249 }
250
257 this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
258 }
259
267 bool removeFinalState ( const StateType & state ) {
268 return this-> template accessComponent < FinalStates > ( ).remove ( state );
269 }
270
277 return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( );
278 }
279
286 return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) );
287 }
288
297 return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) );
298 }
299
306 this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) );
307 }
308
315 this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) );
316 }
317
326 return this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol );
327 }
328
335 return this->template accessComponent < BottomOfTheStackSymbol > ( ).get ( );
336 }
337
344 return std::move ( this->template accessComponent < BottomOfTheStackSymbol > ( ).get ( ) );
345 }
346
355 return this->template accessComponent < BottomOfTheStackSymbol > ( ).set ( std::move ( symbol ) );
356 }
357
364 return this-> template accessComponent < InputAlphabet > ( ).get ( );
365 }
366
373 return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) );
374 }
375
384 return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
385 }
386
393 this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
394 }
395
402 this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
403 }
404
412 void removeInputSymbol ( const InputSymbolType & symbol ) {
413 this-> template accessComponent < InputAlphabet > ( ).remove ( symbol );
414 }
415
431
447
462
478
494
509
524
538 bool addLocalTransition ( StateType from, InputSymbolType input, StateType to );
539
552 bool addLocalTransition ( StateType from, StateType to );
553
568 bool removeCallTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const StateType & to, const PushdownStoreSymbolType & push );
569
584 bool removeCallTransition ( const StateType & from, const InputSymbolType & input, const StateType & to, const PushdownStoreSymbolType & push );
585
599 bool removeCallTransition ( const StateType & from, const StateType & to, const PushdownStoreSymbolType & push );
600
615 bool removeReturnTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const PushdownStoreSymbolType & pop, const StateType & to );
616
631 bool removeReturnTransition ( const StateType & from, const InputSymbolType & input, const PushdownStoreSymbolType & pop, const StateType & to );
632
646 bool removeReturnTransition ( const StateType & from, const PushdownStoreSymbolType & pop, const StateType & to );
647
661 bool removeLocalTransition ( const StateType & from, const common::symbol_or_epsilon < InputSymbolType > & input, const StateType & to );
662
676 bool removeLocalTransition ( const StateType & from, const InputSymbolType & input, const StateType & to );
677
690 bool removeLocalTransition ( const StateType & from, const StateType & to );
691
698
704 ext::map < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && getCallTransitions ( ) &&;
705
711 const ext::map < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions ( ) const &;
712
718 ext::map < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > && getReturnTransitions ( ) &&;
719
725 const ext::map < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > & getLocalTransitions ( ) const &;
726
732 ext::map < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > && getLocalTransitions ( ) &&;
733
741 auto operator <=> ( const RealTimeHeightDeterministicDPDA & other ) const {
742 return std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) <=> std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
743 }
744
752 bool operator == ( const RealTimeHeightDeterministicDPDA & other ) const {
753 return std::tie(getStates(), getInputAlphabet(), getInitialState(), getFinalStates(), getPushdownStoreAlphabet(), getBottomOfTheStackSymbol(), callTransitions, returnTransitions, localTransitions) == std::tie(other.getStates(), other.getInputAlphabet(), other.getInitialState(), other.getFinalStates(), other.getPushdownStoreAlphabet(), other.getBottomOfTheStackSymbol(), other.callTransitions, other.returnTransitions, other.localTransitions);
754 }
755
765 return out << "(RealTimeHeightDeterministicDPDA"
766 << " states = " << instance.getStates ( )
767 << " inputAlphabet = " << instance.getInputAlphabet ( )
768 << " initialState = " << instance.getInitialState ( )
769 << " finalStates = " << instance.getFinalStates ( )
770 << " pushdownStoreAlphabet = " << instance.getPushdownStoreAlphabet ( )
771 << " bottomOfTheStackSymbol = " << instance.getBottomOfTheStackSymbol ( )
772 << " callTransitions = " << instance.getCallTransitions ( )
773 << " returnTransitions = " << instance.getReturnTransitions ( )
774 << " localTransitions = " << instance.getLocalTransitions ( )
775 << ")";
776 }
777};
778
779template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
780RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >::RealTimeHeightDeterministicDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreAlphabet, StateType initialState, PushdownStoreSymbolType bottomOfTheStackSymbol, ext::set < StateType > finalStates ) : core::Components < RealTimeHeightDeterministicDPDA, ext::set < InputSymbolType >, component::Set, InputAlphabet, 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 ( inputAlphabet ), std::move ( pushdownStoreAlphabet ), std::move ( bottomOfTheStackSymbol ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) {
781}
782
783template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
785}
786
787template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
789 if (!getStates().count(from)) {
790 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
791 }
792
793 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ))) {
794 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
795 }
796
797 if (!getStates().count(to)) {
798 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
799 }
800
801 if (!getPushdownStoreAlphabet().count(push)) {
802 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( push ) + "\" doesn't exist.");
803 }
804
805 if(getBottomOfTheStackSymbol() == push)
806 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( push ) + "\" is bottom of the stack.");
807
808 ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >> key(std::move(from), std::move(input));
809 ext::pair<StateType, PushdownStoreSymbolType> value = ext::make_pair(std::move(to), std::move(push));
810
811 if(callTransitions.find(key) != callTransitions.end() && callTransitions.find(key)->second == value)
812 return false;
813
814 if(key.second.is_epsilon ( ) ) {
815 for(const auto& transition : callTransitions)
816 if(transition.first.first == key.first )
817 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
818
819 for(const auto& transition : returnTransitions)
820 if(std::get<0>(transition.first) == key.first)
821 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
822
823 for(const auto& transition : localTransitions)
824 if(transition.first.first == key.first)
825 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
826 } else {
827 for(const auto& transition : callTransitions)
828 if(transition.first.first == key.first && (transition.first.second.is_epsilon ( ) || transition.first.second == key.second))
829 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
830
831 for(const auto& transition : returnTransitions)
832 if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).is_epsilon ( ) || std::get<1>(transition.first) == key.second))
833 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
834
835 for(const auto& transition : localTransitions)
836 if(transition.first.first == key.first && (transition.first.second.is_epsilon ( ) || transition.first.second == key.second))
837 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
838 }
839
840 callTransitions.insert ( std::move ( key ), std::move ( value ) );
841 return true;
842}
843
844template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
846 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
847 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
848}
849
850template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
852 common::symbol_or_epsilon < InputSymbolType > inputVariant(std::move(input));
853 return addCallTransition(std::move(from), std::move(inputVariant), std::move(to), std::move(push));
854}
855
856template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
858 if (!getStates().count(from)) {
859 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
860 }
861
862 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ))) {
863 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
864 }
865
866 if (!getStates().count(to)) {
867 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
868 }
869
870 if (!getPushdownStoreAlphabet().count(pop)) {
871 throw AutomatonException("Pushdown store symbol \"" + ext::to_string ( pop ) + "\" doesn't exist.");
872 }
873
874 ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType> key(std::move(from), std::move(input), std::move(pop));
875
876 if(returnTransitions.find(key) != returnTransitions.end() && returnTransitions.find(key)->second == to)
877 return false;
878
879 if(std::get<1>(key).is_epsilon ( ) ) {
880 for(const auto& transition : callTransitions)
881 if(transition.first.first == std::get<0>(key) )
882 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when other transitions are present.");
883
884 for(const auto& transition : returnTransitions)
885 if(std::get<0>(transition.first) == std::get<0>(key) && std::get<2>(transition.first) == std::get<2>(key))
886 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when other transitions are present.");
887
888 for(const auto& transition : localTransitions)
889 if(transition.first.first == std::get<0>(key))
890 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( std::get<0>(key) ) + "\" when other transitions are present.");
891 } else {
892 for(const auto& transition : callTransitions)
893 if(transition.first.first == std::get<0>(key) && (transition.first.second.is_epsilon ( ) || transition.first.second == std::get<1>(key)))
894 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.");
895
896 for(const auto& transition : returnTransitions)
897 if(std::get<0>(transition.first) == std::get<0>(key) && (std::get<1>(transition.first).is_epsilon ( ) || std::get<1>(transition.first) == std::get<1>(key)) && std::get<2>(transition.first) == std::get<2>(key))
898 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.");
899
900 for(const auto& transition : localTransitions)
901 if(transition.first.first == std::get<0>(key) && (transition.first.second.is_epsilon ( ) || transition.first.second == std::get<1>(key)))
902 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.");
903 }
904
905 returnTransitions.insert ( std::move ( key ), std::move ( to ) );
906 return true;
907}
908
909template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
911 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
912 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
913}
914
915template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
917 common::symbol_or_epsilon < InputSymbolType > inputVariant(std::move(input));
918 return addReturnTransition(std::move(from), std::move(inputVariant), std::move(pop), std::move(to));
919}
920
921template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
923 if (!getStates().count(from)) {
924 throw AutomatonException("State \"" + ext::to_string ( from ) + "\" doesn't exist.");
925 }
926
927 if ( ! input.is_epsilon ( ) && !getInputAlphabet().count(input.getSymbol ( ))) {
928 throw AutomatonException("Input symbol \"" + ext::to_string ( input ) + "\" doesn't exist.");
929 }
930
931 if (!getStates().count(to)) {
932 throw AutomatonException("State \"" + ext::to_string ( to ) + "\" doesn't exist.");
933 }
934
935 ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >> key(std::move(from), std::move(input));
936
937 if(localTransitions.find(key) != localTransitions.end() && localTransitions.find(key)->second == to)
938 return false;
939
940 if(key.second.is_epsilon ( ) ) {
941 for(const auto& transition : callTransitions)
942 if(transition.first.first == key.first )
943 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
944
945 for(const auto& transition : returnTransitions)
946 if(std::get<0>(transition.first) == key.first)
947 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
948
949 for(const auto& transition : localTransitions)
950 if(transition.first.first == key.first)
951 throw AutomatonException("Can't add epsilon transition from state \"" + ext::to_string ( key.first ) + "\" when other transitions are present.");
952 } else {
953 for(const auto& transition : callTransitions)
954 if(transition.first.first == key.first && (transition.first.second.is_epsilon ( ) || transition.first.second == key.second))
955 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
956
957 for(const auto& transition : returnTransitions)
958 if(std::get<0>(transition.first) == key.first && (std::get<1>(transition.first).is_epsilon ( ) || std::get<1>(transition.first) == key.second))
959 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
960
961 for(const auto& transition : localTransitions)
962 if(transition.first.first == key.first && (transition.first.second.is_epsilon ( ) || transition.first.second == key.second))
963 throw AutomatonException("Can't add transition from state \"" + ext::to_string ( key.first ) + "\" when transition reading \"" + ext::to_string ( key.second ) + "\" is present.");
964 }
965
966 localTransitions.insert ( std::move ( key ), std::move ( to ) );
967 return true;
968}
969
970template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
972 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
973 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
974}
975
976template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
978 common::symbol_or_epsilon < InputSymbolType > inputVariant(std::move(input));
979 return addLocalTransition(std::move(from), std::move(inputVariant), std::move(to));
980}
981
982template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
986
987 if (callTransitions.find(key) == callTransitions.end())
988 return false;
989
990 if(callTransitions.find(key)->second != value)
991 throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
992
993 callTransitions.erase(key);
994 return true;
995}
996
997template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
999 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
1000 return removeCallTransition(from, inputVariant, to, push);
1001}
1002
1003template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1006 return removeCallTransition(from, inputVariant, to, push);
1007}
1008
1009template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1012
1013 if (returnTransitions.find(key) == returnTransitions.end())
1014 return false;
1015
1016 if(returnTransitions.find(key)->second != to)
1017 throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
1018
1019 returnTransitions.erase(key);
1020 return true;
1021}
1022
1023template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1025 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
1026 return removeReturnTransition(from, inputVariant, pop, to);
1027}
1028
1029template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1032 return removeReturnTransition(from, inputVariant, pop, to);
1033}
1034
1035template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1038
1039 if (localTransitions.find(key) == localTransitions.end())
1040 return false;
1041
1042 if(localTransitions.find(key)->second != to)
1043 throw AutomatonException("Transition (\"" + ext::to_string ( from ) + "\", \"" + ext::to_string ( input ) + "\") -> \"" + ext::to_string ( to ) + "\" doesn't exist.");
1044
1045 localTransitions.erase(key);
1046 return true;
1047}
1048
1049template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1051 auto inputVariant = common::symbol_or_epsilon < InputSymbolType > ( );
1052 return removeLocalTransition(from, inputVariant, to);
1053}
1054
1055template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1058 return removeLocalTransition(from, inputVariant, to);
1059}
1060
1061template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1063 return callTransitions;
1064}
1065
1066template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1068 return std::move ( callTransitions );
1069}
1070
1071template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1073 return returnTransitions;
1074}
1075
1076template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1078 return std::move ( returnTransitions );
1079}
1080
1081template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1083 return localTransitions;
1084}
1085
1086template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1088 return std::move ( localTransitions );
1089}
1090
1091} /* namespace automaton */
1092
1093namespace core {
1094
1102template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1103class SetConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > {
1104public:
1114 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
1115 if ( ! callTransition.first.second.is_epsilon ( ) && symbol == callTransition.first.second.getSymbol ( ))
1116 return true;
1117
1118 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
1119 if ( ! std::get<1>(returnTransition.first).is_epsilon ( ) && symbol == std::get<1>(returnTransition.first).getSymbol ( ))
1120 return true;
1121
1122 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, StateType>& localTransition : automaton.getLocalTransitions())
1123 if ( ! localTransition.first.second.is_epsilon ( ) && symbol == localTransition.first.second.getSymbol ( ))
1124 return true;
1125
1126 return false;
1127 }
1128
1138 return true;
1139 }
1140
1148 }
1149};
1150
1158template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1159class SetConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > {
1160public:
1170 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
1171 if (symbol == callTransition.second.second)
1172 return true;
1173
1174 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
1175 if (symbol == std::get<2>(returnTransition.first))
1176 return true;
1177
1178 if(automaton.getBottomOfTheStackSymbol() == symbol)
1179 return true;
1180
1181 return false;
1182 }
1183
1193 return true;
1194 }
1195
1203 }
1204};
1205
1213template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1214class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::BottomOfTheStackSymbol > {
1215public:
1225 return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol );
1226 }
1227
1235 }
1236};
1237
1245template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1246class SetConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > {
1247public:
1257 if ( automaton.getInitialState ( ) == state )
1258 return true;
1259
1260 if ( automaton.getFinalStates ( ).count ( state ) )
1261 return true;
1262
1263 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, ext::pair<StateType, PushdownStoreSymbolType> >& callTransition : automaton.getCallTransitions())
1264 if (state == callTransition.first.first || callTransition.second.first == state)
1265 return true;
1266
1267 for ( const std::pair<const ext::tuple<StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType>, StateType>& returnTransition : automaton.getReturnTransitions())
1268 if (state == std::get<0>(returnTransition.first) || returnTransition.second == state)
1269 return true;
1270
1271 for ( const std::pair<const ext::pair<StateType, common::symbol_or_epsilon < InputSymbolType >>, StateType>& localTransition : automaton.getLocalTransitions())
1272 if (state == localTransition.first.first || localTransition.second == state)
1273 return true;
1274
1275 return false;
1276 }
1277
1287 return true;
1288 }
1289
1297 }
1298};
1299
1307template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1308class SetConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > {
1309public:
1319 return false;
1320 }
1321
1331 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1332 }
1333
1341 }
1342};
1343
1351template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1352class ElementConstraint< automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > {
1353public:
1363 return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state );
1364 }
1365
1373 }
1374};
1375
1381template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
1382struct normalize < automaton::RealTimeHeightDeterministicDPDA < InputSymbolType, PushdownStoreSymbolType, StateType > > {
1384 ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getInputAlphabet ( ) );
1385 ext::set < DefaultSymbolType > pushdownAlphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getPushdownStoreAlphabet ( ) );
1386 DefaultSymbolType bottomOfTheStackSymbol = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( value ).getBottomOfTheStackSymbol ( ) );
1387 ext::set < DefaultStateType > states = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getStates ( ) );
1388 DefaultStateType initialState = automaton::AutomatonNormalize::normalizeState ( std::move ( value ).getInitialState ( ) );
1389 ext::set < DefaultStateType > finalStates = automaton::AutomatonNormalize::normalizeStates ( std::move ( value ).getFinalStates ( ) );
1390
1391 automaton::RealTimeHeightDeterministicDPDA < > res ( std::move ( states ), std::move ( alphabet ), std::move ( pushdownAlphabet ), std::move ( initialState ), std::move ( bottomOfTheStackSymbol ), std::move ( finalStates ) );
1392
1393 for ( std::pair < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, ext::pair < StateType, PushdownStoreSymbolType > > && transition : ext::make_mover ( std::move ( value ).getCallTransitions ( ) ) ) {
1394 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second.first ) );
1395 DefaultSymbolType push = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( transition.second.second ) );
1396
1397 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1399
1400 res.addCallTransition ( std::move ( from ), std::move ( input ), std::move ( to ), std::move ( push ) );
1401 }
1402
1403 for ( std::pair < ext::tuple < StateType, common::symbol_or_epsilon < InputSymbolType >, PushdownStoreSymbolType >, StateType > && transition : ext::make_mover ( std::move ( value ).getReturnTransitions ( ) ) ) {
1404 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1405
1406 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( std::get < 0 > ( transition.first ) ) );
1407 common::symbol_or_epsilon < DefaultSymbolType > input = automaton::AutomatonNormalize::normalizeSymbolEpsilon ( std::move ( std::get < 1 > ( transition.first ) ) );
1408 DefaultSymbolType pop = alphabet::SymbolNormalize::normalizeSymbol ( std::move ( std::get < 2 > ( transition.first ) ) );
1409
1410 res.addReturnTransition ( std::move ( from ), std::move ( input ), std::move ( pop ), std::move ( to ) );
1411 }
1412
1413 for ( std::pair < ext::pair < StateType, common::symbol_or_epsilon < InputSymbolType > >, StateType > && transition : ext::make_mover ( std::move ( value ).getLocalTransitions ( ) ) ) {
1414 DefaultStateType to = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.second ) );
1415
1416 DefaultStateType from = automaton::AutomatonNormalize::normalizeState ( std::move ( transition.first.first ) );
1418 res.addLocalTransition ( std::move ( from ), std::move ( input ), std::move ( to ) );
1419 }
1420
1421 return res;
1422 }
1423};
1424
1425} /* namespace core */
1426
1428
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
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
PushdownStoreSymbolType PushdownStoreSymbolType_t
Definition: RealTimeHeightDeterministicDPDA.h:120
PushdownStoreSymbolTypeT PushdownStoreSymbolType
Definition: RealTimeHeightDeterministicDPDA.h:92
bool addPushdownStoreSymbol(PushdownStoreSymbolType symbol)
Definition: RealTimeHeightDeterministicDPDA.h:296
bool addLocalTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, StateType to)
Adds a local transition to the automaton.
Definition: RealTimeHeightDeterministicDPDA.h:922
bool operator==(const RealTimeHeightDeterministicDPDA &other) const
Definition: RealTimeHeightDeterministicDPDA.h:752
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: RealTimeHeightDeterministicDPDA.h:363
bool addReturnTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, PushdownStoreSymbolType pop, StateType to)
Adds a return transition to the automaton.
Definition: RealTimeHeightDeterministicDPDA.h:857
StateTypeT StateType
Definition: RealTimeHeightDeterministicDPDA.h:93
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: RealTimeHeightDeterministicDPDA.h:1010
void setPushdownStoreAlphabet(ext::set< PushdownStoreSymbolType > symbols)
Definition: RealTimeHeightDeterministicDPDA.h:314
bool removeState(const StateType &state)
Definition: RealTimeHeightDeterministicDPDA.h:218
ext::set< PushdownStoreSymbolType > && getPushdownStoreAlphabet() &&
Definition: RealTimeHeightDeterministicDPDA.h:285
ext::set< StateType > && getFinalStates() &&
Definition: RealTimeHeightDeterministicDPDA.h:236
PushdownStoreSymbolType && getBottomOfTheStackSymbol() &&
Definition: RealTimeHeightDeterministicDPDA.h:343
const StateType & getInitialState() const &
Definition: RealTimeHeightDeterministicDPDA.h:149
bool removeLocalTransition(const StateType &from, const common::symbol_or_epsilon< InputSymbolType > &input, const StateType &to)
Removes a local transition from the automaton.
Definition: RealTimeHeightDeterministicDPDA.h:1036
RealTimeHeightDeterministicDPDA(ext::set< StateType > states, ext::set< InputSymbolType > inputAlphabet, 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: RealTimeHeightDeterministicDPDA.h:780
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1062
void setStates(ext::set< StateType > states)
Definition: RealTimeHeightDeterministicDPDA.h:207
void setFinalStates(ext::set< StateType > states)
Definition: RealTimeHeightDeterministicDPDA.h:256
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: RealTimeHeightDeterministicDPDA.h:276
bool setInitialState(StateType state)
Definition: RealTimeHeightDeterministicDPDA.h:169
InputSymbolTypeT InputSymbolType
Definition: RealTimeHeightDeterministicDPDA.h:91
StateType StateType_t
Definition: RealTimeHeightDeterministicDPDA.h:115
friend ext::ostream & operator<<(ext::ostream &out, const RealTimeHeightDeterministicDPDA &instance)
Definition: RealTimeHeightDeterministicDPDA.h:764
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1082
void addInputSymbols(ext::set< InputSymbolType > symbols)
Definition: RealTimeHeightDeterministicDPDA.h:392
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1072
bool removeFinalState(const StateType &state)
Definition: RealTimeHeightDeterministicDPDA.h:267
const ext::set< StateType > & getStates() const &
Definition: RealTimeHeightDeterministicDPDA.h:178
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicDPDA.h:227
void addPushdownStoreSymbols(ext::set< PushdownStoreSymbolType > symbols)
Definition: RealTimeHeightDeterministicDPDA.h:305
StateType && getInitialState() &&
Definition: RealTimeHeightDeterministicDPDA.h:158
bool removePushdownStoreSymbol(const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicDPDA.h:325
void removeInputSymbol(const InputSymbolType &symbol)
Definition: RealTimeHeightDeterministicDPDA.h:412
const PushdownStoreSymbolType & getBottomOfTheStackSymbol() const &
Definition: RealTimeHeightDeterministicDPDA.h:334
void setInputAlphabet(ext::set< InputSymbolType > symbols)
Definition: RealTimeHeightDeterministicDPDA.h:401
bool addFinalState(StateType state)
Definition: RealTimeHeightDeterministicDPDA.h:247
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: RealTimeHeightDeterministicDPDA.h:983
bool addInputSymbol(InputSymbolType symbol)
Definition: RealTimeHeightDeterministicDPDA.h:383
bool addCallTransition(StateType from, common::symbol_or_epsilon< InputSymbolType > input, StateType to, PushdownStoreSymbolType push)
Adds a call transition to the automaton.
Definition: RealTimeHeightDeterministicDPDA.h:788
bool addState(StateType state)
Definition: RealTimeHeightDeterministicDPDA.h:198
ext::set< InputSymbolType > && getInputAlphabet() &&
Definition: RealTimeHeightDeterministicDPDA.h:372
ext::set< StateType > && getStates() &&
Definition: RealTimeHeightDeterministicDPDA.h:187
bool setBottomOfTheStackSymbol(PushdownStoreSymbolType symbol)
Definition: RealTimeHeightDeterministicDPDA.h:354
Definition: symbol_or_epsilon.hpp:24
Definition: components.hpp:181
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicDPDA.h:1372
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicDPDA.h:1362
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicDPDA.h:1234
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicDPDA.h:1224
Definition: components.hpp:25
static bool used(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicDPDA.h:1318
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicDPDA.h:1330
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicDPDA.h:1340
static bool used(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const PushdownStoreSymbolType &symbol)
Definition: RealTimeHeightDeterministicDPDA.h:1169
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicDPDA.h:1202
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType &)
Definition: RealTimeHeightDeterministicDPDA.h:1192
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: RealTimeHeightDeterministicDPDA.h:1147
static bool used(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const InputSymbolType &symbol)
Definition: RealTimeHeightDeterministicDPDA.h:1113
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const InputSymbolType &)
Definition: RealTimeHeightDeterministicDPDA.h:1137
static bool used(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &automaton, const StateType &state)
Definition: RealTimeHeightDeterministicDPDA.h:1256
static bool available(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicDPDA.h:1286
static void valid(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &, const StateType &)
Definition: RealTimeHeightDeterministicDPDA.h:1296
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
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::RealTimeHeightDeterministicDPDA< > eval(automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &&value)
Definition: RealTimeHeightDeterministicDPDA.h:1383
Definition: normalize.hpp:13