Create a gist now

Instantly share code, notes, and snippets.

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