class Evopop::Dna
Represents a Dna
structure, like an array of floating point values
Attributes
dna[RW]
dna_len[RW]
max_mutation[RW]
max_range[RW]
min_mutation[RW]
min_range[RW]
Public Class Methods
create(min_range, max_range, min_mutation, max_mutation, dna)
click to toggle source
# File lib/evopop/dna.rb, line 23 def self.create(min_range, max_range, min_mutation, max_mutation, dna) new_dna = new(min_range, max_range, min_mutation, max_mutation, dna.size) new_dna.dna = dna new_dna end
new(min_range, max_range, min_mutation, max_mutation, dna_len)
click to toggle source
# File lib/evopop/dna.rb, line 8 def initialize(min_range, max_range, min_mutation, max_mutation, dna_len) # TODO: Extract these to a DnaProperties class or something so we don't # have to couple parameter passsing so much. @min_range = min_range @max_range = max_range @min_mutation = min_mutation @max_mutation = max_mutation @dna = [] @dna_len = dna_len dna_len_range.each do @dna << random_dna_val end end
Public Instance Methods
==(other)
click to toggle source
# File lib/evopop/dna.rb, line 65 def ==(other) @dna == other.dna end
[](key)
click to toggle source
# File lib/evopop/dna.rb, line 57 def [](key) @dna[key] end
[]=(key, value)
click to toggle source
# File lib/evopop/dna.rb, line 61 def []=(key, value) @dna[key] = value end
dna_len_range()
click to toggle source
# File lib/evopop/dna.rb, line 29 def dna_len_range 0...@dna_len end
drop(ordinal)
click to toggle source
# File lib/evopop/dna.rb, line 53 def drop(ordinal) @dna.drop(ordinal) end
length()
click to toggle source
# File lib/evopop/dna.rb, line 45 def length @dna.length end
mutate(i)
click to toggle source
# File lib/evopop/dna.rb, line 41 def mutate(i) @dna[i] += [random_mutation_val, -1 * random_mutation_val].sample end
random_dna_val()
click to toggle source
# File lib/evopop/dna.rb, line 33 def random_dna_val Random.rand(@min_range...@max_range) end
random_mutation_val()
click to toggle source
# File lib/evopop/dna.rb, line 37 def random_mutation_val Random.rand(@min_mutation...@max_mutation) end
take(num)
click to toggle source
# File lib/evopop/dna.rb, line 49 def take(num) @dna.take(num) end
to_s()
click to toggle source
# File lib/evopop/dna.rb, line 69 def to_s @dna.to_s end