Vaucanson  1.4.1
skeleton.hxx
1 // skeleton.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_INTERNAL_SKELETON_HXX
18 # define VCSN_ALGORITHMS_INTERNAL_SKELETON_HXX
19 
21 
22 namespace vcsn
23 {
24 
25  /*------------------------.
26  | Skeleton Implementation |
27  `------------------------*/
28 
29  template<typename A, typename T>
30  Skeleton<A, T>::Skeleton(const Element<A, T>& x) : a(x)
31  {
32 
33  typedef Element<A, T> automaton_t;
34 
35  AUTOMATON_TYPES(automaton_t);
36 
37  int i, j;
38  std::list<htransition_t> out;
39  std::map<series_set_elt_t, int> Lmap;
40  std::map<hstate_t, int> Smap;
41 
42  states.reserve(a.states().size());
43  transitions.reserve(a.transitions().size());
44  src_transitions.reserve(a.transitions().size());
45  dst_transitions.reserve(a.transitions().size());
46  transitions_labels.reserve(a.transitions().size());
47 
48  // *** FIXME ***
49  // HOW TO INITIALIZE A VECTOR OF LISTS?
50  std::list<int> dummy;
51  delta_in.assign(a.states().size(), dummy);
52  delta_out.assign(a.states().size(), dummy);
53 
54 
55  // Gives each state a number. Constructs lists I and T of initial
56  // and final states
57  // Time complexity: O(n log n)
58  i = 0;
59  for_all_states(q, a)
60  {
61  states.push_back(*q);
62  Smap[*q] = i++;
63 
64  if (a.is_initial(*q))
65  I.push_front(i - 1);
66  else
67  if (a.is_final(*q))
68  F.push_front(i - 1);
69  }
70 
71  // Gives each transition an index (transition[i] = transition whose index is i)
72  // Gives each label an index in map Lmap
73  // Gives each transition the index of its label (transitions_labels[i] = index
74  // of label of transition i)
75  // (time complexity: O(m log s + m log n))
76  // Constructs vectors src_of and dst_of
77 
78  // Index of the labels
79  i = 0;
80  // Index of the transitions
81  j = 0;
82  for_all_transitions(e, a)
83  {
84  transitions.push_back(*e);
85  src_transitions.push_back(Smap[a.src_of(*e)]);
86  dst_transitions.push_back(Smap[a.dst_of(*e)]);
87 
88  if (Lmap.find(a.series_of(*e)) == Lmap.end())
89  transitions_labels.push_back(Lmap[a.series_of(*e)] = i++);
90  else
91  transitions_labels.push_back(Lmap[a.series_of(*e)]);
92  }
93 
94  // Here, i = number of different labels
95 
96  /*** FIXME ***/
97  // The following piece of code is intended to visit each entry of
98  // map Lmap and put each label in its place in vector
99  // labels, but it doesn't compile. The problem is then solved by
100  // visiting all the transitions of the automaton, what can produce
101  // several visits to the same label.
102  //
103  // for (std::map<label_t, int>::iterator itr = Lmap.begin();
104  // itr != Lmap.end(); itr++)
105  // labels[itr->second] = itr->first;
106  // *** REMARK: vector labels is obsolete
107 
108 
109  // Construct the list of transitions for each label (transitions_lex indexed
110  // by labels, transitions_lex[i] = list of transitions with label i)
111 
112  std::vector< std::list<int> > transitions_lex(i);
113 
114  for (i = 0; i < static_cast<int>(a.transitions().size()); i++)
115  transitions_lex[transitions_labels[i]].push_front(i);
116 
117  // By using vector transitions_lex, defines ingoing and outgoing transitions
118  // of each state in lexicographic order
119  for (i = 0; i < static_cast<int>(transitions_lex.capacity()); i++)
120  for (std::list<int>::iterator it = transitions_lex[i].begin();
121  it != transitions_lex[i].end(); it++)
122  {
123  delta_in[dst_transitions[*it]].push_back(*it);
124  delta_out[src_transitions[*it]].push_back(*it);
125  }
126 
127  }
128 
129  template<typename A, typename T>
130  void Skeleton<A, T>::reserve_aux_states_int()
131  {
132  aux_states_int.reserve(a.states().size());
133  }
134 
135  template<typename A, typename T>
136  void Skeleton<A, T>::reserve_aux_states_bool()
137  {
138  aux_states_bool.reserve(a.states().size());
139  }
140 
141  template<typename A, typename T>
142  void Skeleton<A, T>::reserve_aux_states_generic()
143  {
144  aux_states_generic.reserve(a.states().size());
145  }
146 
147  template<typename A, typename T>
148  void Skeleton<A, T>::reserve_aux_transitions_int()
149  {
150  aux_transitions_int.reserve(a.transitions().size());
151  }
152 
153  template<typename A, typename T>
154  void Skeleton<A, T>::reserve_aux_transitions_bool()
155  {
156  aux_transitions_bool.reserve(a.transitions().size());
157  }
158 
159  template<typename A, typename T>
160  void Skeleton<A, T>::reserve_aux_transitions_generic()
161  {
162  aux_transitions_generic.reserve(a.transitions().size());
163  }
164 
165 } // vcsn
166 
167 #endif // ! VCSN_ALGORITHMS_INTERNAL_SKELETON_HXX