Class: EvoSynth::Mutations::ShiftingMutation
- Inherits:
-
Object
- Object
- EvoSynth::Mutations::ShiftingMutation
- Defined in:
- lib/evosynth/operators/mutations/shifting_mutation.rb
Overview
The ShiftingMutation shifts a random range of genes by one index in the genome. It is based on VERSCHIEBENDE-MUTATION (Weicker 2007, page 132).
This mutations does not destroy permutations.
Instance Method Summary collapse
-
#mutate(individual) ⇒ Object
:call-seq: mutate(Individual) -> Individual.
-
#to_s ⇒ Object
:call-seq: to_s -> string.
Instance Method Details
#mutate(individual) ⇒ Object
:call-seq: mutate(Individual) -> Individual
Returns a clone of a given individual and shifts a random range of genes by one index in the genome of this clone.
m = ShiftingMutation.new
m.mutate(a_individual) #=> a_new_individual
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/evosynth/operators/mutations/shifting_mutation.rb', line 44 def mutate(individual) mutated = individual.deep_clone genome = mutated.genome index_one = EvoSynth.rand(genome.size) index_two = EvoSynth.rand(genome.size) return mutated if index_one == index_two shift_genome(index_one, index_two, genome) mutated end |
#to_s ⇒ Object
:call-seq: to_s -> string
Returns description of this mutation
m = ShiftingMutation.new
m.to_s #=> "shifting muation"
64 65 66 |
# File 'lib/evosynth/operators/mutations/shifting_mutation.rb', line 64 def to_s "shifting muation" end |