Class: Evolvable::UniformCrossover

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

Overview

Chooses genes independently at each position, selecting randomly from either parent with equal probability. No segments are preserved—each gene is treated in isolation.

Best for:

  • Problems where gene order doesn't matter
  • High genetic diversity and exploration
  • Complex interdependencies across traits

Uniform crossover is especially effective when good traits are scattered across the genome.

Set your population to use this strategy during initialization with:

population = MyEvolvable.new_population(
  combination: Evolvable::UniformCrossover.new
)

Or update an existing population:

population.combination = Evolvable::UniformCrossover.new

Instance Method Summary collapse

Instance Method Details

#call(population) ⇒ Object



32
33
34
35
# File 'lib/evolvable/uniform_crossover.rb', line 32

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

#new_evolvables(population, count) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/evolvable/uniform_crossover.rb', line 37

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