public
Last active

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Chromosome
attr_accessor :bitstring
 
def initialize (length, bitstring=nil)
@bitstring ||= rand(2**length+1).to_s(2).rjust(length, '0')
fitness
end
 
def self.random_chromosomes(length, number)
return Array.new(length) { Chromosome.new(length) }
end
 
def to_s
@bitstring
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.