Limi
reachable.h
1 /*
2  * Copyright 2016, IST Austria
3  *
4  * This file is part of Limi.
5  *
6  * Limi is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Limi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Limi. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIMI_REACHABLE_H
21 #define LIMI_REACHABLE_H
22 #include "automaton.h"
23 
24 #include <iostream>
25 #include <fstream>
26 #include <string>
27 #include <unordered_set>
28 #include <deque>
29 #include <unordered_map>
30 
31 namespace Limi {
32 
45 template <class State, class Symbol,class Implementation>
46 std::unordered_set<State> explore(const automaton<State,Symbol,Implementation>& automaton) {
47  std::unordered_set<State> seen;
48  std::deque<State> frontier;
49  for (const auto& s : automaton.initial_states()) {
50  frontier.push_back(s);
51  }
52  while (!frontier.empty()) {
53  State next = frontier.front();
54  frontier.pop_front();
55  if (seen.find(next) == seen.end()) {
56  seen.insert(next);
57  for (const Symbol& symbol : automaton.next_symbols(next)) {
58  for (const State& succ : automaton.successors(next, symbol)) {
59  frontier.push_back(succ);
60  }
61  }
62  }
63  }
64 
65  return seen;
66 }
67 
68 }
69 
70 #endif // LIMI_REACHABLE_H
void next_symbols(const State &state, Symbol_vector &symbols) const
Returns possible successor symbols for a state.
Definition: automaton.h:256
The main namespace of the library.
Definition: antichain_algo.h:40
std::unordered_set< State > explore(const automaton< State, Symbol, Implementation > &automaton)
This function fully explores an automaton and returns a set of all reachable states.
Definition: reachable.h:46
void successors(const State &state, const Symbol &sigma, State_vector &successors1) const
Returns the successor for a specific state.
Definition: automaton.h:201
void initial_states(State_vector &states) const
Returns the initial states.
Definition: automaton.h:167
Automata need to inherit from this class and implement certain methods.
Definition: automaton.h:49