28#include <alib/multimap>
73template <
class SymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
74class EpsilonNFA final :
public core::Components < EpsilonNFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > {
130 return this->
template accessComponent < InitialState > ( ).get ( );
139 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
150 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
159 return this->
template accessComponent < States > ( ).get ( );
168 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
179 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
188 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
199 this->
template accessComponent < States > ( ).remove ( state );
208 return this->
template accessComponent < FinalStates > ( ).get ( );
217 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
228 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
237 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
248 this->
template accessComponent < FinalStates > ( ).remove ( state );
257 return this->
template accessComponent < InputAlphabet > ( ).get ( );
266 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
277 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
286 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
295 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
306 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
535 return out <<
"(EpsilonNFA"
536 <<
" states = " << instance.
getStates ( )
561template <
class SymbolType,
class StateType >
572template<
class SymbolType,
class StateType >
573EpsilonNFA < SymbolType, StateType >::EpsilonNFA (
ext::set < StateType > states,
ext::set < SymbolType > inputAlphabet,
StateType initialState,
ext::set < StateType > finalStates ) :
core::Components <
EpsilonNFA,
ext::set < SymbolType >, component::Set, InputAlphabet,
ext::set < StateType >, component::Set, std::tuple < States, FinalStates >,
StateType, component::Value, InitialState > ( std::move ( inputAlphabet ), std::move ( states ), std::move ( finalStates ), std::move ( initialState ) ) {
576template<
class SymbolType,
class StateType >
581template<
class SymbolType,
class StateType >
583 for (
const auto & transition : other.getTransitions ( ) )
586 for (
const auto & initialState : other.getInitialStates ( ) )
591template<
class SymbolType,
class StateType >
593 for (
const auto & transition : other.getTransitions ( ) )
597template<
class SymbolType,
class StateType >
599 for (
const auto & transition : other.getTransitions ( ) )
603template<
class SymbolType,
class StateType >
605 if ( ! getStates ( ).contains ( from ) )
608 if ( ! input.is_epsilon ( ) && !getInputAlphabet ( ).contains ( input.getSymbol ( ) ) )
611 if ( ! getStates ( ).contains ( to ) )
614 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input ) );
615 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input ) );
616 auto iter = std::lower_bound ( lower_bound, upper_bound, to, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
617 if ( iter != upper_bound && to >= iter->second )
621 transitions.insert ( iter,
std::make_pair ( std::move ( key ), std::move ( to ) ) );
625template<
class SymbolType,
class StateType >
629 return addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( to ) );
632template<
class SymbolType,
class StateType >
636 return addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( to ) );
639template<
class SymbolType,
class StateType >
641 auto upper_bound = transitions.upper_bound (
ext::tie ( from, input ) );
642 auto lower_bound = transitions.lower_bound (
ext::tie ( from, input ) );
643 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second == to; } );
644 if ( iter == upper_bound )
647 transitions.erase ( iter );
651template<
class SymbolType,
class StateType >
655 return addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( to ) );
658template<
class SymbolType,
class StateType >
662 return addTransition ( std::move ( from ), std::move ( inputVariant ), std::move ( to ) );
665template<
class SymbolType,
class StateType >
670template<
class SymbolType,
class StateType >
672 return std::move ( transitions );
675template<
class SymbolType,
class StateType >
680 if ( transition.first.second.is_epsilon ( ) )
681 result.insert ( transition.first.first, transition.second );
686template<
class SymbolType,
class StateType >
691 if ( ! transition.first.second.is_epsilon ( ) )
692 result.insert (
ext::make_pair ( transition.first.first, transition.first.second.getSymbol ( ) ), transition.second );
697template<
class SymbolType,
class StateType >
699 if ( ! getStates ( ).contains ( from ) )
705 if ( transition.first.first == from )
706 transitionsFromState.
insert ( transition );
708 return transitionsFromState;
711template<
class SymbolType,
class StateType >
713 if ( ! getStates ( ).contains ( from ) )
719 res.insert ( transition.first.first, transition.second );
724template<
class SymbolType,
class StateType >
726 if ( ! getStates ( ).contains ( from ) )
732 if ( ( transition.first.first == from ) && ! transition.first.second.is_epsilon ( ) )
735 return transitionsFromState;
738template<
class SymbolType,
class StateType >
740 if ( ! getStates ( ).contains ( to ) )
746 if ( transition.second == to )
747 transitionsToState.
insert ( transition );
749 return transitionsToState;
752template<
class SymbolType,
class StateType >
754 if ( ! getStates ( ).contains ( to ) )
760 if ( transition.second == to && transition.first.second.is_epsilon ( ) )
761 transitionsToState.
insert ( transition.first.first, to );
763 return transitionsToState;
766template<
class SymbolType,
class StateType >
768 if ( ! getStates ( ).contains ( to ) )
774 if ( transition.second == to && ! transition.first.second.is_epsilon ( ) )
777 return transitionsToState;
780template<
class SymbolType,
class StateType >
783 if ( transition.first.second.is_epsilon ( ) )
789template<
class SymbolType,
class StateType >
791 if ( transitions.empty ( ) )
794 for (
auto iter = transitions.begin ( ); std::next ( iter ) != transitions.end ( ); ++ iter )
795 if ( iter->first == std::next ( iter )->first )
798 return isEpsilonFree ( );
801template<
class SymbolType,
class StateType >
803 return isDeterministic ( ) && transitions.size ( ) == getInputAlphabet ( ).size ( ) * getStates ( ).size ( );
816template<
class SymbolType,
class StateType >
829 if ( ! transition.first.second.is_epsilon ( ) && ( transition.first.second.getSymbol ( ) == symbol ) )
863template<
class SymbolType,
class StateType >
875 if (
automaton.getInitialState ( ) == state )
878 if (
automaton.getFinalStates ( ).contains ( state ) )
882 if ( transition.first.first == state || transition.second == state )
916template<
class SymbolType,
class StateType >
940 return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state );
959template<
class SymbolType,
class StateType >
971 return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state );
989template<
class SymbolType,
class StateType >
1004 res.addTransition ( std::move ( from ), std::move ( input ), std::move ( target ) );
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
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 finite automaton. Accepts regular languages.
Definition: DFA.h:71
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
ext::set< SymbolType > && getInputAlphabet() &&
Definition: EpsilonNFA.h:265
const ext::set< StateType > & getStates() const &
Definition: EpsilonNFA.h:158
ext::multimap< StateType, StateType > getEpsilonTransitions() const
Definition: EpsilonNFA.h:676
bool isEpsilonFree() const
Determines whether the automaton is without epsilon transitions.
Definition: EpsilonNFA.h:781
void removeState(const StateType &state)
Definition: EpsilonNFA.h:198
StateType && getInitialState() &&
Definition: EpsilonNFA.h:138
bool addTransition(StateType from, common::symbol_or_epsilon< SymbolType > input, StateType to)
Add a transition to the automaton.
Definition: EpsilonNFA.h:604
SymbolTypeT SymbolType
Definition: EpsilonNFA.h:76
void addInputSymbols(ext::set< SymbolType > symbols)
Definition: EpsilonNFA.h:285
ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< SymbolType > >, StateType > getTransitionsFromState(const StateType &from) const
Definition: EpsilonNFA.h:698
bool addInputSymbol(SymbolType symbol)
Definition: EpsilonNFA.h:276
void setInputAlphabet(ext::set< SymbolType > symbols)
Definition: EpsilonNFA.h:294
EpsilonNFA(StateType initialState)
Creates a new instance of the automaton with a concrete initial state.
Definition: EpsilonNFA.h:577
ext::set< StateType > && getStates() &&
Definition: EpsilonNFA.h:167
bool setInitialState(StateType state)
Definition: EpsilonNFA.h:149
void removeInputSymbol(const SymbolType &symbol)
Definition: EpsilonNFA.h:305
bool isDeterministic() const
Determines whether the automaton is deterministic.
Definition: EpsilonNFA.h:790
ext::set< StateType > && getFinalStates() &&
Definition: EpsilonNFA.h:216
ext::multimap< StateType, StateType > getEpsilonTransitionsFromState(const StateType &from) const
Definition: EpsilonNFA.h:712
ext::multimap< StateType, StateType > getEpsilonTransitionsToState(const StateType &to) const
Definition: EpsilonNFA.h:753
bool removeTransition(StateType from, common::symbol_or_epsilon< SymbolType > input, StateType to)
Removes a transition to the automaton.
Definition: EpsilonNFA.h:640
const ext::set< StateType > & getFinalStates() const &
Definition: EpsilonNFA.h:207
const ext::set< SymbolType > & getInputAlphabet() const &
Definition: EpsilonNFA.h:256
ext::multimap< ext::pair< StateType, SymbolType >, StateType > getSymbolTransitions() const
Definition: EpsilonNFA.h:687
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< SymbolType > >, StateType > & getTransitions() const &
Definition: EpsilonNFA.h:666
void removeFinalState(const StateType &state)
Definition: EpsilonNFA.h:247
void setFinalStates(ext::set< StateType > states)
Definition: EpsilonNFA.h:236
ext::multimap< ext::pair< StateType, SymbolType >, StateType > getSymbolTransitionsToState(const StateType &to) const
Definition: EpsilonNFA.h:767
StateTypeT StateType
Definition: EpsilonNFA.h:77
ext::multimap< ext::pair< StateType, SymbolType >, StateType > getSymbolTransitionsFromState(const StateType &from) const
Definition: EpsilonNFA.h:725
bool isTotal() const
Determines whether the automaton is total deterministic.
Definition: EpsilonNFA.h:802
const StateType & getInitialState() const &
Definition: EpsilonNFA.h:129
void setStates(ext::set< StateType > states)
Definition: EpsilonNFA.h:187
friend ext::ostream & operator<<(ext::ostream &out, const EpsilonNFA &instance)
Definition: EpsilonNFA.h:534
bool addFinalState(StateType state)
Definition: EpsilonNFA.h:227
ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< SymbolType > >, StateType > getTransitionsToState(const StateType &to) const
Definition: EpsilonNFA.h:739
bool addState(StateType state)
Definition: EpsilonNFA.h:178
bool operator==(const EpsilonNFA &other) const
Definition: EpsilonNFA.h:522
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Definition: EpsilonNFA.h:551
Definition: symbol_or_epsilon.hpp:24
Definition: components.hpp:181
static bool available(const automaton::EpsilonNFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: EpsilonNFA.h:970
static void valid(const automaton::EpsilonNFA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFA.h:980
Definition: components.hpp:25
static bool available(const automaton::EpsilonNFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: EpsilonNFA.h:939
static void valid(const automaton::EpsilonNFA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFA.h:949
static bool used(const automaton::EpsilonNFA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFA.h:927
static bool used(const automaton::EpsilonNFA< SymbolType, StateType > &automaton, const SymbolType &symbol)
Definition: EpsilonNFA.h:827
static bool available(const automaton::EpsilonNFA< SymbolType, StateType > &, const SymbolType &)
Definition: EpsilonNFA.h:843
static void valid(const automaton::EpsilonNFA< SymbolType, StateType > &, const SymbolType &)
Definition: EpsilonNFA.h:853
static bool available(const automaton::EpsilonNFA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFA.h:896
static bool used(const automaton::EpsilonNFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: EpsilonNFA.h:874
static void valid(const automaton::EpsilonNFA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFA.h:906
Definition: setComponents.hpp:26
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.hpp:48
iterator insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: multimap.hpp:118
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Definition: BarSymbol.cpp:12
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
Definition: ToGrammar.h:31
constexpr bool isEpsilonNFA
Definition: EpsilonNFA.h:570
Definition: Permutation.hpp:18
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T ¶m)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static automaton::EpsilonNFA< > eval(automaton::EpsilonNFA< SymbolType, StateType > &&value)
Definition: EpsilonNFA.h:991
Definition: normalize.hpp:13