Class: EvoSynth::Evolvers::Hillclimber

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

Overview

BINÄRES-HILLCLIMBING (Weicker Page 49)

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) ⇒ Hillclimber

Returns a new instance of Hillclimber.



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

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

	@evaluator.calculate_and_set_initial_fitness(@individual)
end

Instance Method Details

#best_solutionObject



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

def best_solution
	@individual
end

#next_generationObject



56
57
58
59
60
# File 'lib/evosynth/evolvers/basic/hillclimber.rb', line 56

def next_generation
	child = @mutation.mutate(@individual)
	@evaluator.calculate_and_set_fitness(child)
	@individual = child if child > @individual
end

#return_resultObject



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

def return_result
	@individual
end

#to_sObject



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

def to_s
	"hillclimber <mutation: #{@mutation}, individual: #{@individual}>"
end

#worst_solutionObject



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

def worst_solution
	@individual
end