Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
AutomataUnionMultipleInitialStates.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
27#include <automaton/TA/NFTA.h>
28
29namespace automaton {
30
31namespace transform {
32
39public:
48 template < class SymbolType, class StateType >
50
55 template < class SymbolType, class StateType >
57
62 template < class SymbolType, class StateType >
64
73 template < class SymbolType, class StateType >
75
76};
77
78template < class SymbolType, class StateType >
80 unsigned firstDefault = 1;
81 unsigned secondDefault = 2;
82
84
85 for(const auto& a : first.getInputAlphabet())
86 res.addInputSymbol(a);
87 for(const auto& a : second.getInputAlphabet())
88 res.addInputSymbol(a);
89
90 for ( const auto & q : first.getStates ( ) )
91 res.addState ( ext::make_pair ( q, firstDefault ) );
92 for ( const auto & q : second.getStates ( ) )
93 res.addState ( ext::make_pair ( q, secondDefault ) );
94
95 for(const auto& q : first.getFinalStates())
96 res.addFinalState ( ext::make_pair ( q, firstDefault ) );
97 for(const auto& q : second.getFinalStates())
98 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
99
100 res.addInitialState ( ext::make_pair ( first.getInitialState ( ), firstDefault ) );
101 res.addInitialState ( ext::make_pair ( second.getInitialState ( ), secondDefault ) );
102
103 for(const auto& t : first.getTransitions())
104 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
105
106 for(const auto& t : second.getTransitions())
107 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
108
109 return res;
110}
111
112template < class SymbolType, class StateType >
114 unsigned firstDefault = 1;
115 unsigned secondDefault = 2;
116
118
119 for(const auto& a : first.getInputAlphabet())
120 res.addInputSymbol(a);
121 for(const auto& a : second.getInputAlphabet())
122 res.addInputSymbol(a);
123
124 for ( const auto & q : first.getStates ( ) )
125 res.addState ( ext::make_pair ( q, firstDefault ) );
126 for ( const auto & q : second.getStates ( ) )
127 res.addState ( ext::make_pair ( q, secondDefault ) );
128
129 for(const auto& q : first.getFinalStates())
130 res.addFinalState ( ext::make_pair ( q, firstDefault ) );
131 for(const auto& q : second.getFinalStates())
132 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
133
134 res.addInitialState ( ext::make_pair ( first.getInitialState ( ), firstDefault ) );
135 res.addInitialState ( ext::make_pair ( second.getInitialState ( ), secondDefault ) );
136
137 for(const auto& t : first.getTransitions())
138 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
139
140 for(const auto& t : second.getTransitions())
141 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
142
143 return res;
144}
145
146template < class SymbolType, class StateType >
148 unsigned firstDefault = 1;
149 unsigned secondDefault = 2;
150
152
153 for(const auto& a : first.getInputAlphabet())
154 res.addInputSymbol(a);
155 for(const auto& a : second.getInputAlphabet())
156 res.addInputSymbol(a);
157
158 for ( const auto & q : first.getStates ( ) )
159 res.addState ( ext::make_pair ( q, firstDefault ) );
160 for ( const auto & q : second.getStates ( ) )
161 res.addState ( ext::make_pair ( q, secondDefault ) );
162
163 for(const auto& q : first.getFinalStates())
164 res.addFinalState ( ext::make_pair ( q, firstDefault ) );
165 for(const auto& q : second.getFinalStates())
166 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
167
168 res.addInitialState ( ext::make_pair ( first.getInitialState ( ), firstDefault ) );
169 res.addInitialState ( ext::make_pair ( second.getInitialState ( ), secondDefault ) );
170
171 for(const auto& t : first.getTransitions())
172 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
173
174 for(const auto& t : second.getTransitions())
175 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
176
177 return res;
178}
179
180template < class SymbolType, class StateType >
182 unsigned firstDefault = 1;
183 unsigned secondDefault = 2;
184
186
187 for(const auto& a : first.getInputAlphabet())
188 res.addInputSymbol(a);
189 for(const auto& a : second.getInputAlphabet())
190 res.addInputSymbol(a);
191
192 for ( const auto & q : first.getStates ( ) )
193 res.addState ( ext::make_pair ( q, firstDefault ) );
194 for ( const auto & q : second.getStates ( ) )
195 res.addState ( ext::make_pair ( q, secondDefault ) );
196
197 for(const auto& q : first.getFinalStates())
198 res.addFinalState ( ext::make_pair ( q, firstDefault ) );
199 for(const auto& q : second.getFinalStates())
200 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
201
202 for(const auto& t : first.getTransitions()) {
204 for ( const auto & state : t.first.second ) {
205 source.push_back ( ext::make_pair ( state, firstDefault ) );
206 }
207 res.addTransition ( t.first.first, std::move ( source ), ext::make_pair ( t.second, firstDefault ) );
208 }
209
210 for(const auto& t : second.getTransitions()) {
212 for ( const auto & state : t.first.second ) {
213 source.push_back ( ext::make_pair ( state, firstDefault ) );
214 }
215 res.addTransition ( t.first.first, std::move ( source ), ext::make_pair ( t.second, secondDefault ) );
216 }
217
218 return res;
219}
220
221} /* namespace transform */
222
223} /* namespace automaton */
224
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
const ext::set< StateType > & getFinalStates() const &
Definition: DFA.h:183
const ext::map< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: DFA.h:473
const StateType & getInitialState() const &
Definition: DFA.h:105
const ext::set< SymbolType > & getInputAlphabet() const &
Definition: DFA.h:232
const ext::set< StateType > & getStates() const &
Definition: DFA.h:134
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 automaton. Accepts regular languages.
Definition: MultiInitialStateEpsilonNFA.h:75
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
const ext::set< StateType > & getStates() const &
Definition: NFA.h:136
const StateType & getInitialState() const &
Definition: NFA.h:107
const ext::set< SymbolType > & getInputAlphabet() const &
Definition: NFA.h:234
const ext::multimap< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: NFA.h:484
const ext::set< StateType > & getFinalStates() const &
Definition: NFA.h:185
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
const ext::set< StateType > & getFinalStates() const &
Definition: NFTA.h:159
const ext::multimap< ext::pair< common::ranked_symbol< SymbolType >, ext::vector< StateType > >, StateType > & getTransitions() const &
Definition: NFTA.h:294
const ext::set< StateType > & getStates() const &
Definition: NFTA.h:110
const ext::set< common::ranked_symbol< SymbolType > > & getInputAlphabet() const &
Definition: NFTA.h:208
Definition: AutomataUnionMultipleInitialStates.h:38
static automaton::MultiInitialStateEpsilonNFA< SymbolType, ext::pair< StateType, unsigned > > unification(const automaton::EpsilonNFA< SymbolType, StateType > &first, const automaton::EpsilonNFA< SymbolType, StateType > &second)
Definition: AutomataUnionMultipleInitialStates.h:79
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
q
Definition: SingleInitialStateEpsilonTransition.h:85
return res
Definition: AutomataConcatenation.h:102
t first second
Definition: AutomataConcatenation.h:78
Definition: ToGrammar.h:31
ContainerType< ResType > transform(const ContainerType< InType, Ts ... > &in, Callback transform)
In container tranformation of all elements according to the tranform.
Definition: algorithm.hpp:150
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79