Class: GeneGenie::SimpleGeneMutator
- Inherits:
-
Object
- Object
- GeneGenie::SimpleGeneMutator
- Defined in:
- lib/gene_genie/mutator/simple_gene_mutator.rb
Overview
A SimpleGeneMutator loops through each member of a hash, and has a 1% chance of swapping the value for another valid value (based on the template)
Instance Method Summary collapse
- #call(genes) ⇒ Object
-
#initialize(template, mutation_rate = 0.01) ⇒ SimpleGeneMutator
constructor
A new instance of SimpleGeneMutator.
Constructor Details
#initialize(template, mutation_rate = 0.01) ⇒ SimpleGeneMutator
Returns a new instance of SimpleGeneMutator.
7 8 9 10 |
# File 'lib/gene_genie/mutator/simple_gene_mutator.rb', line 7 def initialize(template, mutation_rate = 0.01) @template = template @mutation_rate = mutation_rate end |
Instance Method Details
#call(genes) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gene_genie/mutator/simple_gene_mutator.rb', line 12 def call(genes) genes.each_with_index do |hash, index| hash.each do |k, v| if rand < @mutation_rate hash[k] = rand(@template[index][k]) end end end genes end |