Vaucanson  1.4.1
accessible.hxx
1 // accessible.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, 2008 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_ACCESSIBLE_HXX
18 # define VCSN_ALGORITHMS_ACCESSIBLE_HXX
19 
21 
22 # include <vaucanson/automata/concept/automata_base.hh>
23 # include <vaucanson/automata/implementation/transpose_view.hh>
25 # include <vaucanson/misc/usual_macros.hh>
26 
27 # include <queue>
28 # include <set>
29 
30 
31 namespace vcsn {
32 
33  /*-----------------------.
34  | do_accessible_states. |
35  `-----------------------*/
36 
37  template <class A, typename AI>
38  std::set<typename Element<A, AI>::hstate_t>
39  do_accessible_states(const AutomataBase<A>&,
40  const Element<A, AI>& a)
41  {
42  typedef Element<A, AI> auto_t;
43  AUTOMATON_TYPES(auto_t);
44  typedef std::set<hstate_t> state_set_t;
45 
46  std::queue<hstate_t> queue;
47  state_set_t reachable_states;
48 
49  /*---------------.
50  | Initialization |
51  `---------------*/
52  for_all_const_initial_states(i, a)
53  {
54  queue.push(*i);
55  reachable_states.insert(*i);
56  }
57 
58  /*----------.
59  | Main loop |
60  `----------*/
61  while (!queue.empty())
62  {
63  hstate_t state = queue.front();
64  queue.pop();
65  state_set_t delta_ret;
66  for (delta_iterator j(a.value(), state); ! j.done(); j.next())
67  delta_ret.insert(a.dst_of(*j));
68  for_all_const_(state_set_t, j, delta_ret)
69  {
70  state = *j;
71  if (reachable_states.find(state) == reachable_states.end())
72  {
73  reachable_states.insert(state);
74  queue.push(state);
75  }
76  }
77  }
78  return reachable_states;
79  }
80 
81  template<typename A, typename AI>
82  std::set<typename Element<A, AI>::hstate_t>
84  {
85  BENCH_TASK_SCOPED("accessible_states");
86  return do_accessible_states(a.structure(), a);
87  }
88 
89  template<typename A, typename AI>
90  void
92  {
94  }
95 
96  template<typename A, typename AI>
97  Element<A, AI>
99  {
100  return sub_automaton(a, accessible_states(a));
101  }
102 
103  /*-----------------------.
104  | do_coaccessible_states |
105  `-----------------------*/
106 
107  template <class A, typename AI>
108  std::set<typename Element<A, AI>::hstate_t>
109  do_coaccessible_states(const AutomataBase<A>&,
110  const Element<A, AI>& a)
111  {
113  }
114 
115  template<typename A, typename AI>
116  std::set<typename Element<A, AI>::hstate_t>
118  {
119  return do_coaccessible_states(a.structure(), a);
120  }
121 
122  template<typename A, typename AI>
123  Element<A, AI>
125  {
126  return sub_automaton(a, coaccessible_states(a));
127  }
128 
129  template<typename A, typename AI>
130  void
132  {
134  }
135 
136 } // vcsn
137 
138 #endif // ! VCSN_ALGORITHMS_ACCESSIBLE_HXX