17 #ifndef AWALI_ALGOS_GRAIL_HH
18 # define AWALI_ALGOS_GRAIL_HH
28 namespace awali {
namespace sttc {
41 template <
typename Aut>
89 const std::string& fmt =
"text")
98 std::vector<transition_t> ts;
99 for (
auto t :
aut_->out(s))
105 return (std::forward_as_tuple(
aut_->label_of(l),
aut_->dst_of(l))
106 < std::forward_as_tuple(
aut_->label_of(
r),
aut_->dst_of(
r)));
119 for (
auto s:
aut_->states())
137 for (
auto t:
aut_->initial_transitions())
138 res.emplace_back(
aut_->dst_of(t));
147 for (
auto t:
aut_->final_transitions())
148 res.emplace_back(
aut_->src_of(t));
178 template <
typename Aut>
182 "requires labels_are_(letters|nullable)");
185 "requires Boolean weights");
197 using super_type::super_type;
204 bool is_deter = is_deterministic_(aut_);
205 os_ << (is_deter ?
"@DFA" :
"@NFA");
206 list_states_(finals_());
210 list_states_(initials_());
212 output_transitions_();
216 template <
typename A>
217 typename std::enable_if<labelset_t_of<A>::is_free(),
219 is_deterministic_(
const A& a)
224 template <
typename A>
225 typename std::enable_if<!labelset_t_of<A>::is_free(),
227 is_deterministic_(
const A&)
235 template <
typename Aut>
237 fado(
const Aut& aut, std::ostream& out)
255 template <
typename Aut>
259 "requires labels_are_(letters|nullable)");
262 "requires Boolean weights");
275 using super_type::super_type;
282 const char* sep =
"";
283 for (
auto s: initials_())
287 aut_->print_state(s, os_);
290 output_transitions_();
291 for (
auto s: finals_())
294 aut_->print_state(s, os_) <<
" -| (FINAL)";
300 template <
typename Aut>
302 grail(
const Aut& aut, std::ostream& out)
The Boolean semring.
Definition: b.hh:38
Format an automaton into Fado.
Definition: grail.hh:180
void operator()()
Actually output aut_ on os_.
Definition: grail.hh:202
Format an automaton into Fado.
Definition: grail.hh:257
void operator()()
Actually output aut_ on os_.
Definition: grail.hh:279
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:96
void output_transitions_()
Output transitions, sorted lexicographically.
Definition: grail.hh:117
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:88
virtual std::string label_(const label_t &l)
Convert a label to its representation.
Definition: grail.hh:69
context_t_of< automaton_t > context_t
Definition: grail.hh:59
const automaton_t & aut_
The automaton we have to output.
Definition: grail.hh:154
void list_states_(const states_t &ss)
List names of states in ss, preceded by ' '.
Definition: grail.hh:124
states_t finals_()
The list of final states, sorted.
Definition: grail.hh:144
weight_t_of< automaton_t > weight_t
Definition: grail.hh:62
virtual void output_transition_(transition_t t)
Output the transition t.
Definition: grail.hh:76
Aut automaton_t
Definition: grail.hh:45
const labelset_t_of< automaton_t > & ls_
Short-hand to the labelset.
Definition: grail.hh:158
const weightset_t & ws_
Short-hand to the weightset.
Definition: grail.hh:160
std::ostream & os_
Output stream.
Definition: grail.hh:156
virtual ~outputter()=default
std::vector< state_t > states_t
A list of states.
Definition: grail.hh:65
const polynomialset< context_t_of< automaton_t > > ps_
Short-hand to the polynomialset used to print the entries.
Definition: grail.hh:162
label_t_of< automaton_t > label_t
Definition: grail.hh:60
states_t initials_()
The list of initial states, sorted.
Definition: grail.hh:134
weightset_t_of< automaton_t > weightset_t
Definition: grail.hh:61
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:35
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:790
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:302
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:237
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