Module: SinglePointCrossover
- Defined in:
- lib/charlie/list/list_crossover.rb
Overview
Simple single point crossover, returns two children.
Instance Method Summary collapse
Instance Method Details
#cross(parent1, parent2) ⇒ Object
6 7 8 9 10 |
# File 'lib/charlie/list/list_crossover.rb', line 6 def cross(parent1,parent2) cross_pt = rand(parent1.size+1) [ parent1.genes[0...cross_pt] + parent2.genes[cross_pt..-1], parent2.genes[0...cross_pt] + parent1.genes[cross_pt..-1]].map{|x| from_genes(x) } end |