Class: EvoSynth::Mutations::ShiftingMutation

Inherits:
Object
  • Object
show all
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

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_sObject

: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