Class: Selection::RankRoulette

Inherits:
Object
  • Object
show all
Includes:
SelectMore
Defined in:
../lib/rank_roulette.rb

Overview

Rank Selection using given Ranking instance. Selection operator which uses Roulette wheel selection applied on :proportion value of pre-ranked individuals.

See www.obitko.com/tutorials/genetic-algorithms/selection.php

Instance Attribute Summary (collapse)

Attributes included from SelectMore

#unique_winners

Instance Method Summary (collapse)

Methods included from SelectMore

#select

Constructor Details

- (RankRoulette) initialize(ranker)

Set the instance of the Ranking object which will be used for ranking the population before the selection.



18
19
20
21
22
23
24
# File '../lib/rank_roulette.rb', line 18

def initialize ranker
  raise "RankRoulette: invalid Ranking object" unless ranker.kind_of? Ranking     
  @ranker = ranker
  @roulette = Roulette.new :proportion
  @population = nil     
  @ranked = nil
end

Instance Attribute Details

- (Object) population

The population to select from.



27
28
29
# File '../lib/rank_roulette.rb', line 27

def population
  @population
end

Instance Method Details

- (Object) random=(rnd)

Set the source of randomness for the roulette, using Roulette#random=



30
31
32
# File '../lib/rank_roulette.rb', line 30

def random= rnd
  @roulette.random = rnd
end

- (Object) select_one(population = self.population)

Rank the population and then select one individual from it. The stochastic “slots” are :proportion-al.



36
37
38
39
40
41
# File '../lib/rank_roulette.rb', line 36

def select_one population=self.population
  @ranked = @ranker.rank( population ) 
  @population = population

  select_one_internal
end