Class: MutationStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mutation_rate = 0.01) ⇒ MutationStrategy

Returns a new instance of MutationStrategy.



5
6
7
# File 'lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb', line 5

def initialize(mutation_rate = 0.01)
  @mutation_rate = mutation_rate
end

Instance Attribute Details

#mutation_rateObject

Returns the value of attribute mutation_rate.



9
10
11
# File 'lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb', line 9

def mutation_rate
  @mutation_rate
end

Instance Method Details

#mutate(solution) ⇒ Object



11
12
13
14
15
16
# File 'lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb', line 11

def mutate(solution)
  if rand < @mutation_rate
    perform_mutation(solution)
    solution.reset_fitness_state
  end
end

#perform_mutation(solution) ⇒ Object

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb', line 18

def perform_mutation(solution)
  raise NotImplementedError
end