Class: SolutionSpaceMutationStrategy

Inherits:
MutationStrategy show all
Defined in:
lib/gimuby/genetic/solution/mutation_strategy/solution_space_mutation_strategy.rb

Instance Attribute Summary

Attributes inherited from MutationStrategy

#mutation_rate

Instance Method Summary collapse

Methods inherited from MutationStrategy

#mutate

Constructor Details

#initialize(mutation_rate = 0.01) ⇒ SolutionSpaceMutationStrategy

Returns a new instance of SolutionSpaceMutationStrategy.



5
6
7
8
9
10
11
# File 'lib/gimuby/genetic/solution/mutation_strategy/solution_space_mutation_strategy.rb', line 5

def initialize(mutation_rate = 0.01)
  super(mutation_rate)
  @default_min = nil
  @default_max = nil
  @mins = {}
  @maxs = {}
end

Instance Method Details

#perform_mutation(solution) ⇒ Object



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

def perform_mutation(solution)
  x_values = solution.get_solution_representation
  x_values = perform_mutation_from_representation(x_values)
  solution.set_solution_representation(x_values)
end

#set_max(max, index = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gimuby/genetic/solution/mutation_strategy/solution_space_mutation_strategy.rb', line 27

def set_max(max, index = nil)
  if index.nil?
    @default_max = max
  else
    @maxs[index] = max
  end
end

#set_min(min, index = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/gimuby/genetic/solution/mutation_strategy/solution_space_mutation_strategy.rb', line 19

def set_min(min, index = nil)
  if index.nil?
    @default_min = min
  else
    @mins[index] = min
  end
end