Module: EvoSynth::Evolvers
- Defined in:
- lib/evosynth/evolvers/elitism.rb,
lib/evosynth/evolvers/evolver.rb,
lib/evosynth/evolvers/runnable_evolver.rb,
lib/evosynth/evolvers/basic/hillclimber.rb,
lib/evosynth/evolvers/basic/steady_state_ga.rb,
lib/evosynth/evolvers/profile_using_evolver.rb,
lib/evosynth/evolvers/basic/genetic_algorithm.rb,
lib/evosynth/evolvers/basic/memetic_algorithm.rb,
lib/evosynth/evolvers/local_search/local_search.rb,
lib/evosynth/evolvers/basic/population_hillclimber.rb,
lib/evosynth/evolvers/evolution_strategies/adaptive_es.rb,
lib/evosynth/evolvers/local_search/acceptance_threshold.rb,
lib/evosynth/evolvers/local_search/acceptance_hillclimber.rb,
lib/evosynth/evolvers/evolution_strategies/derandomized_es.rb,
lib/evosynth/evolvers/evolution_strategies/selfadaptive_es.rb,
lib/evosynth/evolvers/local_search/acceptance_great_deluge.rb,
lib/evosynth/evolvers/coevolutionary/balanced_coevolutionary.rb,
lib/evosynth/evolvers/local_search/acceptance_record_to_record.rb,
lib/evosynth/evolvers/coevolutionary/round_robin_coevolutionary.rb,
lib/evosynth/evolvers/local_search/acceptance_simulated_annealing.rb
Defined Under Namespace
Modules: Evolver, ProfileUsingEvolver, RunnableEvolver Classes: AdaptiveES, BalancedCoevolutionary, DerandomizedES, GeneticAlgorithm, Hillclimber, LocalSearch, MemeticAlgorithm, PopulationHillclimber, RoundRobinCoevolutionary, SelfAdaptiveES, SteadyStateGA
Class Method Summary collapse
-
.add_strong_elistism(evolver, n = 1) ⇒ Object
this function adds weak elistism to a evolver using instance_eval.
-
.add_weak_elistism(evolver) ⇒ Object
this function adds weak elistism to a evolver using instance_eval.
Class Method Details
.add_strong_elistism(evolver, n = 1) ⇒ Object
this function adds weak elistism to a evolver using instance_eval
strong elitism: copy best n parents into offspring population (replace worst n childrens)
TODO: add some elegance to this code ;-)
65 66 67 68 69 70 71 72 73 74 75 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/elitism.rb', line 65 def Evolvers.add_strong_elistism(evolver, n = 1) evolver.population rescue raise "Evolver not supported!" if (n == 1) evolver.instance_eval(" alias :original_next_generation :next_generation alias :original_to_s :to_s def next_generation best = population.best original_next_generation population.remove(population.worst) population.add(best) end def to_s '<< strong elitism >> ' + original_to_s end ") else evolver.instance_eval(" alias :original_next_generation :next_generation alias :original_to_s :to_s def next_generation best = population.best(#{n}) original_next_generation worst = population.worst(#{n}) worst.each { |individual| population.remove(individual) } best.each { |individual| population.add(individual) } end def to_s '<< strong elitism >> ' + original_to_s end ") end end |
.add_weak_elistism(evolver) ⇒ Object
this function adds weak elistism to a evolver using instance_eval
weak elitism: if fitness of childrens decreased, replace worst individual with best parent
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/evosynth/evolvers/elitism.rb', line 35 def Evolvers.add_weak_elistism(evolver) evolver.population rescue raise "Evolver not supported!" evolver.instance_eval(%q{ alias :original_next_generation :next_generation alias :original_to_s :to_s def next_generation best_individual = population.best original_next_generation if population.best < best_individual population.remove(population.worst) population.add(best_individual) end end def to_s "<< weak elitism >> " + original_to_s end }) end |