20 #ifndef LIMI_DOT_PRINTER_H
21 #define LIMI_DOT_PRINTER_H
22 #include "automaton.h"
27 #include <unordered_set>
29 #include <unordered_map>
31 #include "internal/helpers.h"
46 template <
class State,
class Symbol,
class Implementation>
48 typedef std::unordered_set<State> State_set;
49 typedef std::unordered_set<Symbol> Symbol_set;
52 struct frontier_item {
55 explicit frontier_item(State s) : s(s) {}
56 frontier_item(State s,
const Symbol_set& sleep_set) : frontier_item(s)
57 { this->sleep_set = sleep_set; }
70 unsigned state_counter = 0;
71 std::unordered_map<State, unsigned> state_id;
73 out <<
"digraph automaton {" << std::endl;
74 std::unordered_set<State> seen;
75 std::deque<State> frontier;
77 frontier.push_back(s);
78 state_id[s] = ++state_counter;
79 out <<
"begin" << state_counter <<
" [shape=none,label=\"\"]" << std::endl;
80 out <<
"begin" << state_counter <<
" -> " << state_counter << std::endl;
83 while (!frontier.empty()) {
84 State next = frontier.front();
86 if (seen.find(next) == seen.end()) {
88 auto next_it = state_id.find(next);
89 assert(next_it != state_id.end());
91 out << std::to_string(next_it->second) <<
" [label=\"" << automaton.
state_printer()(next) <<
"\"";
93 out <<
",shape=doublecircle";
94 out <<
"]" << std::endl;
95 for (
const Symbol& symbol : automaton.
next_symbols(next)) {
96 for (
const State& succ : automaton.
successors(next, symbol)) {
98 auto succ_it = state_id.find(succ);
99 if (succ_it == state_id.end()) succ_it = state_id.insert(std::make_pair(succ, ++state_counter)).first;
101 frontier.push_back(succ);
102 out << std::to_string(next_it->second) <<
" -> " << std::to_string(succ_it->second) <<
" [label=\"" << automaton.
symbol_printer()(symbol) <<
"\"]" << std::endl;
108 out <<
"}" << std::endl;
118 std::ofstream myfile;
119 myfile.open(filename);
127 #endif // LIMI_DOT_PRINTER_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
Prints automata in dot format.
Definition: dot_printer.h:47
void print_dot(const automaton< State, Symbol, Implementation > &automaton, const std::string &filename)
Writes the automaton to a file.
Definition: dot_printer.h:117
void print_dot(const Automaton &automaton, std::ostream &out)
Prints the automaton to the ostream out.
Definition: dot_printer.h:69
const printer_base< State > & state_printer() const
Returns a printer for states.
Definition: automaton.h:292
bool is_final_state(const State &state) const
This function determines if a specific state is final.
Definition: automaton.h:160
void successors(const State &state, const Symbol &sigma, State_vector &successors1) const
Returns the successor for a specific state.
Definition: automaton.h:201
const printer_base< Symbol > & symbol_printer() const
Returns a printer for symbols.
Definition: automaton.h:304
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