Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
SingleInitialStateEpsilonTransition.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 <automaton/FSM/DFA.h>
27#include <automaton/FSM/NFA.h>
33
36
37namespace automaton {
38
39namespace simplify {
40
47public:
56 template < class T >
57 requires isMultiInitialStateNFA < T > || isMultiInitialStateEpsilonNFA < T >
59
63 template < class T >
64 requires isDFA < T > || isNFA < T > || isEpsilonNFA < T > || isExtendedNFA < T > || isCompactNFA < T >
65 static T convert ( const T & fsm );
66};
67
68template < class T >
69requires isMultiInitialStateNFA < T > || isMultiInitialStateEpsilonNFA < T >
71 using StateType = typename T::StateType;
72 using SymbolType = typename T::SymbolType;
73
74 // step 1, 3
75 StateType q0 = common::createUnique ( label::InitialStateLabel::instance < StateType > ( ), fsm.getStates ( ) );
76
78 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
79
80 for( const StateType & q : fsm.getStates ( ) )
81 res.addState( q );
82
83 // step 2
84 for ( const auto & q : fsm.getInitialStates ( ) )
85 res.addTransition ( q0, q );
86
87 for ( const auto & t : fsm.getTransitions ( ) )
88 res.addTransition ( t.first.first, t.first.second, t.second );
89
90 // step 4, 5
91 res.setFinalStates ( fsm.getFinalStates ( ) );
92
93 return res;
94}
95
96template < class T >
97requires isDFA < T > || isNFA < T > || isEpsilonNFA < T > || isExtendedNFA < T > || isCompactNFA < T >
99 return fsm;
100}
101
102} /* namespace simplify */
103
104} /* namespace automaton */
105
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Definition: SingleInitialStateEpsilonTransition.h:46
static automaton::EpsilonNFA< typename T::StateType, typename T::SymbolType > convert(const T &fsm)
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
typename T::SymbolType SymbolType
Definition: SingleInitialStateEpsilonTransition.h:72
return res
Definition: MinimizeByPartitioning.h:145
q
Definition: SingleInitialStateEpsilonTransition.h:85
StateType q0
Definition: SingleInitialState.h:96
Definition: ToGrammar.h:31
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46