Class: Selection::Roulette
- Inherits:
-
Object
- Object
- Selection::Roulette
- Includes:
- SelectMore
- Defined in:
- ../lib/roulette.rb
Overview
Roulette Selection method. This is the classic stochastic selection method with the probability of the individual selection proportional to some (usually fitness) non-negative value.
See www.obitko.com/tutorials/genetic-algorithms/selection.php
Direct Known Subclasses
Defined Under Namespace
Classes: Slot
Instance Attribute Summary (collapse)
-
- (Object) population
The population to select from.
-
- (Object) proportional_by
The symbol for obtaining the proportion of an individual.
-
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
Attributes included from SelectMore
Instance Method Summary (collapse)
-
- (Roulette) initialize(proportional_by = nil, &block)
constructor
Set the proportional_by or the block for obtaining invividual’s proportion.
-
- (Object) select_one(population = self.population)
Select one individual from the population.
Methods included from SelectMore
Constructor Details
- (Roulette) initialize(proportional_by = nil, &block)
Set the proportional_by or the block for obtaining invividual’s proportion.
17 18 19 20 21 22 23 24 25 26 27 |
# File '../lib/roulette.rb', line 17 def initialize proportional_by=nil, &block @prop = if proportional_by.nil? block else proc { |individual| individual.send(proportional_by) } end @proportional_by = proportional_by @random = Kernel @population = nil @wheel = nil end |
Instance Attribute Details
- (Object) population
The population to select from.
33 34 35 |
# File '../lib/roulette.rb', line 33 def population @population end |
- (Object) proportional_by
The symbol for obtaining the proportion of an individual. The Roulette expects the proportion value on the call ‘individual.send(proportional_by)’
37 38 39 |
# File '../lib/roulette.rb', line 37 def proportional_by @proportional_by end |
- (Object) random
The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.
30 31 32 |
# File '../lib/roulette.rb', line 30 def random @random end |
Instance Method Details
- (Object) select_one(population = self.population)
Select one individual from the population.
40 41 42 43 44 |
# File '../lib/roulette.rb', line 40 def select_one population=self.population @sum,@wheel = wheel_core population @population = population select_one_internal end |