lib/individual.rb
# TWORS Mutation which is select two elements and exchange them.
# For example, [1,2,3,4,5,6] -> [1,4,3,2,5,6] in which 2 and 4 are exchanged

TWORS Mutation which is select two elements and exchange them.
TWORS Mutation which is select two elements and exchange them .
def twors_mutation(gene_ary)  
    idx1 = rand(gene_ary.size)
    idx2 = rand(gene_ary.size)
    while idx1 == idx2
      idx2 = rand(gene_ary.size)
    end
    tmp = gene_ary[idx1]
    gene_ary[idx1] = gene_ary[idx2]
    gene_ary[idx2] = tmp
    return gene_ary
  end
def twors_mutation ( gene_ary ) idx1 = rand ( gene_ary . size ) idx2 = rand ( gene_ary . size ) while idx1 == idx2 idx2 = rand ( gene_ary . size ) end tmp = gene_ary [ idx1 ] gene_ary [ idx1 ] = gene_ary [ idx2 ] gene_ary [ idx2 ] = tmp return gene_ary end
TWORS Mutation which is select two elements and exchange them.
TWORS Mutation which is select two elements and exchange them .
# for TSP

gene_ary
<not_specific>