Class: AnswerFactory::Machines::PointCrossover
- Defined in:
- lib/machines/point_crossover.rb
Instance Attribute Summary
Attributes inherited from Machine
Instance Method Summary collapse
- #build(batch, overridden_options = {}) ⇒ Object (also: #generate)
Methods inherited from Machine
Constructor Details
This class inherits a constructor from AnswerFactory::Machines::Machine
Instance Method Details
#build(batch, overridden_options = {}) ⇒ Object Also known as: generate
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/machines/point_crossover.rb', line 10 def build(batch, ={}) raise ArgumentError, "PointCrossover#build cannot process a #{batch.class}" unless batch.kind_of?(Batch) = @options.merge() replicates = [:replicates] || 1 result = Batch.new number_of_parents = batch.length batch.each do |answer| replicates.times do parents = batch.sample(2) mom = parents[0] dad = parents[1] mom_point = Kernel.rand(mom.points)+1 dad_point = Kernel.rand(dad.points)+1 dad_code = dad.program[dad_point].blueprint baby = mom.replace_point_or_clone(mom_point,dad_code) baby_progress = [dad.progress, mom.progress].max + 1 result << Answer.new(baby, progress:baby_progress) end end return result end |