Module: MatrixUniformCrossover
- Defined in:
- lib/charlie/list/matrix.rb
Overview
Uniform crossover for matrices
Instance Method Summary collapse
Instance Method Details
#cross(parent1, parent2) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/charlie/list/matrix.rb', line 48 def cross(parent1,parent2) tc1 = []; tc2=[] g1 = parent1.genes; g2 = parent2.genes g1.each_with_index{|rg1,ri| tc1 << (r1=[]); tc2 << (r2=[]) rg2 = g2[ri]; rg1.each_with_index{|e,i| if rand(2).zero? r1 << e; r2 << rg2[i] else r2 << e; r1 << rg2[i] end } } [tc1,tc2].map{|x| from_genes(x) } end |