Class: Evolvable::UniformCrossover

Inherits:
Object
  • Object
show all
Defined in:
lib/evolvable/uniform_crossover.rb

Overview

Randomly chooses a gene from one of the parents for each gene position.

Instance Method Summary collapse

Instance Method Details

#call(population) ⇒ Object


8
9
10
11
# File 'lib/evolvable/uniform_crossover.rb', line 8

def call(population)
  population.evolvables = new_evolvables(population, population.size)
  population
end

#new_evolvables(population, count) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/evolvable/uniform_crossover.rb', line 13

def new_evolvables(population, count)
  parent_genome_cycle = population.new_parent_genome_cycle
  Array.new(count) do
    genome = build_genome(parent_genome_cycle.next)
    population.new_evolvable(genome: genome)
  end
end