Module: PhenotypicTruncation

Included in:
Alps, AlpsStrict, Generational, Nsga2, ParetoGPSimplified, Spea2, Spea2Ranking
Defined in:
../algorithm/support/phenotypic_truncation.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) duplicate_elimination

Returns the value of attribute duplicate_elimination



4
5
6
# File '../algorithm/support/phenotypic_truncation.rb', line 4

def duplicate_elimination
  @duplicate_elimination
end

- (Object) shorten_individual

Returns the value of attribute shorten_individual



4
5
6
# File '../algorithm/support/phenotypic_truncation.rb', line 4

def shorten_individual
  @shorten_individual
end

Instance Method Details

- (Object) eliminate_duplicates(population)



27
28
29
30
31
32
# File '../algorithm/support/phenotypic_truncation.rb', line 27

def eliminate_duplicates population
  uniq = {}
  population.each { |individual| uniq[individual.phenotype] = individual }
  population = uniq.values
  return population
end

- (Object) phenotypic_truncation(population, max_size)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File '../algorithm/support/phenotypic_truncation.rb', line 6

def phenotypic_truncation( population, max_size )
  # prepare phenotypic hash
  uniq = {}
  population.each do |individual|
    individual.shorten_chromozome = @shorten_individual
    slot = uniq.fetch( individual.phenotype, [] ) 
    slot.push individual
    uniq[individual.phenotype] = slot
  end

  # trim archive size, decimate duplicate phenotypes first
  current_size = uniq.values.flatten.size
  while current_size > max_size 
    candidate = uniq.values.max {|a,b| a.size <=> b.size }
    break if candidate.size == 1
    candidate.pop
    current_size -= 1
  end
  uniq.values.flatten
end