Class: EvoSynth::Evolvers::SteadyStateGA
- Inherits:
-
Object
- Object
- EvoSynth::Evolvers::SteadyStateGA
show all
- Includes:
- Evolver
- Defined in:
- lib/evosynth/evolvers/basic/steady_state_ga.rb
Overview
STEADY-STATE-GA (Weicker Page 129)
Constant Summary
collapse
- DEFAULT_SELECTION =
EvoSynth::Selections::FitnessProportionalSelection.new
- DEFAULT_RECOMBINATION =
EvoSynth::Recombinations::OnePointCrossover.new
- DEFAULT_RECOMBINATION_PROBABILITY =
0.75
Instance Attribute Summary
#generations_computed
Instance Method Summary
collapse
#init_profile, #use_profile
#run_until, #run_until_fitness_reached, #run_until_generations_reached
Constructor Details
Returns a new instance of SteadyStateGA.
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 37
def initialize(profile)
init_profile :population,
:evaluator,
:mutation,
:parent_selection => DEFAULT_SELECTION,
:recombination => DEFAULT_RECOMBINATION,
:recombination_probability => DEFAULT_RECOMBINATION_PROBABILITY
use_profile profile
@population.each { |individual| @evaluator.calculate_and_set_initial_fitness(individual) }
end
|
Instance Method Details
#best_solution ⇒ Object
54
55
56
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 54
def best_solution
@population.best
end
|
#next_generation ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 66
def next_generation
parents = @parent_selection.select(@population, 2)
if EvoSynth.rand < @recombination_probability
child = @recombination.recombine(parents[0], parents[1])[0]
else
child = parents[1]
end
child = @mutation.mutate(child)
@evaluator.calculate_and_set_fitness(child)
@population.remove(@population.worst)
@population.add(child)
end
|
#return_result ⇒ Object
62
63
64
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 62
def return_result
@population
end
|
#to_s ⇒ Object
50
51
52
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 50
def to_s
"steady-state genetic algoritm <mutation: #{@mutation}, parent selection: #{@parent_selection}, recombination: #{@recombination}>"
end
|
#worst_solution ⇒ Object
58
59
60
|
# File 'lib/evosynth/evolvers/basic/steady_state_ga.rb', line 58
def worst_solution
@population.worst
end
|