lib/individual.rb
# Children are inherit each of elements of gene from parent1, 2 in 50%.

Children are inherit each of elements of gene from parent1, 2 in 50%.
Children are inherit each of elements of gene from parent1 2 in 50% .
def uniform_crossover(gene1, gene2)
    if gene1.size != gene2.size
      raise "Different gene size."
    end
    tmp1 = gene1.dup
    tmp2 = gene2.dup
    tmp1.size.times do |i|
      if rand(2) == 0  
        tmp = tmp1[i]
        tmp1[i] = tmp2[i]
        tmp2[i] = tmp
      end
    end
    return tmp1, tmp2
  end
def uniform_crossover ( gene1 , gene2 ) if gene1 . size != gene2 . size raise "Different gene size." end tmp1 = gene1 . dup tmp2 = gene2 . dup tmp1 . size . times do | i | if rand ( 2 ) == 0 tmp = tmp1 [ i ] tmp1 [ i ] = tmp2 [ i ] tmp2 [ i ] = tmp end end return tmp1 , tmp2 end
Children are inherit each of elements of gene from parent1, 2 in 50%.
Children are inherit each of elements of gene from parent1 2 in 50% .
# 0 is returned in 50%.

gene1
<not_specific>
gene2
<not_specific>