Vaucanson  1.4.1
gen_random.hh
1 // gen_random.hh: 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
6 // Vaucanson Group.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // The complete GNU General Public Licence Notice can be found as the
14 // `COPYING' file in the root directory.
15 //
16 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
17 //
18 #ifndef VCSN_TOOLS_GEN_RANDOM_HH
19 # define VCSN_TOOLS_GEN_RANDOM_HH
20 
22 # include <vaucanson/algebra/implementation/monoid/monoid_rep.hh>
23 # include <vaucanson/automata/concept/transducer.hh>
24 
25 // We can have letter types with very large cardinal
26 // (say int letters). So we clip the max size to
27 // ALPHABET_MAX_SIZE to ensure the test-suite will
28 // be able to generate random automata with max-sized
29 // alphabets.
30 # define ALPHABET_MAX_SIZE 1024
31 
32 namespace vcsn {
33 
34  namespace tools {
35 
36  /*---------------------.
37  | GenRandomAutomataSet |
38  `---------------------*/
39 
40  class GenRandomAutomataSet
41  {
42  public:
43 
44  template <class AutoSet>
45  static AutoSet generate(SELECTOR(AutomataBase<AutoSet>),
46  unsigned nb_letter = 0);
47 
48  template <class AutoSet>
49  static AutoSet generate(SELECTOR(TransducerBase<AutoSet>),
50  unsigned input_nb_letter = 0,
51  unsigned output_nb_letter = 0);
52  };
53 
54 
55  /*------------------.
56  | GenRandomAutomata |
57  `------------------*/
58 
59  template <class TAutomata, class AutomataSetGenerator = GenRandomAutomataSet>
60  class GenRandomAutomata
61  {
62  public:
63  typedef typename TAutomata::set_t automata_set_t;
64  typedef typename TAutomata::hstate_t hstate_t;
65 
66  public:
67  GenRandomAutomata();
68 
69  TAutomata empty(unsigned nb_letter = 0);
70  TAutomata empty(const automata_set_t& set);
71 
72  TAutomata generate(unsigned nb_state, unsigned nb_transition,
73  unsigned istate = 1, unsigned fstate = 1,
74  unsigned nb_letter = 0);
75  TAutomata generate(const automata_set_t& set,
76  unsigned nb_state, unsigned nb_transition,
77  unsigned istate = 1, unsigned fstate = 1);
78 
79  TAutomata generate_dfa(unsigned nb_state,
80  unsigned size_alphabet = 0,
81  unsigned fstate = 1);
82  TAutomata generate_dfa(const automata_set_t& set,
83  unsigned nb_state,
84  unsigned fstate = 1);
85 
86  TAutomata generate_with_epsilon(unsigned nb_state, unsigned nb_transition,
87  unsigned nb_epsilon_min,
88  unsigned nb_epsilon_max);
89  TAutomata generate_with_epsilon(const automata_set_t& set,
90  unsigned nb_state, unsigned nb_transition,
91  unsigned nb_epsilon_min,
92  unsigned nb_epsilon_max);
93 
94  TAutomata generate_normalized(unsigned nb_state, unsigned density = 3);
95  TAutomata generate_normalized(const automata_set_t& set,
96  unsigned nb_state, unsigned density = 3);
97 
98 
99  private:
100 
101  unsigned nb_transition_circle(TAutomata work, hstate_t state);
102  void del_transition_circle(TAutomata& work, hstate_t state);
103 
104  };
105 
106  static unsigned alea(unsigned max);
107 
108  } // ! tools
109 
110 } // ! vcsn
111 
112 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
113 # include <vaucanson/tools/gen_random.hxx>
114 # endif // VCSN_USE_INTERFACE_ONLY
115 
116 #endif // ! VCSN_TOOLS_GEN_RANDOM_HH