28#include <alib/multimap>
72template <
class SymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
73class EpsilonNFTA final :
public core::Components < EpsilonNFTA < SymbolTypeT, StateTypeT >, ext::set < common::ranked_symbol < SymbolTypeT > >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates > > {
119 return this->
template accessComponent < States > ( ).get ( );
128 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
139 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
148 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
159 this->
template accessComponent < States > ( ).remove ( state );
168 return this->
template accessComponent < FinalStates > ( ).get ( );
177 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
188 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
197 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
208 this->
template accessComponent < FinalStates > ( ).remove ( state );
217 return this->
template accessComponent < InputAlphabet > ( ).get ( );
226 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
237 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
246 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
255 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
266 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
364 return std::move ( transitions );
388 if ( transition.second ==
q )
389 res.insert ( transition );
403 if ( std::find ( source.second.begin ( ), source.second.end ( ),
q ) != source.second.end ( ) ) {
404 res.insert ( transition );
407 if ( transition.first.template is < StateType > ( ) ) {
408 const StateType & source = transition.first.template get < StateType > ( );
410 res.insert ( transition );
484 return out <<
"(EpsilonNFTA "
485 <<
" states = " << instance.
getStates ( )
509template <
class SymbolType,
class StateType >
520template <
class SymbolType,
class StateType >
521EpsilonNFTA < SymbolType, StateType >::EpsilonNFTA (
ext::set < StateType > states,
ext::set < common::ranked_symbol < SymbolType > > inputAlphabet,
ext::set < StateType > finalStates ) :
core::Components <
EpsilonNFTA,
ext::set <
common::ranked_symbol < SymbolType > >, component::Set, InputAlphabet,
ext::set < StateType >, component::Set, std::tuple < States, FinalStates > > ( std::move ( inputAlphabet ), std::move ( states ), std::move ( finalStates ) ) {
524template <
class SymbolType,
class StateType >
528template <
class SymbolType,
class StateType >
530 transitions.insert ( other.getTransitions ( ).begin ( ), other.getTransitions ( ).end ( ) );
533template <
class SymbolType,
class StateType >
535 transitions.insert ( other.getTransitions ( ).begin ( ), other.getTransitions ( ).end ( ) );
538template <
class SymbolType,
class StateType >
540 if ( lhs.template is < StateType > ( ) ) {
541 const StateType & source = lhs.template get < StateType > ( );
542 if ( ! getStates().
contains ( source ) )
546 if ( source.second.size ( ) != source.first.getRank ( ) )
549 if ( ! getInputAlphabet ( ).contains ( source.first ) )
552 for (
const StateType & it : source.second ) {
553 if ( ! getStates ( ).contains ( it ) )
558 if ( ! getStates().contains ( rhs ) )
561 auto upper_bound = transitions.upper_bound ( lhs );
562 auto lower_bound = transitions.lower_bound ( lhs );
563 auto iter = std::lower_bound ( lower_bound, upper_bound, rhs, [ ] (
const auto & transition,
const auto & target ) {
return transition.second < target; } );
564 if ( iter != upper_bound && rhs >= iter->second )
567 transitions.insert ( iter,
std::make_pair ( std::move ( lhs ), std::move ( rhs ) ) );
571template <
class SymbolType,
class StateType >
576template <
class SymbolType,
class StateType >
581template <
class SymbolType,
class StateType >
583 auto upper_bound = transitions.upper_bound ( lhs );
584 auto lower_bound = transitions.lower_bound ( lhs );
585 auto iter = std::find_if ( lower_bound, upper_bound, [ & ] (
const auto & transition ) {
return transition.second == rhs; } );
586 if ( iter == upper_bound )
589 transitions.erase ( iter );
593template <
class SymbolType,
class StateType >
598template <
class SymbolType,
class StateType >
603template<
class SymbolType,
class StateType >
608 if ( transition.first.template is < StateType > ( ) )
609 result.insert ( transition.first.template get < StateType > ( ), transition.second );
614template<
class SymbolType,
class StateType >
621 result.insert ( source, transition.second );
628template<
class SymbolType,
class StateType >
630 if ( !getStates ( ).contains ( from ) )
634 for (
const auto & transition : transitions.equal_range ( from ) )
635 res.insert ( from, transition.second );
640template<
class SymbolType,
class StateType >
642 if ( !getStates ( ).contains ( to ) )
646 for (
const auto & transition : transitions )
647 if ( transition.second == to && transition.first.template is < StateType > ( ) )
648 res.insert ( transition.first.template get < StateType > ( ), to );
653template<
class SymbolType,
class StateType >
656 if ( transition.first.template is < StateType > ( ) )
662template <
class SymbolType,
class StateType >
664 if ( transitions.empty ( ) )
667 for (
auto iter = transitions.begin ( ); std::next ( iter ) != transitions.end ( ); ++ iter )
668 if ( iter->first == std::next ( iter )->first )
671 return isEpsilonFree ( );
684template <
class SymbolType,
class StateType >
699 if ( source.first == symbol)
734template <
class SymbolType,
class StateType >
746 if (
automaton.getFinalStates ( ).contains ( state ) )
752 if (
ext::contains ( source.second.begin ( ), source.second.end ( ), state ) ) {
756 if ( t.first.template is < StateType > ( ) ) {
757 if ( t.first.template get < StateType > ( ) == state ) {
761 if ( t .
second == state ) {
797template <
class SymbolType,
class StateType >
821 return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state );
839template <
class SymbolType,
class StateType >
850 if ( transition.first.template is < StateType > ( ) ) {
852 res.addTransition ( from, to );
859 res.addTransition ( std::move ( input ), std::move ( from ), std::move ( to ) );
static common::ranked_symbol< DefaultSymbolType > normalizeRankedSymbol(common::ranked_symbol< SymbolType > &&symbol)
Definition: SymbolNormalize.h:81
static ext::set< common::ranked_symbol< DefaultSymbolType > > normalizeRankedAlphabet(ext::set< common::ranked_symbol< SymbolType > > &&symbols)
Definition: SymbolNormalize.h:59
Definition: AutomatonException.h:15
static DefaultStateType normalizeState(StateType &&state)
Definition: AutomatonNormalize.h:76
static ext::multiset< DefaultStateType > normalizeStates(ext::multiset< StateType > &&states)
Definition: AutomatonNormalize.h:49
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: DFTA.h:74
Epsilon nondeterministic finite tree automaton. Accepts regular tree languages.
Definition: EpsilonNFTA.h:73
ext::multimap< ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > >, StateType > getSymbolTransitions() const
Definition: EpsilonNFTA.h:615
ext::multimap< ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > >, StateType > && getTransitions() &&
Definition: EpsilonNFTA.h:363
StateTypeT StateType
Definition: EpsilonNFTA.h:76
friend ext::ostream & operator<<(ext::ostream &out, const EpsilonNFTA &instance)
Definition: EpsilonNFTA.h:483
void removeInputSymbol(const common::ranked_symbol< SymbolType > &symbol)
Definition: EpsilonNFTA.h:265
ext::multimap< StateType, StateType > getEpsilonTransitions() const
Definition: EpsilonNFTA.h:604
void removeState(const StateType &state)
Definition: EpsilonNFTA.h:158
bool addState(StateType state)
Definition: EpsilonNFTA.h:138
bool operator==(const EpsilonNFTA &other) const
Definition: EpsilonNFTA.h:471
ext::multimap< ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > >, StateType > getTransitionsFromState(const StateType &q) const
Definition: EpsilonNFTA.h:397
bool isEpsilonFree() const
Determines whether the automaton is without epsilon transitions.
Definition: EpsilonNFTA.h:654
void addInputSymbols(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: EpsilonNFTA.h:245
const ext::set< StateType > & getFinalStates() const &
Definition: EpsilonNFTA.h:167
void removeFinalState(const StateType &state)
Definition: EpsilonNFTA.h:207
SymbolTypeT SymbolType
Definition: EpsilonNFTA.h:75
const ext::set< StateType > & getStates() const &
Definition: EpsilonNFTA.h:118
void setStates(ext::set< StateType > states)
Definition: EpsilonNFTA.h:147
auto operator<=>(const EpsilonNFTA &other) const
Definition: EpsilonNFTA.h:460
void setFinalStates(ext::set< StateType > states)
Definition: EpsilonNFTA.h:196
bool addTransition(ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > > lhs, StateType rhs)
Add a transition to the automaton.
Definition: EpsilonNFTA.h:539
bool removeTransition(const ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > > &lhs, const StateType &rhs)
Removes a transition from the automaton.
Definition: EpsilonNFTA.h:582
bool isDeterministic() const
Determines whether the automaton is deterministic.
Definition: EpsilonNFTA.h:663
const ext::multimap< ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > >, StateType > & getTransitions() const &
Definition: EpsilonNFTA.h:354
ext::multimap< StateType, StateType > getEpsilonTransitionsFromState(const StateType &from) const
Definition: EpsilonNFTA.h:629
EpsilonNFTA()
Creates a new instance of the automaton.
Definition: EpsilonNFTA.h:525
ext::set< StateType > && getStates() &&
Definition: EpsilonNFTA.h:127
bool addFinalState(StateType state)
Definition: EpsilonNFTA.h:187
const ext::set< common::ranked_symbol< SymbolType > > & getInputAlphabet() const &
Definition: EpsilonNFTA.h:216
void setInputAlphabet(ext::set< common::ranked_symbol< SymbolType > > symbols)
Definition: EpsilonNFTA.h:254
ext::set< StateType > && getFinalStates() &&
Definition: EpsilonNFTA.h:176
ext::multimap< ext::variant< StateType, ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > > >, StateType > getTransitionsToState(const StateType &q) const
Definition: EpsilonNFTA.h:384
bool addInputSymbol(common::ranked_symbol< SymbolType > symbol)
Definition: EpsilonNFTA.h:236
ext::set< common::ranked_symbol< SymbolType > > && getInputAlphabet() &&
Definition: EpsilonNFTA.h:225
ext::multimap< StateType, StateType > getEpsilonTransitionsToState(const StateType &to) const
Definition: EpsilonNFTA.h:641
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
Definition: EpsilonNFTA.h:499
Definition: ranked_symbol.hpp:20
Definition: components.hpp:181
static void valid(const automaton::EpsilonNFTA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFTA.h:787
static bool available(const automaton::EpsilonNFTA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFTA.h:777
static bool used(const automaton::EpsilonNFTA< SymbolType, StateType > &automaton, const StateType &state)
Definition: EpsilonNFTA.h:745
static bool used(const automaton::EpsilonNFTA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFTA.h:808
static bool available(const automaton::EpsilonNFTA< SymbolType, StateType > &automaton, const StateType &state)
Definition: EpsilonNFTA.h:820
static void valid(const automaton::EpsilonNFTA< SymbolType, StateType > &, const StateType &)
Definition: EpsilonNFTA.h:830
static bool available(const automaton::EpsilonNFTA< SymbolType, StateType > &, const common::ranked_symbol< SymbolType > &)
Definition: EpsilonNFTA.h:714
static bool used(const automaton::EpsilonNFTA< SymbolType, StateType > &automaton, const common::ranked_symbol< SymbolType > &symbol)
Definition: EpsilonNFTA.h:695
static void valid(const automaton::EpsilonNFTA< SymbolType, StateType > &, const common::ranked_symbol< SymbolType > &)
Definition: EpsilonNFTA.h:724
Definition: setComponents.hpp:26
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Implementation of the variant class allowing to store any type of those listed in the template parame...
Definition: variant.hpp:98
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Definition: BarSymbol.cpp:12
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
p second
Definition: ToRegExpAlgebraic.h:126
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
q
Definition: SingleInitialStateEpsilonTransition.h:85
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 isEpsilonNFTA
Definition: EpsilonNFTA.h:518
Definition: normalize.hpp:10
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
bool contains(InputIt first, InputIt last, const Element &elem)
Linear version of search in a range of values.
Definition: algorithm.hpp:170
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::EpsilonNFTA< > eval(automaton::EpsilonNFTA< SymbolType, StateType > &&value)
Definition: EpsilonNFTA.h:841
Definition: normalize.hpp:13