Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
Reverse.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/FSM/NFA.h>
28#include <automaton/FSM/DFA.h>
29
30namespace automaton {
31
32namespace transform {
33
38class Reverse {
39public:
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 >
66
67 res.setStates(automaton.getStates());
68 res.addFinalState(automaton.getInitialState());
69 res.setInitialStates( automaton.getFinalStates() );
70 res.setInputAlphabet(automaton.getInputAlphabet());
71
72 for(const auto& t : automaton.getTransitions())
73 res.addTransition(t.second, t.first.second, t.first.first);
74
75 return res;
76}
77
78template < class SymbolType, class StateType >
81
82 res.setStates(automaton.getStates());
83 res.addFinalState(automaton.getInitialState());
84 res.setInitialStates( automaton.getFinalStates() );
85 res.setInputAlphabet(automaton.getInputAlphabet());
86
87 for(const auto& t : automaton.getTransitions())
88 res.addTransition(t.second, t.first.second, t.first.first);
89
90 return res;
91}
92
93template < class SymbolType, class StateType >
96
97 res.setStates(automaton.getStates());
98 res.setFinalStates(automaton.getInitialStates());
99 res.setInitialStates( automaton.getFinalStates() );
100 res.setInputAlphabet(automaton.getInputAlphabet());
101
102 for(const auto& t : automaton.getTransitions())
103 res.addTransition ( t.second, t.first.second, t.first.first);
104
105 return res;
106}
107
108} /* namespace transform */
109
110} /* namespace automaton */
111
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Definition: Reverse.h:38
static automaton::MultiInitialStateNFA< SymbolType, StateType > convert(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: Reverse.h:64
return res
Definition: AutomataConcatenation.h:102
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