Evocosm - A C++ Framework for Evolutionary Computing

Main Index

Created by Scott Robert Ladd at Coyote Gulch Productions.


roulette.h
1 /*
2  Evocosm is a C++ framework for implementing evolutionary algorithms.
3 
4  Copyright 2011 Scott Robert Ladd. All rights reserved.
5 
6  Evocosm is user-supported open source software. Its continued development is dependent
7  on financial support from the community. You can provide funding by visiting the Evocosm
8  website at:
9 
10  http://www.coyotegulch.com
11 
12  You may license Evocosm in one of two fashions:
13 
14  1) Simplified BSD License (FreeBSD License)
15 
16  Redistribution and use in source and binary forms, with or without modification, are
17  permitted provided that the following conditions are met:
18 
19  1. Redistributions of source code must retain the above copyright notice, this list of
20  conditions and the following disclaimer.
21 
22  2. Redistributions in binary form must reproduce the above copyright notice, this list
23  of conditions and the following disclaimer in the documentation and/or other materials
24  provided with the distribution.
25 
26  THIS SOFTWARE IS PROVIDED BY SCOTT ROBERT LADD ``AS IS'' AND ANY EXPRESS OR IMPLIED
27  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
28  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SCOTT ROBERT LADD OR
29  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
32  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 
36  The views and conclusions contained in the software and documentation are those of the
37  authors and should not be interpreted as representing official policies, either expressed
38  or implied, of Scott Robert Ladd.
39 
40  2) Closed-Source Proprietary License
41 
42  If your project is a closed-source or proprietary project, the Simplified BSD License may
43  not be appropriate or desirable. In such cases, contact the Evocosm copyright holder to
44  arrange your purchase of an appropriate license.
45 
46  The author can be contacted at:
47 
48  scott.ladd@coyotegulch.com
49  scott.ladd@gmail.com
50  http:www.coyotegulch.com
51 */
52 
53 #if !defined(LIBEVOCOSM_ROULETTE_H)
54 #define LIBEVOCOSM_ROULETTE_H
55 
56 // standard C++ Library
57 #include <cmath>
58 #include <vector>
59 #include <limits>
60 
61 // libevocosm
62 #include "evocommon.h"
63 
64 namespace libevocosm
65 {
66  using std::vector;
67 
69 
89  class roulette_wheel : protected globals
90  {
91  public:
93 
99  roulette_wheel(const vector<double> & a_weights,
100  double a_min_weight = std::numeric_limits<double>::epsilon(),
101  double a_max_weight = std::numeric_limits<double>::max());
102 
104 
111  roulette_wheel(const double * a_weights,
112  size_t a_length,
113  double a_min_weight = std::numeric_limits<double>::epsilon(),
114  double a_max_weight = std::numeric_limits<double>::max());
115 
117 
121  roulette_wheel(const roulette_wheel & a_source);
122 
124 
128  roulette_wheel & operator = (const roulette_wheel & a_source);
129 
131 
134  ~roulette_wheel();
135 
137 
141  size_t get_size() const
142  {
143  return m_size;
144  }
145 
147 
153  double set_weight(size_t a_index, double a_weight);
154 
156 
161  double get_weight(size_t a_index) const;
162 
164 
170  size_t get_index() const;
171 
172  protected:
174  size_t m_size;
175 
177  double * m_weights;
178 
181 
183  double m_min_weight;
184 
186  double m_max_weight;
187 
188  private:
189  // internal copy function
190  void copy(const roulette_wheel & a_source);
191  };
192 };
193 
194 #endif
double m_total_weight
Total weight of all indexes.
Definition: roulette.h:180
double m_max_weight
Maximum possible weight value.
Definition: roulette.h:186
double * m_weights
Array of m_weights.
Definition: roulette.h:177
size_t get_size() const
Get size (number of weights)
Definition: roulette.h:141
roulette_wheel & operator=(const roulette_wheel &a_source)
Assignment operator.
A toolkit and framework for implementing evolutionary algorithms.
Definition: analyzer.h:60
Elements shared by all classes in Evocosm.
Definition: evocommon.h:117
A simulated roulette wheel for weighted selection.
Definition: roulette.h:89
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)
~roulette_wheel()
Destructor.
size_t get_index() const
Retrieve a random index.
double get_weight(size_t a_index) const
Get the weight for an index.
double set_weight(size_t a_index, double a_weight)
Change the weight assigned to an entry.
double m_min_weight
Minimum possible weight value.
Definition: roulette.h:183
size_t m_size
Number of weights in this wheel.
Definition: roulette.h:174

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