Created
July 20, 2012 16:04
-
-
Save Poincare/3151578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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