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