17 #ifndef AWALI_ALGOS_GRAIL_HH
18 # define AWALI_ALGOS_GRAIL_HH
28 namespace awali {
namespace sttc {
41 template <
typename Aut>
87 const std::string& fmt =
"text")
96 std::vector<transition_t> ts;
97 for (
auto t :
aut_->out(s))
103 return (std::forward_as_tuple(
aut_->label_of(l),
aut_->dst_of(l))
104 < std::forward_as_tuple(
aut_->label_of(
r),
aut_->dst_of(
r)));
117 for (
auto s:
aut_->states())
135 for (
auto t:
aut_->initial_transitions())
136 res.emplace_back(
aut_->dst_of(t));
145 for (
auto t:
aut_->final_transitions())
146 res.emplace_back(
aut_->src_of(t));
176 template <
typename Aut>
180 "requires labels_are_(letters|nullable)");
183 "requires Boolean weights");
195 using super_type::super_type;
202 bool is_deter = is_deterministic_(aut_);
203 os_ << (is_deter ?
"@DFA" :
"@NFA");
204 list_states_(finals_());
208 list_states_(initials_());
210 output_transitions_();
214 template <
typename A>
215 typename std::enable_if<labelset_t_of<A>::is_free(),
217 is_deterministic_(
const A& a)
222 template <
typename A>
223 typename std::enable_if<!labelset_t_of<A>::is_free(),
225 is_deterministic_(
const A&)
233 template <
typename Aut>
235 fado(
const Aut& aut, std::ostream& out)
253 template <
typename Aut>
257 "requires labels_are_(letters|nullable)");
260 "requires Boolean weights");
273 using super_type::super_type;
280 const char* sep =
"";
281 for (
auto s: initials_())
285 aut_->print_state(s, os_);
288 output_transitions_();
289 for (
auto s: finals_())
292 aut_->print_state(s, os_) <<
" -| (FINAL)";
298 template <
typename Aut>
300 grail(
const Aut& aut, std::ostream& out)
The Boolean semring.
Definition: b.hh:38
Format an automaton into Fado.
Definition: grail.hh:178
void operator()()
Actually output aut_ on os_.
Definition: grail.hh:200
Format an automaton into Fado.
Definition: grail.hh:255
void operator()()
Actually output aut_ on os_.
Definition: grail.hh:277
Factor common bits in automaton formatting.
Definition: grail.hh:43
void output_state_(const state_t s)
Output transitions, sorted lexicographically on (Label, Dest).
Definition: grail.hh:94
void output_transitions_()
Output transitions, sorted lexicographically.
Definition: grail.hh:115
outputter(const automaton_t &aut, std::ostream &out)
Definition: grail.hh:48
std::string format_entry_(state_t src, state_t dst, const std::string &fmt="text")
The labels and weights of transitions from src to dst.
Definition: grail.hh:86
virtual std::string label_(const label_t &l)
Convert a label to its representation.
Definition: grail.hh:67
context_t_of< automaton_t > context_t
Definition: grail.hh:57
const automaton_t & aut_
The automaton we have to output.
Definition: grail.hh:152
void list_states_(const states_t &ss)
List names of states in ss, preceded by ' '.
Definition: grail.hh:122
states_t finals_()
The list of final states, sorted.
Definition: grail.hh:142
weight_t_of< automaton_t > weight_t
Definition: grail.hh:60
virtual void output_transition_(transition_t t)
Output the transition t.
Definition: grail.hh:74
Aut automaton_t
Definition: grail.hh:45
const labelset_t_of< automaton_t > & ls_
Short-hand to the labelset.
Definition: grail.hh:156
const weightset_t & ws_
Short-hand to the weightset.
Definition: grail.hh:158
std::ostream & os_
Output stream.
Definition: grail.hh:154
std::vector< state_t > states_t
A list of states.
Definition: grail.hh:63
const polynomialset< context_t_of< automaton_t > > ps_
Short-hand to the polynomialset used to print the entries.
Definition: grail.hh:160
label_t_of< automaton_t > label_t
Definition: grail.hh:58
states_t initials_()
The list of initial states, sorted.
Definition: grail.hh:132
weightset_t_of< automaton_t > weightset_t
Definition: grail.hh:59
Linear combination of labels: map labels to weights.
Definition: polynomialset.hh:69
std::string format(const value_t &v, const std::string &sep=" + ", const std::string &fmt="text") const
Definition: polynomialset.hh:620
The semiring of floating Numbers.
Definition: r.hh:34
static constexpr TOP< void > value
Definition: priority.hh:93
bool is_deterministic(const Aut &aut, state_t s)
Whether state s is deterministic in aut.
Definition: is_deterministic.hxx:48
typename internal::label_t_of_impl< internal::base_t< ValueSet > >::type label_t_of
Helper to retrieve the type of the labels of a value set.
Definition: traits.hh:71
void sort(Aut a, Compare p)
Definition: sort.hh:28
typename internal::weight_t_of_impl< internal::base_t< ValueSet > >::type weight_t_of
Helper to retrieve the type of the weights of a value set.
Definition: traits.hh:81
polynomialset< context_t_of< Aut > >::value_t get_entry(const Aut &aut, state_t s, state_t d)
The entry between two states of an automaton.
Definition: polynomialset.hh:787
typename internal::context_t_of_impl< internal::base_t< ValueSet > >::type context_t_of
Helper to retrieve the type of the context of a value set.
Definition: traits.hh:66
std::ostream & grail(const Aut &aut, std::ostream &out)
Definition: grail.hh:300
typename internal::labelset_t_of_impl< internal::base_t< ValueSet > >::type labelset_t_of
Helper to retrieve the type of the labelset of a value set.
Definition: traits.hh:76
std::ostream & fado(const Aut &aut, std::ostream &out)
Definition: grail.hh:235
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
typename internal::weightset_t_of_impl< internal::base_t< ValueSet > >::type weightset_t_of
Helper to retrieve the type of the weightset of a value set.
Definition: traits.hh:86
Main namespace of Awali.
Definition: ato.hh:22
unsigned state_t
Definition: types.hh:21
unsigned transition_t
Definition: types.hh:22