31#include <ext/algorithm>
72template <
class SymbolTypeT = DefaultSymbolType,
class StateTypeT = DefaultStateType >
73class CompactDFA final :
public core::Components < CompactDFA < SymbolTypeT, StateTypeT >, ext::set < SymbolTypeT >, component::Set, InputAlphabet, ext::set < StateTypeT >, component::Set, std::tuple < States, FinalStates >, StateTypeT, component::Value, InitialState > {
115 return this->
template accessComponent < InitialState > ( ).get ( );
124 return std::move ( this->
template accessComponent < InitialState > ( ).
get ( ) );
135 return this->
template accessComponent < InitialState > ( ).set ( std::move ( state ) );
144 return this->
template accessComponent < States > ( ).get ( );
153 return std::move ( this->
template accessComponent < States > ( ).
get ( ) );
164 return this->
template accessComponent < States > ( ).add ( std::move ( state ) );
173 this->
template accessComponent < States > ( ).set ( std::move ( states ) );
184 this->
template accessComponent < States > ( ).remove ( state );
193 return this->
template accessComponent < FinalStates > ( ).get ( );
202 return std::move ( this->
template accessComponent < FinalStates > ( ).
get ( ) );
213 return this->
template accessComponent < FinalStates > ( ).add ( std::move ( state ) );
222 this->
template accessComponent < FinalStates > ( ).set ( std::move ( states ) );
233 this->
template accessComponent < FinalStates > ( ).remove ( state );
242 return this->
template accessComponent < InputAlphabet > ( ).get ( );
251 return std::move ( this->
template accessComponent < InputAlphabet > ( ).
get ( ) );
262 return this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) );
271 this->
template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) );
280 this->
template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) );
291 this->
template accessComponent < InputAlphabet > ( ).remove ( symbol );
385 return out <<
"(CompactDFA"
386 <<
" states = " << instance.
getStates ( )
411template <
class SymbolType,
class StateType >
422template <
class SymbolType,
class StateType >
423CompactDFA < SymbolType, StateType >::CompactDFA (
ext::set < StateType > states,
ext::set < SymbolType > inputAlphabet,
StateType initialState,
ext::set < StateType > finalStates ) :
core::Components <
CompactDFA,
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 ) ) {
426template <
class SymbolType,
class StateType >
430template <
class SymbolType,
class StateType >
432 for (
const auto & transition : other.getTransitions ( ) )
436template <
class SymbolType,
class StateType >
438 if ( ! getStates ( ).contains ( from ) )
444 if ( ! std::includes ( getInputAlphabet ( ).
begin ( ), getInputAlphabet ( ).
end ( ), inputStringAlphabet.
begin ( ), inputStringAlphabet.
end ( ) ) )
445 throw AutomatonException (
"Input string is over different alphabet than automaton" );
447 if ( ! getStates ( ).
contains ( to ) )
451 if ( transitions.find ( key ) != transitions.end ( ) )
454 auto transitionsFromState = getTransitionsFromState ( key.first );
455 if ( key.second.empty ( ) && ! transitionsFromState.empty ( ) )
459 if ( transition.first.second.empty ( ) || transition.first.second [ 0 ] == key.second [ 0 ] )
462 transitions.insert ( std::move ( key ), std::move ( to ) );
466template <
class SymbolType,
class StateType >
470 auto iter = transitions.find ( key );
472 if ( iter == transitions.end ( ) )
475 if ( iter->second != to )
478 transitions.erase ( iter );
482template <
class SymbolType,
class StateType >
487template <
class SymbolType,
class StateType >
489 return std::move ( transitions );
492template<
class SymbolType,
class StateType >
494 if ( ! getStates ( ).contains ( from ) )
503template <
class SymbolType,
class StateType >
505 if ( ! getStates ( ).contains ( to ) )
511 if ( transition.second == to )
512 transitionsToState.
insert ( transition );
514 return transitionsToState;
527template <
class SymbolType,
class StateType >
576template <
class SymbolType,
class StateType >
588 if (
automaton.getInitialState ( ) == state )
591 if (
automaton.getFinalStates ( ).contains ( state ) )
595 if ( ( t.first.first == state ) || t.second == state )
629template <
class SymbolType,
class StateType >
653 return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state );
672template <
class SymbolType,
class StateType >
684 return automaton.template accessComponent < automaton::States > ( ).get ( ).contains ( state );
702template <
class SymbolType,
class StateType >
717 res.addTransition ( std::move ( from ), std::move ( input ), target );
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static ext::vector< DefaultSymbolType > normalizeSymbols(ext::vector< SymbolType > &&symbols)
Definition: SymbolNormalize.h:86
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
Compact deterministic finite automaton. Accepts regular languages. The automaton has a list of symbol...
Definition: CompactDFA.h:73
void addInputSymbols(ext::set< SymbolType > symbols)
Definition: CompactDFA.h:270
SymbolTypeT SymbolType
Definition: CompactDFA.h:75
StateType && getInitialState() &&
Definition: CompactDFA.h:123
CompactDFA(StateType initialState)
Creates a new instance of the automaton with a concrete initial state.
Definition: CompactDFA.h:427
const ext::map< ext::pair< StateType, ext::vector< SymbolType > >, StateType > & getTransitions() const &
Definition: CompactDFA.h:483
ext::set< SymbolType > && getInputAlphabet() &&
Definition: CompactDFA.h:250
bool addFinalState(StateType state)
Definition: CompactDFA.h:212
ext::set< StateType > && getStates() &&
Definition: CompactDFA.h:152
ext::map< ext::pair< StateType, ext::vector< SymbolType > >, StateType > getTransitionsToState(const StateType &to) const
Definition: CompactDFA.h:504
bool addState(StateType state)
Definition: CompactDFA.h:163
void setFinalStates(ext::set< StateType > states)
Definition: CompactDFA.h:221
bool operator==(const CompactDFA &other) const
Definition: CompactDFA.h:372
bool setInitialState(StateType state)
Definition: CompactDFA.h:134
const ext::set< StateType > & getFinalStates() const &
Definition: CompactDFA.h:192
bool removeTransition(const StateType &from, const ext::vector< SymbolType > &input, const StateType &to)
Removes a transition from the automaton.
Definition: CompactDFA.h:467
friend ext::ostream & operator<<(ext::ostream &out, const CompactDFA &instance)
Definition: CompactDFA.h:384
const StateType & getInitialState() const &
Definition: CompactDFA.h:114
const ext::set< StateType > & getStates() const &
Definition: CompactDFA.h:143
bool addTransition(StateType from, ext::vector< SymbolType > input, StateType to)
Add a transition to the automaton.
Definition: CompactDFA.h:437
bool addInputSymbol(SymbolType symbol)
Definition: CompactDFA.h:261
void removeFinalState(const StateType &state)
Definition: CompactDFA.h:232
void setInputAlphabet(ext::set< SymbolType > symbols)
Definition: CompactDFA.h:279
void removeInputSymbol(const SymbolType &symbol)
Definition: CompactDFA.h:290
StateTypeT StateType
Definition: CompactDFA.h:76
ext::iterator_range< typename ext::map< ext::pair< StateType, ext::vector< SymbolType > >, StateType >::const_iterator > getTransitionsFromState(const StateType &from) const
Definition: CompactDFA.h:493
void setStates(ext::set< StateType > states)
Definition: CompactDFA.h:172
ext::set< StateType > && getFinalStates() &&
Definition: CompactDFA.h:201
const ext::set< SymbolType > & getInputAlphabet() const &
Definition: CompactDFA.h:241
void removeState(const StateType &state)
Definition: CompactDFA.h:183
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Definition: CompactDFA.h:401
Definition: components.hpp:181
static void valid(const automaton::CompactDFA< SymbolType, StateType > &, const StateType &)
Definition: CompactDFA.h:693
static bool available(const automaton::CompactDFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: CompactDFA.h:683
Definition: components.hpp:25
static bool available(const automaton::CompactDFA< SymbolType, StateType > &, const SymbolType &)
Definition: CompactDFA.h:556
static bool used(const automaton::CompactDFA< SymbolType, StateType > &automaton, const SymbolType &symbol)
Definition: CompactDFA.h:538
static void valid(const automaton::CompactDFA< SymbolType, StateType > &, const SymbolType &)
Definition: CompactDFA.h:566
static bool used(const automaton::CompactDFA< SymbolType, StateType > &, const StateType &)
Definition: CompactDFA.h:640
static void valid(const automaton::CompactDFA< SymbolType, StateType > &, const StateType &)
Definition: CompactDFA.h:662
static bool available(const automaton::CompactDFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: CompactDFA.h:652
static void valid(const automaton::CompactDFA< SymbolType, StateType > &, const StateType &)
Definition: CompactDFA.h:619
static bool available(const automaton::CompactDFA< SymbolType, StateType > &, const StateType &)
Definition: CompactDFA.h:609
static bool used(const automaton::CompactDFA< SymbolType, StateType > &automaton, const StateType &state)
Definition: CompactDFA.h:587
Definition: setComponents.hpp:26
Implementation of iterator_range, i.e. pair of iterators. The class provides most notably begin and e...
Definition: range.hpp:24
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
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
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
constexpr bool isCompactDFA
Definition: CompactDFA.h:420
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
SliceComp< Ts ... > slice_comp(const Ts &... inst)
Definition: functional.hpp:95
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
iterator_range< Iter > make_iterator_range(Iter begin, Iter end)
Helper to create iterator_range from two iterators.
Definition: range.hpp:235
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void end()
Definition: measurements.cpp:19
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static automaton::CompactDFA< > eval(automaton::CompactDFA< SymbolType, StateType > &&value)
Definition: CompactDFA.h:704
Definition: normalize.hpp:13