Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ToArcFactored.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
28
30
32
33namespace automaton {
34
35namespace simplify {
36
42public:
43 template < class SymbolType, class StateType >
45};
46
47template < class SymbolType, class StateType >
50
52 for ( const std::pair < const ext::pair < ext::variant < SymbolType, StateType >, ext::vector < ext::variant < SymbolType, StateType > > >, StateType > & transition : automaton.getTransitions ( ) )
53 for ( const StateType & state : epsilonClosure [ transition.second ] )
54 nonEpsilonTransitions.insert ( ext::make_pair ( transition.first, state ) );
55
57
58 for ( const StateType & state : automaton.getStates ( ) )
59 res.addState ( ext::vector < ext::variant < SymbolType, StateType > > ( 1, state ) );
60
61 for ( const StateType & state : automaton.getFinalStates ( ) )
62 res.addFinalState ( ext::vector < ext::variant < SymbolType, StateType > > ( 1, state ) );
63
64 res.addInputSymbols ( automaton.getInputAlphabet ( ) );
65
66 for ( const SymbolType & symbol : automaton.getInputAlphabet ( ) ) {
68 res.addState ( state );
69 res.addTransition ( symbol, state );
70 }
71
72 for ( const std::pair < const ext::pair < ext::variant < SymbolType, StateType >, ext::vector < ext::variant < SymbolType, StateType > > >, StateType > & transition : nonEpsilonTransitions ) {
73 if ( ! transition.first.second.empty ( ) ) {
75
76 for ( auto iter = transition.first.second.begin ( ); std::next ( iter ) != transition.first.second.end ( ); ++ iter ) {
78 res.addState ( newSource );
79 res.addTransition ( ext::make_pair ( source, ext::vector < ext::variant < SymbolType, StateType > > ( 1, * iter ) ), newSource );
80 source = newSource;
81 }
82
83 res.addTransition ( ext::make_pair ( source, ext::vector < ext::variant < SymbolType, StateType > > ( 1, transition.first.second.back ( ) ) ), ext::vector < ext::variant < SymbolType, StateType > > ( 1, transition.second ) );
84 }
85 }
86
87 // actually not in the paper
88 for ( const std::pair < const ext::pair < ext::variant < SymbolType, StateType >, ext::vector < ext::variant < SymbolType, StateType > > >, StateType > & transition : nonEpsilonTransitions )
89 if ( automaton.getInputAlphabet ( ).contains ( transition.first.first ) && transition.first.second.empty ( ) )
90 res.addTransition ( transition.first.first.template get < SymbolType > ( ), ext::vector < ext::variant < SymbolType, StateType > > ( 1, transition.second ) );
91
92 return res;
93}
94
95} /* namespace simplify */
96
97} /* namespace automaton */
Nondeterministic Z-Automaton in Arc-Factored Normal Form. Computation model for unranked regular tree...
Definition: ArcFactoredNondeterministicZAutomaton.h:67
Nondeterministic Z-Automaton. Computation model for unranked regular tree languages.
Definition: NondeterministicZAutomaton.h:68
static ext::map< typename T::StateType, ext::set< typename T::StateType > > allEpsilonClosure(const T &fsm)
Definition: ToArcFactored.h:41
static ArcFactoredNondeterministicZAutomaton< SymbolType, ext::vector< ext::variant< SymbolType, StateType > > > convert(const NondeterministicZAutomaton< SymbolType, StateType > &automaton)
Definition: ToArcFactored.h:48
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the multimap class from the standard library. Original reason is to allow printing of...
Definition: multimap.hpp:48
iterator insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: multimap.hpp:118
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Implementation of the variant class allowing to store any type of those listed in the template parame...
Definition: variant.hpp:98
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
typename T::SymbolType SymbolType
Definition: SingleInitialStateEpsilonTransition.h:72
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79