Class: Evolvable::Evolution
- Inherits:
-
Object
- Object
- Evolvable::Evolution
- Extended by:
- Forwardable
- Defined in:
- lib/evolvable/evolution.rb
Overview
Evolution moves a population from one generation to the next. It runs in three steps: selection, combination, and mutation. You can swap out any step with your own strategy.
Default pipeline:
- Selection – keep the most fit evolvables
- Combination – create offspring by recombining genes
- Mutation – add random variation to preserve diversity
Instance Attribute Summary collapse
-
#combination ⇒ Object
Returns the value of attribute combination.
-
#mutation ⇒ Object
Returns the value of attribute mutation.
-
#selection ⇒ Object
Returns the value of attribute selection.
Instance Method Summary collapse
-
#call(population) ⇒ Evolvable::Population
Executes the evolution process on the population.
-
#initialize(selection: Selection.new, combination: GeneCombination.new, mutation: Mutation.new) ⇒ Evolution
constructor
Initializes a new evolution object.
Constructor Details
#initialize(selection: Selection.new, combination: GeneCombination.new, mutation: Mutation.new) ⇒ Evolution
Initializes a new evolution object.
25 26 27 28 29 30 31 |
# File 'lib/evolvable/evolution.rb', line 25 def initialize(selection: Selection.new, combination: GeneCombination.new, mutation: Mutation.new) @selection = selection @combination = combination @mutation = mutation end |
Instance Attribute Details
#combination ⇒ Object
Returns the value of attribute combination.
33 34 35 |
# File 'lib/evolvable/evolution.rb', line 33 def combination @combination end |
#mutation ⇒ Object
Returns the value of attribute mutation.
33 34 35 |
# File 'lib/evolvable/evolution.rb', line 33 def mutation @mutation end |
#selection ⇒ Object
Returns the value of attribute selection.
33 34 35 |
# File 'lib/evolvable/evolution.rb', line 33 def selection @selection end |
Instance Method Details
#call(population) ⇒ Evolvable::Population
Executes the evolution process on the population. Applies selection, combination, and mutation in sequence.
74 75 76 77 78 79 |
# File 'lib/evolvable/evolution.rb', line 74 def call(population) selection.call(population) combination.call(population) mutation.call(population) population end |