Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
AutomatonIteration.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:
46 template < class Automaton >
47 requires isDFA < Automaton > || isNFA < Automaton >
49};
50
51template < class Automaton >
52requires isDFA < Automaton > || isNFA < Automaton >
55
58
59 for(const auto& t : automaton.getTransitionsFromState(automaton.getInitialState())) {
60 res.addTransition(newInitialState, t.first.second, t.second);
61 if (automaton.getFinalStates().contains(t.second)) {
62 res.addTransition(newInitialState, t.first.second, automaton.getInitialState());
63 }
64 }
65
66 for(const auto& qf : res.getFinalStates())
67 for(const auto& t : res.getTransitionsToState(qf))
68 res.addTransition(t.first.first, t.first.second, res.getInitialState());
69
70 res.setInitialState(newInitialState);
71 res.addFinalState(newInitialState);
72
73 return res;
74}
75
76} /* namespace transform */
77
78} /* namespace automaton */
79
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Definition: AutomatonIteration.h:37
static automaton::NFA< typename Automaton::SymbolType, typename Automaton::StateType > iteration(const Automaton &automaton)
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: AutomataConcatenation.h:102
Automaton::StateType newInitialState
Definition: AutomatonIteration.h:56
Definition: ToGrammar.h:31
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
ContainerType< ResType > transform(const ContainerType< InType, Ts ... > &in, Callback transform)
In container tranformation of all elements according to the tranform.
Definition: algorithm.hpp:150