Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RemoveUnused.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 <ext/algorithm>
27#include <ext/iostream>
28
29#include <alib/map>
30#include <alib/vector>
31
33
34namespace automaton {
35
36namespace simplify {
37
42public:
54 template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
56};
57
58template < class InputSymbolType, class PushdownStoreSymbolType, class StateType >
63
64 states.insert ( pda.getInitialState ( ) );
65 pushdownAlphabet.insert ( pda.getBottomOfTheStackSymbol ( ) );
66
67 for ( const auto & transition : pda.getCallTransitions ( ) ) {
68 if ( ! transition.first.second.is_epsilon ( ) )
69 alphabet.insert ( transition.first.second.getSymbol ( ) );
70 pushdownAlphabet.insert ( transition.second.second );
71 states.insert ( transition.first.first );
72 states.insert ( transition.second.first );
73 }
74
75 for ( const auto & transition : pda.getLocalTransitions ( ) ) {
76 if ( ! transition.first.second.is_epsilon ( ) )
77 alphabet.insert ( transition.first.second.getSymbol ( ) );
78 states.insert ( transition.first.first );
79 states.insert ( transition.second );
80 }
81
82 for ( const auto & transition : pda.getReturnTransitions ( ) ) {
83 if ( ! std::get < 1 > ( transition.first ).is_epsilon ( ) )
84 alphabet.insert ( std::get < 1 > ( transition.first ).getSymbol ( ) );
85 pushdownAlphabet.insert ( std::get < 2 > ( transition.first ) );
86 states.insert ( std::get < 0 > ( transition.first ) );
87 states.insert ( transition.second );
88 }
89
91
92 result.setInputAlphabet ( alphabet );
93 result.setPushdownStoreAlphabet ( pushdownAlphabet );
94 result.setStates ( states );
95
96 for ( const StateType & state : pda.getFinalStates ( ) )
97 if ( states.contains ( state ) )
98 result.addFinalState ( state );
99
100 for ( const auto & transition : pda.getCallTransitions ( ) )
101 result.addCallTransition ( transition.first.first, transition.first.second, transition.second.first, transition.second.second );
102
103 for ( const auto & transition : pda.getLocalTransitions ( ) )
104 result.addLocalTransition ( transition.first.first, transition.first.second, transition.second );
105
106 for ( const auto & transition : pda.getReturnTransitions ( ) )
107 result.addReturnTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), std::get < 2 > ( transition.first ), transition.second );
108
109 return result;
110}
111
112} /* namespace simplify */
113
114} /* namespace automaton */
115
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
const StateType & getInitialState() const &
Definition: RealTimeHeightDeterministicDPDA.h:149
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, ext::pair< StateType, PushdownStoreSymbolType > > & getCallTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1062
const ext::map< ext::pair< StateType, common::symbol_or_epsilon< InputSymbolType > >, StateType > & getLocalTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1082
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, PushdownStoreSymbolType >, StateType > & getReturnTransitions() const &
Definition: RealTimeHeightDeterministicDPDA.h:1072
const ext::set< StateType > & getFinalStates() const &
Definition: RealTimeHeightDeterministicDPDA.h:227
const PushdownStoreSymbolType & getBottomOfTheStackSymbol() const &
Definition: RealTimeHeightDeterministicDPDA.h:334
Definition: RemoveUnused.h:41
static automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > removeUnused(const automaton::RealTimeHeightDeterministicDPDA< InputSymbolType, PushdownStoreSymbolType, StateType > &pda)
Definition: RemoveUnused.h:59
Definition: set.hpp:44
Definition: BarSymbol.cpp:12
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
Definition: ToGrammar.h:31