Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:3151578
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
class Chromosome
...
def cross(mate)
cs = crossover_site = rand(@bitstring.length-1)+1
mate.bitstring[cs..-1], @bitstring[cs..-1] = @bitstring[cs..-1], mate.bitstring[cs..-1]
end
 
def self.do_crossings(chrs, mates)
i = 0
completed = []
 
#not very idiomatic, but, the i variable is important
while i < chrs.length
 
#due to the symmetric nature of the data structure we're using
if completed.include? i
i += 1
next
end
chrs[i].cross(chrs[mates[i]])
 
completed.push(mates[i])
i += 1
end
return chrs
 
end
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.