Created
July 5, 2012 19:04
-
-
Save Poincare/3055730 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 | |
attr_accessor :bitstring | |
attr_accessor :fitness | |
def generate_random(length) | |
i = 0 | |
@bitstring = "" | |
while i < length | |
@bitstring += rand(2).to_s | |
i += 1 | |
end | |
end | |
def self.get_random_chromosomes(length, number) | |
i = 0 | |
res = [] | |
while i < number | |
res.push(Chromosome.new(length)) | |
i += 1 | |
end | |
setFitnesses(res) | |
return res | |
end | |
def initialize(length, bitString = nil) | |
@length = length | |
if bitString == nil | |
generate_random(length) | |
else | |
@bitstring = bitString | |
end | |
end | |
end |
Thanks - I'm trying to get this on the article itself, but, I can't get a
hold of the editor
…On Fri, Jul 20, 2012 at 12:16 AM, Shannon < ***@***.*** > wrote:
Did a quick refactor, trying to make it more idiomatic Ruby:
https://gist.github.com/3145912
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/3055730
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did a quick refactor, trying to make it more idiomatic Ruby: https://gist.github.com/3145912