Class: Wallace::Evolver
- Inherits:
-
Object
- Object
- Wallace::Evolver
- Defined in:
- lib/core/evolver.rb
Overview
Steady-state vs. Generational
Instance Method Summary collapse
-
#evolve ⇒ Object
Conducts the described evolutionary algorithm until the termination criteria is met.
-
#initialize(rng, population, evaluator, termination) ⇒ Evolver
constructor
Constructs a new evolver.
Constructor Details
#initialize(rng, population, evaluator, termination) ⇒ Evolver
Constructs a new evolver.
Parameters:
-
rng, the random number generator to use for stochastic processes.
-
population, the population to evolve.
-
evaluator, the evaluator to use to determine the fitness of individuals.
-
breeder, the breeder to use to create individuals for successive generations.
-
migrator, the migrator to use to exchange individuals between sub-populations.
-
termination, the termination criteria for the evolution.
13 14 15 16 17 18 19 20 |
# File 'lib/core/evolver.rb', line 13 def initialize(rng, population, evaluator, termination) @rng = rng @population = population @evaluator = evaluator @termination = termination @evaluator = evaluator @state = nil end |
Instance Method Details
#evolve ⇒ Object
Conducts the described evolutionary algorithm until the termination criteria is met. Upon meeting the termination criteria, the best individual found from the entire run is returned.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/core/evolver.rb', line 25 def evolve # Initialise and evaluate the population. @population.fresh!(@rng) @evaluator.process!(@rng, @population) @state = Wallace::State.new(@population) # Continue the evolution unless the termination condition has been met. until @termination.finished?(@state) @migrator.migrate!(@rng, @population) unless @migrator.nil? @population.breed!(@rng) @evaluator.process!(@rng, @population) @state.next! #puts "#{@state.best.to_s} = #{@state.best.fitness.value}" puts "#{@state.generations}: #{@state.best.fitness.value} (#{@state.best.data.length})" end # Return the best individual from the run. return @state.best end |