Vcsn  2.1
Be Rational
minimize.hh
Go to the documentation of this file.
1 #pragma once
2 
8 #include <vcsn/dyn/automaton.hh>
9 #include <vcsn/weightset/fwd.hh> // b
10 
11 namespace vcsn
12 {
13 
14  namespace detail
15  {
16  template <typename Aut>
17  constexpr bool can_use_brzozowski()
18  {
20  && std::is_same<weightset_t_of<Aut>, b>::value;
21  }
22  }
23 
24  // FIXME: there must exist some nicer way to do this.
25  template <typename Aut>
26  inline
28  && labelset_t_of<Aut>::is_free(),
29  quotient_t<Aut>>
30  minimize(const Aut& a, const std::string& algo = "auto")
31  {
32  if (algo == "moore")
33  return minimize_moore(a);
34  else if (algo == "auto" || algo == "signature")
35  return minimize_signature(a);
36  else if (algo == "weighted")
37  return minimize_weighted(a);
38  else
39  raise("minimize: invalid algorithm (Boolean, free labelset): ",
40  str_escape(algo));
41  }
42 
43  template <typename Aut>
44  inline
46  && ! labelset_t_of<Aut>::is_free(),
47  quotient_t<Aut>>
48  minimize(const Aut& a, const std::string& algo = "auto")
49  {
50  if (algo == "auto" || algo == "signature")
51  return minimize_signature(a);
52  else if (algo == "weighted")
53  return minimize_weighted(a);
54  else
55  raise("minimize: invalid algorithm (Boolean, non-free labelset): ",
56  str_escape(algo));
57  }
58 
59  template <typename Aut>
60  inline
62  quotient_t<Aut>>
63  minimize(const Aut& a, const std::string& algo = "auto")
64  {
65  if (algo == "auto" || algo == "weighted")
66  return minimize_weighted(a);
67  else
68  raise("minimize: invalid algorithm (non-Boolean): ", str_escape(algo));
69  }
70 
71  template <typename Aut>
72  inline
73  auto
74  cominimize(const Aut& a, const std::string& algo = "auto")
75  -> decltype(transpose(minimize(transpose(a), algo)))
76  {
77  return transpose(minimize(transpose(a), algo));
78  }
79 
80 
81  /*----------------.
82  | dyn::minimize. |
83  `----------------*/
84 
85  namespace dyn
86  {
87  namespace detail
88  {
89 
90  template <typename Aut, typename String>
91  inline
93  minimize_(const automaton& aut, const std::string& algo)
94  {
95  const auto& a = aut->as<Aut>();
96  if (algo == "brzozowski")
98  else
99  return make_automaton(::vcsn::minimize(a, algo));
100  }
101 
102  template <typename Aut, typename String>
103  inline
105  minimize_(const automaton& aut, const std::string& algo)
106  {
107  const auto& a = aut->as<Aut>();
108  return make_automaton(::vcsn::minimize(a, algo));
109  }
110 
112  template <typename Aut, typename String>
113  inline
114  automaton
115  minimize(const automaton& aut, const std::string& algo)
116  {
117  return minimize_<Aut, String>(aut, algo);
118  }
119  }
120  }
121 
122 
123  /*-----------------.
124  | dyn::cominimize. |
125  `-----------------*/
126 
127  namespace dyn
128  {
129  namespace detail
130  {
131  template <typename Aut, typename String>
132  inline
134  cominimize_(const automaton& aut, const std::string& algo)
135  {
136  const auto& a = aut->as<Aut>();
137  if (algo == "brzozowski")
139  else
140  return make_automaton(::vcsn::cominimize(a, algo));
141  }
142 
143  template <typename Aut, typename String>
144  inline
146  cominimize_(const automaton& aut, const std::string& algo)
147  {
148  const auto& a = aut->as<Aut>();
149  return make_automaton(::vcsn::cominimize(a, algo));
150  }
151 
153  template <typename Aut, typename String>
154  inline
155  automaton
156  cominimize(const automaton& aut, const std::string& algo)
157  {
158  return cominimize_<Aut, String>(aut, algo);
159  }
160  }
161  }
162 
163 } // namespace vcsn
auto cominimize(const Aut &a, const std::string &algo="auto") -> decltype(transpose(minimize(transpose(a), algo)))
Definition: minimize.hh:74
std::ostream & str_escape(std::ostream &os, const std::string &str)
Output a string, escaping special characters.
Definition: escape.cc:43
weightset_mixin< detail::b_impl > b
Definition: fwd.hh:48
typename std::enable_if< Cond, T >::type enable_if_t
Definition: type_traits.hh:16
auto minimize_brzozowski(const Aut &a) -> decltype(determinize(codeterminize(a)))
constexpr bool can_use_brzozowski()
Definition: minimize.hh:17
Aut transpose(const transpose_automaton< Aut > &aut)
Definition: transpose.hh:235
automaton make_automaton(const Aut &aut)
Build a dyn::automaton.
Definition: automaton.hh:75
auto minimize_weighted(const Aut &a) -> quotient_t< Aut >
vcsn::enable_if_t< std::is_same< weightset_t_of< Aut >, b >::value &&labelset_t_of< Aut >::is_free(), quotient_t< Aut > > minimize(const Aut &a, const std::string &algo="auto")
Definition: minimize.hh:30
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:46
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
auto minimize_signature(const Aut &a) -> quotient_t< Aut >
typename detail::labelset_t_of_impl< base_t< ValueSet >>::type labelset_t_of
Definition: traits.hh:47
automaton minimize(const automaton &aut, const std::string &algo)
Bridge.
Definition: minimize.hh:115
auto cominimize_brzozowski(const Aut &a) -> decltype(transpose(minimize_brzozowski(transpose(a))))
vcsn::enable_if_t<::vcsn::detail::can_use_brzozowski< Aut >), automaton > minimize_(const automaton &aut, const std::string &algo)
Definition: minimize.hh:93
vcsn::enable_if_t<::vcsn::detail::can_use_brzozowski< Aut >), automaton > cominimize_(const automaton &aut, const std::string &algo)
Definition: minimize.hh:134
automaton cominimize(const automaton &aut, const std::string &algo)
Bridge.
Definition: minimize.hh:156
auto minimize_moore(const Aut &a) -> quotient_t< Aut >
Minimize automaton a using the Moore algorithm.