Class: Alps

Inherits:
AlgorithmBase show all
Includes:
Elitism, PhenotypicTruncation
Defined in:
../algorithm/alps.rb

Instance Attribute Summary (collapse)

Attributes included from PhenotypicTruncation

#duplicate_elimination, #shorten_individual

Attributes included from Elitism

#elite_size

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

#finished?, #teardown

Instance Attribute Details

- (Object) age_gap

Returns the value of attribute age_gap



14
15
16
# File '../algorithm/alps.rb', line 14

def age_gap
  @age_gap
end

- (Object) aging_scheme

Returns the value of attribute aging_scheme



14
15
16
# File '../algorithm/alps.rb', line 14

def aging_scheme
  @aging_scheme
end

- (Object) layer_diagnostic

Returns the value of attribute layer_diagnostic



14
15
16
# File '../algorithm/alps.rb', line 14

def layer_diagnostic
  @layer_diagnostic
end

- (Object) max_layers

Returns the value of attribute max_layers



14
15
16
# File '../algorithm/alps.rb', line 14

def max_layers
  @max_layers
end

Instance Method Details

- (Object) setup(config)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File '../algorithm/alps.rb', line 16

def setup config
  super
   
  @max_layer_size = @population_size.divmod( @max_layers ).first   

  AlpsIndividual.age_gap @age_gap
  AlpsIndividual.aging_scheme @aging_scheme
  AlpsIndividual.layers @max_layers
  @report['age_limits'] << AlpsIndividual.age_limits.inspect

  @population = load_or_init( @store, @max_layer_size )

  init_elitism @max_layer_size
  
  evaluate_population

  @report.next    
  return @report    
end

- (Object) step



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File '../algorithm/alps.rb', line 36

def step

  @report.next 
  @report << "--------- step #{@steps += 1}"
  @report.report @population

  # sort @population's individuals into all_layers
  all_layers = []
  @population.each do |individual|
    index = individual.layer
    all_layers << [] while index >= all_layers.size
    all_layers[index] << individual 
  end

  # restart junior population each @age_gap   
  if @steps.divmod( @age_gap+2 ).last == 0
    @report << '------ restarting the first layer (age_gap)'
    all_layers[0] = init_population( [], @max_layer_size ) 
  end

  # discard empty layers
  all_layers.delete_if { |layer| layer.empty? }

  # phenotype duplicate elimination
  @report['layer_sizes'] << (all_layers.map { |layer| layer.size }).inspect
  if @duplicate_elimination
    all_layers.map! { |layer| eliminate_duplicates layer }
    @report['layer_sizes_pde'] << (all_layers.map { |layer| layer.size }).inspect    
  end

  # layer diagnostic
  all_layers.each_with_index do |layer,index| 
    layer.first.objective_symbols.each do |objective|     
      values = layer.map { |individual| individual.send(objective) }   
      min, max, avg, n = Util.statistics values  
      @report["layer_#{index}_#{objective}"] << "min: #{min} max: #{max} avg: #{avg} n: #{n}"
    end
  end if @layer_diagnostic

  # breed @population from adjacent all_layers
  @population = [] 
  all_layers.each_with_index do |layer,index|
    parents = layer.clone
    parents.concat all_layers[index-1] if index > 0
    @population.concat breed( parents )
    @population.concat cream( layer )
  end
 
  evaluate_population

  return @report
end