Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
AutomataConcatenationEpsilonTransition.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
28namespace automaton {
29
30namespace transform {
31
38public:
47 template < class SymbolType, class StateType >
49
53 template < class SymbolType, class StateType >
55
59 template < class SymbolType, class StateType >
61};
62
63template < class SymbolType, class StateType >
65 unsigned firstDefault = 1;
66 unsigned secondDefault = 2;
67
69
70 res.addInputSymbols ( first.getInputAlphabet ( ) );
71 res.addInputSymbols ( second.getInputAlphabet ( ) );
72
73 for ( const StateType & q : first.getStates ( ) )
74 res.addState ( ext::make_pair ( q, firstDefault ) );
75 for ( const StateType & q : second.getStates ( ) )
76 res.addState ( ext::make_pair ( q, secondDefault ) );
77
78 for ( const StateType & q : second.getFinalStates ( ) )
79 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
80
81 for ( const auto & t : first.getTransitions ( ) )
82 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
83
84 for ( const auto & t : second.getTransitions ( ) )
85 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
86
87 for ( const StateType & q : first.getFinalStates ( ) )
88 res.addTransition ( ext::make_pair ( q, firstDefault ), ext::make_pair ( second.getInitialState ( ), secondDefault ) );
89
90 return res;
91}
92
93template < class SymbolType, class StateType >
95 unsigned firstDefault = 1;
96 unsigned secondDefault = 2;
97
99
100 res.addInputSymbols ( first.getInputAlphabet ( ) );
101 res.addInputSymbols ( second.getInputAlphabet ( ) );
102
103 for ( const StateType & q : first.getStates ( ) )
104 res.addState ( ext::make_pair ( q, firstDefault ) );
105 for ( const StateType & q : second.getStates ( ) )
106 res.addState ( ext::make_pair ( q, secondDefault ) );
107
108 for ( const StateType & q : second.getFinalStates ( ) )
109 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
110
111 for ( const auto & t : first.getTransitions ( ) )
112 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
113
114 for ( const auto & t : second.getTransitions ( ) )
115 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
116
117 for ( const StateType & q : first.getFinalStates ( ) )
118 res.addTransition ( ext::make_pair ( q, firstDefault ), ext::make_pair ( second.getInitialState ( ), secondDefault ) );
119
120 return res;
121}
122
123template < class SymbolType, class StateType >
125 unsigned firstDefault = 1;
126 unsigned secondDefault = 2;
127
129
130 res.addInputSymbols ( first.getInputAlphabet ( ) );
131 res.addInputSymbols ( second.getInputAlphabet ( ) );
132
133 for ( const StateType & q : first.getStates ( ) )
134 res.addState ( ext::make_pair ( q, firstDefault ) );
135 for ( const StateType & q : second.getStates ( ) )
136 res.addState ( ext::make_pair ( q, secondDefault ) );
137
138 for ( const StateType & q : second.getFinalStates ( ) )
139 res.addFinalState ( ext::make_pair ( q, secondDefault ) );
140
141 for ( const auto & t : first.getTransitions ( ) )
142 res.addTransition ( ext::make_pair ( t.first.first, firstDefault ), t.first.second, ext::make_pair ( t.second, firstDefault ) );
143
144 for ( const auto & t : second.getTransitions ( ) )
145 res.addTransition ( ext::make_pair ( t.first.first, secondDefault ), t.first.second, ext::make_pair ( t.second, secondDefault ) );
146
147 for ( const StateType & q : first.getFinalStates ( ) )
148 res.addTransition ( ext::make_pair ( q, firstDefault ), ext::make_pair ( second.getInitialState ( ), secondDefault ) );
149
150 return res;
151}
152
153} /* namespace transform */
154
155} /* namespace automaton */
156
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
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
Definition: AutomataConcatenationEpsilonTransition.h:37
static automaton::EpsilonNFA< SymbolType, ext::pair< StateType, unsigned > > concatenation(const automaton::DFA< SymbolType, StateType > &first, const automaton::DFA< SymbolType, StateType > &second)
Definition: AutomataConcatenationEpsilonTransition.h:64
q
Definition: SingleInitialStateEpsilonTransition.h:85
typename T::StateType StateType
Definition: Compaction.h:76
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