Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
EpsilonRemoverIncoming.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <map>
9#include <algorithm>
10
13#include <automaton/FSM/NFA.h>
14#include <automaton/FSM/DFA.h>
15
16#include "../../properties/efficient/AllEpsilonClosure.h"
17
18namespace automaton {
19
20namespace simplify {
21
22namespace efficient {
23
25public:
29 template < class SymbolType, class StateType >
31 template < class SymbolType, class StateType >
33 template < class SymbolType, class StateType >
35 template < class SymbolType, class StateType >
37};
38
39template < class SymbolType, class StateType >
41 return fsm;
42}
43
44template < class SymbolType, class StateType >
46 return fsm;
47}
48
49template < class SymbolType, class StateType >
51 return fsm;
52}
53
54template < class SymbolType, class StateType >
57
58 res.setStates ( fsm.getStates ( ) );
59 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
60
62
64
68 for ( const auto & from : fsm.getStates ( ) )
69 for ( const auto & fromClosure : closures [ from ] )
70 for ( const auto & symbol : fsm.getInputAlphabet ( ) ) {
71 auto transitions = origTransitions.equal_range ( ext::make_pair ( fromClosure, symbol ) );
72
73 for ( const auto & transition : transitions )
74 res.addTransition( from, symbol, transition.second );
75 }
76
80 const ext::set < StateType > & F = fsm.getFinalStates ( );
81 for ( const auto & q : res.getStates ( ) ) {
82 const ext::set < StateType > & cl = closures [ q ];
83
84 if ( ! ext::excludes ( F.begin ( ), F.end ( ), cl.begin ( ), cl.end ( ) ) )
85 res.addFinalState ( q );
86 }
87
88 return res;
89}
90
91} /* namespace efficient */
92
93} /* namespace simplify */
94
95} /* namespace automaton */
96
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
const ext::set< StateType > & getStates() const &
Definition: EpsilonNFA.h:158
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 StateType & getInitialState() const &
Definition: EpsilonNFA.h:129
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
static ext::map< StateType, ext::set< StateType > > allEpsilonClosure(const automaton::EpsilonNFA< SymbolType, StateType > &fsm)
Definition: AllEpsilonClosure.h:61
Definition: EpsilonRemoverIncoming.h:24
static automaton::NFA< SymbolType, StateType > remove(const automaton::EpsilonNFA< SymbolType, StateType > &fsm)
Definition: EpsilonRemoverIncoming.h:55
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.hpp:48
auto equal_range(K &&key) const &
Make range of elements with key equal to the key.
Definition: multimap.hpp:268
Definition: set.hpp:44
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
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
q
Definition: SingleInitialStateEpsilonTransition.h:85
Definition: ToGrammar.h:31
bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp)
Tests two sorted ranges wheter all elements from the second are not present in the first.
Definition: algorithm.hpp:46
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79