Class: Spea2Ranking
- Inherits:
-
Ranking
- Object
- Ranking
- Spea2Ranking
- Includes:
- PhenotypicTruncation
- Defined in:
- ../algorithm/spea2.rb
Instance Attribute Summary
Attributes included from PhenotypicTruncation
#duplicate_elimination, #shorten_individual
Instance Method Summary (collapse)
- - (Object) environmental_selection(max_size)
-
- (Spea2Ranking) initialize
constructor
A new instance of Spea2Ranking.
- - (Object) population=(pop)
- - (Object) rank(selected)
Methods included from PhenotypicTruncation
#eliminate_duplicates, #phenotypic_truncation
Constructor Details
- (Spea2Ranking) initialize
A new instance of Spea2Ranking
9 10 11 12 |
# File '../algorithm/spea2.rb', line 9 def initialize @dominance = Dominance.new @reranker = Ranking.new( :spea, :minimize ) end |
Instance Method Details
- (Object) environmental_selection(max_size)
25 26 27 28 29 30 |
# File '../algorithm/spea2.rb', line 25 def environmental_selection max_size valid_population = @ranked_pop.find_all { |individual| individual.original.valid? } valid_population.sort! {|a,b| a.spea <=> b.spea } limited_population = valid_population[ 0...max_size ].map { |individual| individual.original } phenotypic_truncation( limited_population, 0 ) end |
- (Object) population=(pop)
14 15 16 |
# File '../algorithm/spea2.rb', line 14 def population= pop @ranked_pop = @dominance.rank_count pop end |
- (Object) rank(selected)
18 19 20 21 22 23 |
# File '../algorithm/spea2.rb', line 18 def rank selected rank_selection = selected.map { |orig| @ranked_pop.find { |r| r.original == orig } } reranked = @reranker.rank( rank_selection ) reranked.each { |field| field.original = field.original.original } reranked end |