Class: MutationStrategy
- Inherits:
-
Object
- Object
- MutationStrategy
- Defined in:
- lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#mutation_rate ⇒ Object
Returns the value of attribute mutation_rate.
Instance Method Summary collapse
-
#initialize(mutation_rate = 0.01) ⇒ MutationStrategy
constructor
A new instance of MutationStrategy.
- #mutate(solution) ⇒ Object
- #perform_mutation(solution) ⇒ Object
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_rate ⇒ Object
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
18 19 20 |
# File 'lib/gimuby/genetic/solution/mutation_strategy/mutation_strategy.rb', line 18 def perform_mutation(solution) raise NotImplementedError end |