Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RandomizeAutomaton.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#include <automaton/FSM/NFA.h>
29#include <automaton/FSM/DFA.h>
30
32
33namespace automaton {
34
35namespace generate {
36
42public:
50 template < class SymbolType, class StateType >
52
56 template < class SymbolType, class StateType >
58
62 template < class SymbolType, class StateType >
64
68 template < class SymbolType, class StateType >
70};
71
72template < class SymbolType, class StateType >
75
76 automaton::DFA < SymbolType, StateType > res ( statePermutationMap.find ( fsm.getInitialState ( ) )->second );
77
78 res.setStates ( fsm.getStates ( ) );
79 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
80
81 for ( const StateType & finalState : fsm.getFinalStates ( ) )
82 res.addFinalState ( statePermutationMap.find ( finalState )->second );
83
84 for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & transition : fsm.getTransitions ( ) )
85 res.addTransition ( statePermutationMap.find ( transition.first.first )->second, transition.first.second, statePermutationMap.find ( transition.second )->second );
86
87 return res;
88}
89
90template < class SymbolType, class StateType >
93
95
96 res.setStates ( fsm.getStates ( ) );
97 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
98
99 for ( const StateType & initialState : fsm.getInitialStates ( ) )
100 res.addInitialState ( statePermutationMap.find ( initialState )->second );
101
102 for ( const StateType & finalState : fsm.getFinalStates ( ) )
103 res.addFinalState ( statePermutationMap.find ( finalState )->second );
104
105 for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & transition : fsm.getTransitions ( ) )
106 res.addTransition ( statePermutationMap.find ( transition.first.first )->second, transition.first.second, statePermutationMap.find ( transition.second )->second );
107
108 return res;
109}
110
111template < class SymbolType, class StateType >
114
115 automaton::NFA < SymbolType, StateType > res ( statePermutationMap.find ( fsm.getInitialState ( ) )->second );
116
117 res.setStates ( fsm.getStates ( ) );
118 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
119
120 for ( const StateType & finalState : fsm.getFinalStates ( ) )
121 res.addFinalState ( statePermutationMap.find ( finalState )->second );
122
123 for ( const std::pair < const ext::pair < StateType, SymbolType >, StateType > & transition : fsm.getTransitions ( ) )
124 res.addTransition ( statePermutationMap.find ( transition.first.first )->second, transition.first.second, statePermutationMap.find ( transition.second )->second );
125
126 return res;
127}
128
129template < class SymbolType, class StateType >
132
133 automaton::EpsilonNFA < SymbolType, StateType > res ( statePermutationMap.find ( fsm.getInitialState ( ) )->second );
134
135 res.setStates ( fsm.getStates ( ) );
136 res.setInputAlphabet ( fsm.getInputAlphabet ( ) );
137
138 for ( const StateType & finalState : fsm.getFinalStates ( ) )
139 res.addFinalState ( statePermutationMap.find ( finalState )->second );
140
141 for ( const std::pair < const ext::pair < StateType, common::symbol_or_epsilon < SymbolType > >, StateType > & transition : fsm.getTransitions ( ) )
142 res.addTransition ( statePermutationMap.find ( transition.first.first )->second, transition.first.second, statePermutationMap.find ( transition.second )->second );
143
144 return res;
145}
146
147} /* namespace generate */
148
149} /* namespace automaton */
150
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 with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
const ext::set< StateType > & getInitialStates() const &
Definition: MultiInitialStateNFA.h:117
const ext::set< StateType > & getStates() const &
Definition: MultiInitialStateNFA.h:166
const ext::multimap< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: MultiInitialStateNFA.h:520
const ext::set< StateType > & getFinalStates() const &
Definition: MultiInitialStateNFA.h:215
const ext::set< SymbolType > & getInputAlphabet() const &
Definition: MultiInitialStateNFA.h:264
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: RandomizeAutomaton.h:41
static automaton::EpsilonNFA< SymbolType, StateType > randomize(const automaton::EpsilonNFA< SymbolType, StateType > &fsm)
Definition: RandomizeAutomaton.h:130
static ext::map< T, T > permutationMap(const ext::set< T > &data)
Definition: Permutation.hpp:23
Definition: symbol_or_epsilon.hpp:24
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31