Class: Nsga2
- Inherits:
-
AlgorithmBase
- Object
- AlgorithmBase
- Nsga2
- Includes:
- Breed, PhenotypicTruncation
- Defined in:
- ../algorithm/nsga2.rb
Instance Attribute Summary (collapse)
-
- (Object) inject
Returns the value of attribute inject.
-
- (Object) shorten_individual
Returns the value of attribute shorten_individual.
Attributes included from PhenotypicTruncation
Attributes inherited from AlgorithmBase
#init, #population_size, #probabilities, #termination
Instance Method Summary (collapse)
Methods included from PhenotypicTruncation
#eliminate_duplicates, #phenotypic_truncation
Methods inherited from AlgorithmBase
Instance Attribute Details
- (Object) inject
Returns the value of attribute inject
83 84 85 |
# File '../algorithm/nsga2.rb', line 83 def inject @inject end |
- (Object) shorten_individual
Returns the value of attribute shorten_individual
83 84 85 |
# File '../algorithm/nsga2.rb', line 83 def shorten_individual @shorten_individual end |
Instance Method Details
- (Object) setup(config)
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File '../algorithm/nsga2.rb', line 69 def setup config super @selection = Nsga2BinaryTournament.new @dom_sort = Dominance.new @dom_sort.at_least = @population_size @population = load_or_init( @store, @population_size ) @report.next return @report end |
- (Object) step
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File '../algorithm/nsga2.rb', line 85 def step @report.next @report << "--------- step #{@steps += 1}" depth = 0 parent_population = [] front_report = [] Nsga2Individual.uniq_clear @dom_sort.layers( @population ).each do |layer| front = Crowding.distance( layer ) { |orig, cdist| Nsga2Individual.new( orig, depth, cdist ) } front.each { |individual| individual.cache_uniq } depth += 1 empty_slots = @population_size - parent_population.size front_report << front.size if empty_slots >= front.size parent_population.concat front else front.sort! # { |a,b| b.crowding <=> a.crowding } parent_population.concat front[0...empty_slots] end end @report['fronts_sizes'] << front_report.inspect @population = parent_population.map do |individual| individual.orig.shorten_chromozome = @shorten_individual individual.orig end @report.report @population # reporting @cross, @injections, @mutate = 0, 0, 0, 0 sizes = [] while @population.size < 2*@population_size @selection.population = parent_population new_populaton = breed_by_selector_no_report( @selection, @population_size ) @population.concat new_populaton @population = eliminate_duplicates @population sizes << @population.size end @report['eliminated_sizes'] << sizes @report['numof_crossovers'] << @cross @report['numof_injections'] << @injections @report['numof_mutations'] << @mutate @report['time_eval'] << @time_eval @report['numof_evaluations'] << @evaluator.jobs_processed if defined? @evaluator return @report end |