Class: Selection::Tournament

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

Overview

Tournament Selection method. This method selects the best individual from the randomly selected subset of the population. The subset size (tournament_size) and the pressure_modifier parameters control the selection pressure.

See en.wikipedia.org/wiki/Tournament_selection

Instance Attribute Summary (collapse)

Attributes included from SelectMore

#unique_winners

Instance Method Summary (collapse)

Methods included from SelectMore

#select

Constructor Details

- (Tournament) initialize(ranker, tournament_size = 2, pressure_modifier = 1.0)

Set the instance of the Ranking object which will be used for ranking the population before the selection. The tournament_size and/or pressure_modifier can also be set (optional).



19
20
21
22
23
24
25
# File '../lib/tournament.rb', line 19

def initialize ranker, tournament_size=2, pressure_modifier=1.0
  raise "Tournament: invalid Ranking object" unless ranker.kind_of? Ranking 
  @ranker = ranker
  @tournament_size = tournament_size 
  @random = Kernel
  @pressure_modifier = pressure_modifier
end

Instance Attribute Details

- (Object) population

The population to select from.



41
42
43
# File '../lib/tournament.rb', line 41

def population
  @population
end

- (Object) pressure_modifier

The probability of the selection of the best individual from the subset. If the rank.first individual is not selected, the second individual is chosen with the probability pressure_modifier*(1-pressure_modifier), etc.



38
39
40
# File '../lib/tournament.rb', line 38

def pressure_modifier
  @pressure_modifier
end

- (Object) random

The source of randomness, used for calling “random.rand( limit )”, defaulting to ‘Kernel’ class.



34
35
36
# File '../lib/tournament.rb', line 34

def random
  @random
end

- (Object) ranker

The instance of the Ranking object which will be used for ranking the subset (the rank.first is the winner).



31
32
33
# File '../lib/tournament.rb', line 31

def ranker
  @ranker
end

- (Object) tournament_size

The size of the random subset which is to be pre-selected for the tournament.



28
29
30
# File '../lib/tournament.rb', line 28

def tournament_size
  @tournament_size
end

Instance Method Details

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

Select the individual from the population using the Tournament method.



44
45
46
47
48
49
50
# File '../lib/tournament.rb', line 44

def select_one population=self.population
  raise "Tournament: empty population" if population.empty?
  raise "Tournament: tournament_size bigger than population.size" if @tournament_size > population.size 
 
  @population = population
  select_one_internal     
end