Class: EvoSynth::Evolvers::MemeticAlgorithm

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

Overview

MEMETISCHER-ALGORITHMUS (Weicker Page 165) see also: en.wikipedia.org/wiki/Memetic_algorithm for later improvments

Constant Summary collapse

DEFAULT_CHILD_FACTOR =
0.5
DEFAULT_RECOMBINATION_PROBABILITY =
1.0
DEFAULT_RECOMBINATION =
EvoSynth::Recombinations::KPointCrossover.new(2)
DEFAULT_INDIVIDUAL_LEARNING_GOAL =
->(gen, best) { gen >= 10 }
DEFAULT_INDIVIDUAL_LEARNING_PROBABILITY =
0.75
DEFAULT_SELECTION =
EvoSynth::Selections::FitnessProportionalSelection.new
DEFAULT_SUBEVOLVER_CREATOR =
->(profile) { EvoSynth::Evolvers::LocalSearch.new(profile) }

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

Returns a new instance of MemeticAlgorithm.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 42

def initialize(profile)
	init_profile :population,
		:evaluator,
	    :mutation,
		:recombination						=> DEFAULT_RECOMBINATION,
		:parent_selection					=> DEFAULT_SELECTION,
		:enviromental_selection				=> DEFAULT_SELECTION,
		:child_factor						=> DEFAULT_CHILD_FACTOR,
		:recombination_probability			=> DEFAULT_RECOMBINATION_PROBABILITY,
	    :subevolver_creator					=> DEFAULT_SUBEVOLVER_CREATOR,
		:individual_learning_goal			=> DEFAULT_INDIVIDUAL_LEARNING_GOAL,
		:individual_learning_probability	=> DEFAULT_INDIVIDUAL_LEARNING_PROBABILITY

	use_profile profile

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

Instance Method Details

#best_solutionObject



64
65
66
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 64

def best_solution
	@population.best
end

#next_generationObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 76

def next_generation
	selected_population = @parent_selection.select(@population, @population.size * @child_factor)
	child_population = EvoSynth::Population.new

	selected_population.each_index do |index_one|
		index_two = (index_one + 1) % selected_population.size

		if EvoSynth.rand < @recombination_probability
			child_one, child_two = @recombination.recombine(selected_population[index_one], selected_population[index_two])
		else
			child_one = selected_population[index_one]
			child_two = selected_population[index_two]
		end

		child_population.add(@mutation.mutate(child_one))
		child_population.add(@mutation.mutate(child_two))
	end

	child_population.map! do |child|
		if EvoSynth.rand < @individual_learning_probability
			@profile.individual = child
			subevolver = @subevolver_creator.call(@profile)
			subevolver.run_until &@individual_learning_goal
		else
			child
		end
	end

	child_population.each { |individual| @evaluator.calculate_and_set_fitness(individual) }
	@population = @enviromental_selection.select(child_population, @population.size)
end

#return_resultObject



72
73
74
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 72

def return_result
	@population
end

#to_sObject



60
61
62
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 60

def to_s
	"memetic algoritm"
end

#worst_solutionObject



68
69
70
# File 'lib/evosynth/evolvers/basic/memetic_algorithm.rb', line 68

def worst_solution
	@population.worst
end