lib/individual.rb
# Shuffle gene between the two indices.

Shuffle gene between the two indices.
Shuffle gene between the two indices .
def scramble_mutation(gene_ary)
    idx1 = rand(gene_ary.size)
    idx2 = idx1 
    while (idx1 == idx2)
      idx2 = rand(gene_ary.size)
    end
    if idx1 > idx2 
      tmp = idx1
      idx1 = idx2
      idx2 = tmp
    end
    tmp = gene_ary.slice!(idx1, (idx2 - idx1 + 1))
    tmp.shuffle!
    gene_ary.insert(idx1,tmp).flatten!
    return gene_ary
  end
def scramble_mutation ( gene_ary ) idx1 = rand ( gene_ary . size ) idx2 = idx1 while ( idx1 == idx2 ) idx2 = rand ( gene_ary . size ) end if idx1 > idx2 tmp = idx1 idx1 = idx2 idx2 = tmp end tmp = gene_ary . slice! ( idx1 , ( idx2 - idx1 + 1 ) ) tmp . shuffle! gene_ary . insert ( idx1 , tmp ) . flatten! return gene_ary end
Shuffle gene between the two indices.
Shuffle gene between the two indices .
# sort indicis.

gene_ary
<not_specific>