Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
UsefulStates.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <algorithm>
9#include <deque>
10#include <set>
11#include <map>
12
16#include <automaton/FSM/NFA.h>
17#include <automaton/FSM/DFA.h>
18
19namespace automaton {
20
21namespace properties {
22
23namespace efficient {
24
26public:
30 template < class T >
32};
33
34template < class T >
36 using StateType = typename T::StateType;
37
38 ext::map<StateType, ext::set<StateType>> reversedTransitions;
39 for(const auto& transition : fsm.getTransitions())
40 reversedTransitions [ transition.second ].insert(transition.first.first);
41
42 ext::deque<StateType> queue ( fsm.getFinalStates( ).begin(), fsm.getFinalStates().end() );
43 ext::set<StateType> visited = fsm.getFinalStates( );
44
45 while( !queue.empty() ) {
46 const ext::set<StateType>& to = reversedTransitions[queue.front()];
47 queue.pop_front();
48
49 for(const StateType& process : to)
50 if(visited.insert(process).second) {
51 queue.push_back(std::move(const_cast<StateType&>(process)));
52 }
53 }
54
55 return visited;
56}
57
58} /* namespace efficient */
59
60} /* namespace properties */
61
62} /* namespace automaton */
63
static ext::set< typename T::StateType > usefulStates(const T &fsm)
Definition: UsefulStates.h:35
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
Definition: set.hpp:44
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
ext::set< ext::tuple< StateType, StateType, SymbolType > > visited
Definition: Compaction.h:81
Definition: ToGrammar.h:31