Class: EvoSynth::Selections::TournamentSelection

Inherits:
Object
  • Object
show all
Defined in:
lib/evosynth/operators/selections/tournament_selection.rb

Overview

TURNIER-SELEKTION (Weicker Page 76)

Constant Summary collapse

DEFAULT_ENEMIES =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enemies = DEFAULT_ENEMIES) ⇒ TournamentSelection



37
38
39
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 37

def initialize(enemies = DEFAULT_ENEMIES)
  @enemies = enemies
end

Instance Attribute Details

#enemiesObject

Returns the value of attribute enemies.



33
34
35
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 33

def enemies
  @enemies
end

Instance Method Details

#select(population, select_count = 1) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 41

def select(population, select_count = 1)
  selected_population = EvoSynth::Population.new

  select_count.to_i.times do
    individual = fight(population, population[EvoSynth.rand(population.size)])
    selected_population.add(individual)
  end

  selected_population
end

#to_sObject



52
53
54
# File 'lib/evosynth/operators/selections/tournament_selection.rb', line 52

def to_s
  "tournament selection <enemies: #{@enemies}>"
end