Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


roulette.h
1 //---------------------------------------------------------------------
2 // Algorithmic Conjurings @ http://www.coyotegulch.com
3 // Evocosm -- An Object-Oriented Framework for Evolutionary Algorithms
4 //
5 // roulette.h
6 //---------------------------------------------------------------------
7 //
8 // Copyright 1996, 1999, 2002, 2003, 2004, 2005, 2007 Scott Robert Ladd
9 //
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 59 Temple Place - Suite 330
24 // Boston, MA 02111-1307, USA.
25 //
26 //-----------------------------------------------------------------------
27 //
28 // For more information on this software package, please visit
29 // Scott's web site, Coyote Gulch Productions, at:
30 //
31 // http://www.coyotegulch.com
32 //
33 //-----------------------------------------------------------------------
34 
35 #if !defined(LIBEVOCOSM_ROULETTE_H)
36 #define LIBEVOCOSM_ROULETTE_H
37 
38 // standard C++ Library
39 #include <cmath>
40 #include <vector>
41 #include <limits>
42 
43 // libevocosm
44 #include "evocommon.h"
45 
46 namespace libevocosm
47 {
48  using std::vector;
49 
51 
71  class roulette_wheel : protected globals
72  {
73  public:
75 
81  roulette_wheel(const vector<double> & a_weights,
82  double a_min_weight = std::numeric_limits<double>::epsilon(),
83  double a_max_weight = std::numeric_limits<double>::max());
84 
86 
93  roulette_wheel(const double * a_weights,
94  size_t a_length,
95  double a_min_weight = std::numeric_limits<double>::epsilon(),
96  double a_max_weight = std::numeric_limits<double>::max());
97 
99 
103  roulette_wheel(const roulette_wheel & a_source);
104 
106 
110  roulette_wheel & operator = (const roulette_wheel & a_source);
111 
113 
116  ~roulette_wheel();
117 
119 
123  size_t get_size() const
124  {
125  return m_size;
126  }
127 
129 
135  double set_weight(size_t a_index, double a_weight);
136 
138 
143  double get_weight(size_t a_index) const;
144 
146 
152  size_t get_index() const;
153 
154  protected:
156  size_t m_size;
157 
159  double * m_weights;
160 
163 
165  double m_min_weight;
166 
168  double m_max_weight;
169 
170  private:
171  // internal copy function
172  void copy(const roulette_wheel & a_source);
173  };
174 };
175 
176 #endif
size_t get_index() const
Retrieve a random index.
roulette_wheel & operator=(const roulette_wheel &a_source)
Assignment operator.
double set_weight(size_t a_index, double a_weight)
Change the weight assigned to an entry.
size_t m_size
Number of weights in this wheel.
Definition: roulette.h:156
double get_weight(size_t a_index) const
Get the weight for an index.
double m_min_weight
Minimum possible weight value.
Definition: roulette.h:165
double m_max_weight
Maximum possible weight value.
Definition: roulette.h:168
size_t get_size() const
Get size (number of weights)
Definition: roulette.h:123
roulette_wheel(const vector< double > &a_weights, double a_min_weight=std::numeric_limits< double >::epsilon(), double a_max_weight=std::numeric_limits< double >::max())
Creation constructor (from vector)
A toolkit and framework for implementing evolutionary algorithms.
Definition: evocommon.h:60
double m_total_weight
Total weight of all indexes.
Definition: roulette.h:162
Elements shared by all classes in Evocosm.
Definition: evocommon.h:115
A simulated roulette wheel for weighted selection.
Definition: roulette.h:71
double * m_weights
Array of m_weights.
Definition: roulette.h:159
~roulette_wheel()
Destructor.

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.