Vaucanson  1.4.1
brzozowski.hxx
1 // brzozowski.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGORITHMS_BRZOZOWSKI_HXX
18 # define VCSN_ALGORITHMS_BRZOZOWSKI_HXX
19 
21 
22 # include <vaucanson/algorithms/internal/build_pattern.hh>
23 # include <vaucanson/automata/concept/automata_base.hh>
24 
28 # include <vaucanson/misc/usual_macros.hh>
29 
30 namespace vcsn {
31 
32  using namespace algorithm_patterns;
33 
46  template <typename T_auto, typename Exp>
47  struct BrzozowskiAlgo : public IncAutomataConstructor <
48  BrzozowskiAlgo<T_auto, Exp>,
49  T_auto,
50  Exp >
51  {
52  AUTOMATON_TYPES(T_auto);
53  AUTOMATON_FREEMONOID_TYPES(T_auto);
54 
55  BrzozowskiAlgo(const series_set_t& series, const Exp& exp):
56  IncAutomataConstructor<BrzozowskiAlgo, T_auto, Exp>(series, exp)
57  {}
58 
60  void on_state(const Exp& e)
61  {
62  alphabet_t alpha = this->get()->series().monoid().alphabet();
63  if (constant_term(e).first
64  != e.structure().semiring().zero(SELECT(semiring_elt_value_t)))
65  this->set_final();
66  for (alphabet_iterator i = alpha.begin(); i != alpha.end(); ++i)
67  this->link_to(canonical(derivate(e, *i).first), *i);
68  }
69  };
70 
71  template<typename T_auto, typename Exp>
72  T_auto*
73  do_brzozowski(const T_auto& out, const Exp &kexp)
74  {
75  BrzozowskiAlgo<T_auto, Exp> brzozowski_algo(out.series(), canonical(kexp));
76  brzozowski_algo.run();
77  return brzozowski_algo.get();
78  }
79 
80  template<typename A, typename T, typename Exp>
81  void
82  brzozowski(Element<A, T>& out, const Exp& kexp)
83  {
84  BENCH_TASK_SCOPED("brzozowski");
85  out = *do_brzozowski(out, kexp);
86  }
87 
88 } // vcsn
89 
90 #endif // ! VCSN_ALGORITHMS_BRZOZOWSKI_HXX