Evocosm - A C++ Framework for Evolutionary Computing
Created by Scott Robert Ladd at
Coyote Gulch Productions.
libevocosm::roulette_wheel Class Reference
A simulated roulette wheel for weighted selection.
More...
#include <roulette.h>
Inheritance diagram for libevocosm::roulette_wheel:
List of all members.Public Member Functions
- 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 (const double *a_weights, size_t a_length, double a_min_weight=std::numeric_limits< double >::epsilon(), double a_max_weight=std::numeric_limits< double >::max())
- Creation constructor (from c-type array).
- roulette_wheel (const roulette_wheel &a_source)
- Copy constructor.
- roulette_wheel & operator= (const roulette_wheel &a_source)
- Assignment operator.
- ~roulette_wheel ()
- Destructor.
- size_t get_size () const
- Get size (number of weights).
- double set_weight (size_t a_index, double a_weight)
- Change the weight assigned to an entry.
- double get_weight (size_t a_index) const
- Get the weight for an index.
- size_t get_index () const
- Retrieve a random index.
Protected Attributes
Detailed Description
You've probably seen a standard gambler's roulette wheel, a spinning circle divided into thirty-seven or thirty-eight equal-sized, pie-shaped sections. The croupier sets the wheel spinning and at the same time tosses an marble into the bowl in the direction opposite to that in which the wheel is moving; when the motion of the wheel ceases, the ball comes to rest in one of the numbered sections.
As an algorithm, a roulette wheel is an array of weights, and the marble is a random integer less than the sum of all weights in the population. To pick on of the "section" (in this case, an index), the algorithm simulates the bouncing metal ball by iterating through the array of weights; if the marble value is less than the current weight (i.e., the ball has stopped), the algorithm returns the index of that weight. Otherwise, the algorithm subtracts the current weight from the marble value, and repeats the process with the next element in the weight array. Thus the largest weights values tend to be the most likely resting places for the marble, since they use a larger area of the abstract wheel.
Constructor & Destructor Documentation
libevocosm::roulette_wheel::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() |
|
) |
|
|
|
Creates a new roulette_wheel based on a set of weights. - Parameters:
-
| a_weights | - A vector of weights defining the wheel |
| a_min_weight | - Minimum possible weight value (defaults to epsilon for type) |
| a_max_weight | - Maximum possible weight value (defaults to max for type) |
|
libevocosm::roulette_wheel::roulette_wheel |
( |
const double * |
a_weights, |
|
|
size_t |
a_length, |
|
|
double |
a_min_weight = std::numeric_limits< double >::epsilon() , |
|
|
double |
a_max_weight = std::numeric_limits< double >::max() |
|
) |
|
|
|
Creates a new roulette_wheel based on a set of weights. - Parameters:
-
| a_weights | - An array of weights defining the wheel |
| a_length | - Number of elements in a_weights |
| a_min_weight | - Minimum possible weight value (defaults to 1.0) |
| a_max_weight | - Maximum possible weight value (defaults to 100.0) |
|
libevocosm::roulette_wheel::roulette_wheel |
( |
const roulette_wheel & |
a_source |
) |
|
|
|
Creates a new roulette_wheel from an existing one. - Parameters:
-
| a_source | - The source object |
|
libevocosm::roulette_wheel::~roulette_wheel |
( |
|
) |
|
|
Member Function Documentation
size_t libevocosm::roulette_wheel::get_index |
( |
|
) |
const |
|
|
Returns a randomly-selected index value by simulating the bouncing of a ball on a roulette wheel, where each index is a "slot" with a width determined by its assigned weight. - Returns:
- A random index value
|
size_t libevocosm::roulette_wheel::get_size |
( |
|
) |
const [inline] |
|
|
Gets the number of weights indexed by the roulette wheel. - Returns:
- The number of weights
|
double libevocosm::roulette_wheel::get_weight |
( |
size_t |
a_index |
) |
const |
|
|
Gets the weight assigned to a specific index. - Parameters:
-
| a_index | Index for which weight should be returned |
- Returns:
- Weight for this index, or -1 if a_index is invalid
|
|
Assigns a roulette_wheel the state of another. - Parameters:
-
| a_source | - The source object |
|
double libevocosm::roulette_wheel::set_weight |
( |
size_t |
a_index, |
|
|
double |
a_weight |
|
) |
|
|
|
Changes the weight assigned to a specific wheel index. - Parameters:
-
| a_index | - Index to change |
| a_weight | - New weight Value |
- Returns:
- Previous weight for this index, or -1 if a_index is invalid
|
The documentation for this class was generated from the following file:
© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.