Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
AllEpsilonClosure.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
26#include <alib/set>
27#include <alib/map>
28#include <alib/deque>
29
34#include <automaton/FSM/NFA.h>
35#include <automaton/FSM/DFA.h>
36
39
41
42namespace automaton {
43
44namespace properties {
45
50public:
59 template < class T >
60 requires isEpsilonNFA < T > || isEpsilonNFTA < T >
62
73 template < class T >
74 requires isDFA < T > || isNFA < T > || isMultiInitialStateNFA < T >
76
88 template < class SymbolType, class StateType >
90
102 template < class SymbolType, class StateType >
104
105 template < class SymbolType, class StateType >
107};
108
109template < class T >
110requires isEpsilonNFA < T > || isEpsilonNFTA < T >
113
114 Qi.push_back ( { } );
115 for ( const typename T::StateType & state : fsm.getStates ( ) )
116 Qi.at ( 0 ) [ state ].insert ( state );
117
118 int i = 1;
119 while ( true ) {
120 Qi.push_back ( Qi.at ( i - 1 ) );
121
122 for ( const std::pair < const typename T::StateType, ext::set < typename T::StateType > > & p : Qi.at( i - 1 ) )
123 for ( const typename T::StateType & pclosure : p.second )
124 for ( const auto & transition : fsm.getEpsilonTransitionsFromState ( pclosure ) )
125 Qi.at ( i ) [ p.first ].insert ( transition.second );
126
127 if ( Qi.at ( i ) == Qi.at ( i - 1 ) )
128 break;
129
130 i = i + 1;
131 }
132
133 return Qi.at ( i );
134}
135
136template < class T >
137requires isDFA < T > || isNFA < T > || isMultiInitialStateNFA < T >
140 for ( const typename T::StateType & state : fsm.getStates ( ) )
141 closure [ state ].insert ( state );
142 return closure;
143}
144
145template < class SymbolType, class StateType >
149
150 for(const std::pair<const ext::pair<StateType, regexp::UnboundedRegExpStructure < SymbolType > >, StateType >& transition : fsm.getTransitions() )
152 step[transition.first.first].insert(transition.second);
153
154 for(const StateType& state : fsm.getStates())
155 step[state].insert(state);
156
157 do {
158 res = step;
159
160 for(const std::pair<const StateType, ext::set<StateType>>& item : res)
161 for(const StateType& to : item.second)
162 step[item.first].insert(res[to].begin(), res[to].end());
163 } while(res != step);
164
165 return res;
166}
167
168template < class SymbolType, class StateType >
172
173 for(const std::pair<const ext::pair<StateType, ext::vector < SymbolType > >, StateType >& transition : fsm.getTransitions() )
174 if( transition.first.second.empty ( ) )
175 step[transition.first.first].insert(transition.second);
176
177 for(const StateType& state : fsm.getStates())
178 step[state].insert(state);
179
180 do {
181 res = step;
182
183 for(const std::pair<const StateType, ext::set<StateType>>& item : res)
184 for(const StateType& to : item.second)
185 step[item.first].insert(res[to].begin(), res[to].end());
186 } while(res != step);
187
188 return res;
189}
190
191template < class SymbolType, class StateType >
195
197 if ( fsm.getStates ( ).contains ( transition.first.first ) && transition.first.second.empty ( ) )
198 step [ transition.first.first.template get < StateType > ( ) ].insert ( transition.second );
199
200 for(const StateType& state : fsm.getStates())
201 step[state].insert(state);
202
203 do {
204 res = step;
205
206 for(const std::pair<const StateType, ext::set<StateType>>& item : res)
207 for(const StateType& to : item.second)
208 step[item.first].insert(res[to].begin(), res[to].end());
209 } while(res != step);
210
211 return res;
212}
213
214} /* namespace properties */
215
216} /* namespace automaton */
217
Compact nondeterministic finite automaton. Accepts regular languages. The automaton has a list of sym...
Definition: CompactNFA.h:78
const ext::multimap< ext::pair< StateType, ext::vector< SymbolType > >, StateType > & getTransitions() const &
Definition: CompactNFA.h:555
const ext::set< StateType > & getStates() const &
Definition: CompactNFA.h:183
Extended nondeterministic finite automaton. Accepts regular languages. The automaton has a regular ex...
Definition: ExtendedNFA.h:80
const ext::multimap< ext::pair< StateType, regexp::UnboundedRegExpStructure< SymbolType > >, StateType > & getTransitions() const &
Definition: ExtendedNFA.h:581
const ext::set< StateType > & getStates() const &
Definition: ExtendedNFA.h:185
Nondeterministic Z-Automaton. Computation model for unranked regular tree languages.
Definition: NondeterministicZAutomaton.h:68
const ext::multimap< ext::pair< ext::variant< SymbolType, StateType >, ext::vector< ext::variant< SymbolType, StateType > > >, StateType > & getTransitions() const &
Definition: NondeterministicZAutomaton.h:283
const ext::set< StateType > & getStates() const &
Definition: NondeterministicZAutomaton.h:99
Definition: AllEpsilonClosure.h:49
static ext::map< typename T::StateType, ext::set< typename T::StateType > > allEpsilonClosure(const T &fsm)
static ext::map< typename T::StateType, ext::set< typename T::StateType > > allEpsilonClosure(const T &fsm)
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
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
Definition: set.hpp:44
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
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
static bool languageContainsEpsilon(const regexp::FormalRegExpElement< SymbolType > &regexp)
Definition: RegExpEpsilon.h:91
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
int i
Definition: AllEpsilonClosure.h:118
return closure
Definition: AllEpsilonClosure.h:142
ext::deque< ext::set< StateType > > Qi
Definition: ReachableStates.h:95
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void end()
Definition: measurements.cpp:19