Class: EvoSynth::Evolvers::PopulationHillclimber

Inherits:
Object
  • Object
show all
Includes:
Evolver
Defined in:
lib/evosynth/evolvers/basic/population_hillclimber.rb

Overview

POPULATIONSBASIERTES-BINÄRES-HILLCLIMBING (Weicker Page 65)

Instance Attribute Summary

Attributes included from RunnableEvolver

#generations_computed

Instance Method Summary collapse

Methods included from ProfileUsingEvolver

#init_profile, #use_profile

Methods included from RunnableEvolver

#run_until, #run_until_fitness_reached, #run_until_generations_reached

Constructor Details

#initialize(profile) ⇒ PopulationHillclimber

Returns a new instance of PopulationHillclimber.



33
34
35
36
37
38
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 33

def initialize(profile)
	init_profile :mutation, :population, :evaluator
	use_profile profile

	@population.each { |individual| @evaluator.calculate_and_set_initial_fitness(individual) }
end

Instance Method Details

#best_solutionObject



44
45
46
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 44

def best_solution
	@population.best
end

#mutate(individual) ⇒ Object



60
61
62
63
64
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 60

def mutate(individual)
	child = @mutation.mutate(individual)
	@evaluator.calculate_and_set_fitness(child)
	child > individual ? child : individual
end

#next_generationObject



56
57
58
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 56

def next_generation
	@population.map! { |individual| mutate(individual) }
end

#return_resultObject



52
53
54
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 52

def return_result
	@population
end

#to_sObject



40
41
42
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 40

def to_s
	"population based hillclimber <mutation: #{@mutation}>"
end

#worst_solutionObject



48
49
50
# File 'lib/evosynth/evolvers/basic/population_hillclimber.rb', line 48

def worst_solution
	@population.worst
end