27 template <Automaton Aut>
46 using super_t::super_t;
50 const char*
gray =
"color = DimGray";
57 #if defined __GNUC__ && ! defined __clang__
60 # pragma GCC diagnostic push
61 # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
64 #if defined __GNUC__ && ! defined __clang__
65 # pragma GCC diagnostic pop
95 ?
"texmode = math, lblstyle = auto"
96 :
"arrowhead = vee, arrowsize = .6")
101 " d2toptions = \"--format tikz --tikzedgelabels"
102 " --graphstyle=automaton --crop --nominsize --autosize\"\n"
103 " d2tdocpreamble = \""
104 " \\usepackage{amssymb}"
105 " \\usetikzlibrary{arrows.meta, automata, bending}"
106 " \\tikzstyle{automaton}=[shorten >=1pt, pos=.4,"
107 " >={Stealth[bend,round]}, initial text=]"
108 " \\tikzstyle{named}=[rectangle, rounded corners]"
109 " \\tikzstyle{initial}=[initial by arrow]"
110 " \\tikzstyle{accepting}=[accepting by arrow]"
126 const std::string& kind,
const weight_t& w)
133 if (
ws_.show_one() || !
ws_.is_one(w))
135 bos_ <<
", " << kind <<
" text={";
147 bool has_attributes =
false;
150 has_attributes =
true;
157 if (
aut_->state_has_name(s))
159 bos_ <<
"label = \"";
163 static bool debug = getenv(
"VCSN_DEBUG");
165 bos_ <<
" (" << s <<
')';
166 bos_ <<
"\", style = \"named";
171 sep =
"style = \"state, ";
172 if (
print_(sep,
"initial",
aut_->get_initial_weight(s)))
177 if (
print_(sep,
"accepting",
aut_->get_final_weight(s)))
184 if (
aut_->state_has_name(s))
186 has_attributes =
true;
187 bos_ <<
" [label = \"";
191 static bool debug = getenv(
"VCSN_DEBUG");
193 bos_ <<
" (" << s <<
')';
194 bos_ <<
"\", shape = box";
196 if (
aut_->is_lazy(s))
203 has_attributes =
true;
205 bos_ <<
"style = dashed";
215 has_attributes =
true;
234 " node [shape = point, width = 0]\n";
264 if (!
aut_->states().empty())
269 ?
"texmode = math, style = state"
270 :
"shape = circle, style = rounded, width = 0.5")
272 for (
auto s :
aut_->states())
287 if (src ==
aut_->pre())
295 if (dst ==
aut_->post())
305 if (!e.empty() || useless)
308 const char* sep =
"";
311 bos_ <<
"label = \"";
329 std::map<state_t, polynomial_t> dsts;
330 for (
auto src :
aut_->all_states())
331 if (!
aut_->is_lazy(src)
340 ps_.new_weight(dsts[
aut_->dst_of(t)],
341 aut_->label_of(t),
aut_->weight_of(t));
342 for (
const auto& p: dsts)
350 boost::iostreams::flush(
bos_);
357 boost::iostreams::flush(
bos_);
362 detail::io::filtering_ostream
bos_;
375 template <Automaton Aut>
379 detail::dotter<Aut>
dot{aut,
out, fmt};
std::unordered_set< state_t_of< Aut > > useful_
Useful states, without evaluating the lazy states.
const weightset_t & ws_
Short-hand to the weightset.
void print_states_()
Print the states.
auto all_out(const Aut &aut, state_t_of< Aut > s)
Indexes of transitions leaving state s.
std::ostream & operator()()
Print the automaton on the stream.
typename polynomialset_t::value_t polynomial_t
void enable_()
Enable the escaping of backslashes.
void print_state_(state_t s)
Pretty-print state s.
std::ostream & os_
Output stream.
format format_
Format for labels and weights.
std::string to_string(direction d)
Conversion to string.
const polynomialset_t ps_
Short-hand to the polynomialset used to print the entries.
void print_transitions_(const state_t src, const state_t dst, const polynomial_t &entry)
Print the transitions between state src and state dst.
transition_t_of< automaton_t > transition_t
An input/output format for valuesets.
void disable_()
Disable the escaping of backslashes.
detail::io::filtering_ostream bos_
The output stream, with a backslashify filter.
auto out(const Aut &aut, state_t_of< Aut > s)
Indexes of visible transitions leaving state s.
states_t initials_()
The list of initial states, sorted.
void print_transitions_()
Print all the transitions, sorted by src state, then dst state.
auto initial_transitions(const Aut &aut) -> decltype(aut->all_out(aut->pre()))
Indexes of transitions to (visible) initial states.
bool print_(const std::string &sep, const std::string &kind, const weight_t &w)
Print a TikZ attribute.
void print_prologue_()
Start the dot graph.
Format an automaton into Dot.
weight_t_of< automaton_t > weight_t
automaton_t aut_
The automaton we have to output.
Print as a parsable type string.
states_t finals_()
The list of final states, sorted.
state_t_of< automaton_t > state_t
ATTRIBUTE_PURE bool has(const boost::container::flat_set< Key, Compare, Allocator > &s, const Key &e)
Whether e is member of s.
auto final_transitions(const Aut &aut) -> decltype(aut->all_in(aut->post()))
Indexes of transitions from (visible) final states.
states_t< Aut > useful_states(const Aut &a, bool strict=true)
The set of useful states, including possibly pre() and post().
std::ostream & dot(const Aut &aut, std::ostream &out, format fmt={})
Print an automaton in Graphviz's Dot format.
Factor common bits in automaton formatting.
dotter(const automaton_t &aut, std::ostream &out, format fmt)
void print_epilogue_()
Finish the dot graph.
weightset_t_of< automaton_t > weightset_t