Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ReachableStates.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 template < class SymbolType, class StateType >
34};
35
36template < class T >
38 using StateType = typename T::StateType;
39
41 for(const auto& transition : fsm.getTransitions())
42 transitions[transition.first.first].insert(transition.second);
43
44 ext::deque<StateType> queue { fsm.getInitialState( ) };
45 ext::set<StateType> visited { fsm.getInitialState( ) };
46
47 while( !queue.empty() ) {
48 const ext::set<StateType>& to = transitions[queue.front()];
49 queue.pop_front();
50
51 for(const StateType& process : to)
52 if(visited.insert(process).second) {
53 queue.push_back(std::move(const_cast<StateType&>(process)));
54 }
55 }
56
57 return visited;
58}
59
60template < class SymbolType, class StateType >
63 for(const auto& transition : fsm.getTransitions())
64 transitions[transition.first.first].insert(transition.second);
65
66 ext::deque<StateType> queue ( fsm.getInitialStates( ).begin(), fsm.getInitialStates().end() );
68
69 while( !queue.empty() ) {
70 const ext::set<StateType>& to = transitions[queue.front()];
71 queue.pop_front();
72
73 for(const StateType& process : to)
74 if(visited.insert(process).second) {
75 queue.push_back(std::move(const_cast<StateType&>(process)));
76 }
77 }
78
79 return visited;
80}
81
82} /* namespace efficient */
83
84} /* namespace properties */
85
86} /* namespace automaton */
87
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::multimap< ext::pair< StateType, SymbolType >, StateType > & getTransitions() const &
Definition: MultiInitialStateNFA.h:520
static ext::set< typename T::StateType > reachableStates(const T &fsm)
Definition: ReachableStates.h:37
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