Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
EpsilonRemoverOutgoing.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
28#include <automaton/FSM/NFA.h>
29#include <automaton/FSM/DFA.h>
30
32
33#include <global/GlobalData.h>
34
35namespace automaton {
36
37namespace simplify {
38
46public:
55 template < class StateType, class SymbolType >
57
66 template < class StateType, class SymbolType >
68
72 template < class StateType, class SymbolType >
74
78 template < class StateType, class SymbolType >
80
84 template < class StateType, class SymbolType >
86};
87
88template < class StateType, class SymbolType >
90 return fsm;
91}
92
93template < class StateType, class SymbolType >
95 return fsm;
96}
97
98template < class StateType, class SymbolType >
100 return fsm;
101}
102
103template < class StateType, class SymbolType >
106 res.setStates( fsm.getStates() );
107 res.setFinalStates( fsm.getFinalStates() );
108 res.setInputAlphabet( fsm.getInputAlphabet() );
109
113 for( const auto & middle : fsm.getStates( ) ) {
115
117 common::Streams::err << "E-clos(" << middle << ") -> " << middleClosure << std::endl;
118 }
119
120 for( const auto & symbol : fsm.getInputAlphabet() ) {
121 for( const auto& transition : fsm.getTransitions( ) ) {
122 if(transition.second != middle ) continue;
123 if(transition.first.second != symbol) continue;
124
125 for( const auto & to : middleClosure )
126 res.addTransition(transition.first.first, symbol, to );
127 }
128 }
129 }
130
135 res.setInitialStates( cl );
136
137 return res;
138}
139
140template < class StateType, class SymbolType >
143 res.setStates ( fta.getStates ( ) );
144 res.setFinalStates ( fta.getFinalStates ( ) );
145 res.setInputAlphabet ( fta.getInputAlphabet ( ) );
146
148
152 for( const auto & middle : fta.getStates ( ) ) {
154
156 common::Streams::err << "E-clos(" << middle << ") -> " << middleClosure << std::endl;
157 }
158
159 for ( const auto & symbol : fta.getInputAlphabet ( ) ) {
160 for ( const std::pair < const ext::pair < common::ranked_symbol < SymbolType >, ext::vector < StateType > >, StateType > & transition : symbolTransitions ) {
161 if ( transition.second != middle ) continue;
162 if ( transition.first.first != symbol ) continue;
163
164 for ( const auto & to : middleClosure )
165 res.addTransition ( symbol, transition.first.second, to );
166 }
167 }
168 }
169
170 return res;
171}
172
173} /* namespace simplify */
174
175} /* namespace automaton */
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
const ext::multimap< ext::pair< StateType, common::symbol_or_epsilon< SymbolType > >, StateType > & getTransitions() const &
Definition: EpsilonNFA.h:666
const StateType & getInitialState() const &
Definition: EpsilonNFA.h:129
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
const ext::set< StateType > & getFinalStates() const &
Definition: EpsilonNFTA.h:167
const ext::set< StateType > & getStates() const &
Definition: EpsilonNFTA.h:118
const ext::set< common::ranked_symbol< SymbolType > > & getInputAlphabet() const &
Definition: EpsilonNFTA.h:216
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
static ext::set< StateType > epsilonClosure(const automaton::EpsilonNFA< SymbolType, StateType > &fsm, const StateType &q)
Definition: EpsilonClosure.h:125
Definition: EpsilonRemoverOutgoing.h:45
static automaton::MultiInitialStateNFA< SymbolType, StateType > remove(const automaton::EpsilonNFA< SymbolType, StateType > &fsm)
Definition: EpsilonRemoverOutgoing.h:104
static bool verbose
Verbose flag. Some algorithms print additional runtime information about internal datastructures or t...
Definition: GlobalData.h:24
static ext::reference_wrapper< ext::ostream > err
Standard error stream. Mapped to descriptor 2.
Definition: GlobalData.h:72
Definition: ranked_symbol.hpp:20
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
Definition: set.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31