Class: EvoSynth::Recombinations::ArithmeticCrossover
- Inherits:
-
Object
- Object
- EvoSynth::Recombinations::ArithmeticCrossover
- Defined in:
- lib/evosynth/operators/recombinations/arithmetic_crossover.rb
Overview
ARITHMETISCHER-CROSSOVER (Weicker page 83)
ATTENTION PLEASE! needs interpolation method to work:
interpolation_method.call(gene_one, gene_two, factor)
Constant Summary collapse
- INTERPOLATE_NUMBERS =
TODO: add extrapolation and other useful stuff here!
lambda { |gene_one, gene_two, factor| factor * gene_one + (1.0 - factor) * gene_two }
- INTERPOLATE_BOOLEANS =
lambda { |gene_one, gene_two, factor| EvoSynth.rand < factor ? gene_one : gene_two }
- EXTRAPOLATE_NUMBERS =
lambda { |gene_one, gene_two, factor| EvoSynth.rand_bool ? gene_one + factor * gene_two : gene_two + factor * gene_one}
Instance Method Summary collapse
-
#initialize(interpolation_function) ⇒ ArithmeticCrossover
constructor
A new instance of ArithmeticCrossover.
- #recombine(individual_one, individual_two) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(interpolation_function) ⇒ ArithmeticCrossover
Returns a new instance of ArithmeticCrossover.
41 42 43 |
# File 'lib/evosynth/operators/recombinations/arithmetic_crossover.rb', line 41 def initialize(interpolation_function) @interpolation_function = interpolation_function end |
Instance Method Details
#recombine(individual_one, individual_two) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/evosynth/operators/recombinations/arithmetic_crossover.rb', line 45 def recombine(individual_one, individual_two) child_one = individual_one.deep_clone child_two = individual_two.deep_clone shorter = EvoSynth::Recombinations.individual_with_shorter_genome(individual_one, individual_two) shorter.genome.each_with_index do |gene_one, index| gene_two = individual_two.genome[index] child_one.genome[index] = @interpolation_function.call(gene_one, gene_two, EvoSynth.rand) child_two.genome[index] = @interpolation_function.call(gene_two, gene_one, EvoSynth.rand) end [child_one, child_two] end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/evosynth/operators/recombinations/arithmetic_crossover.rb', line 60 def to_s "arithmetic crossover" end |