Class: ParetoGPSimplified

Inherits:
AlgorithmBase show all
Includes:
PhenotypicTruncation
Defined in:
../algorithm/paretogp_simplified.rb

Instance Attribute Summary (collapse)

Attributes included from PhenotypicTruncation

#duplicate_elimination, #shorten_individual

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?

Instance Attribute Details

- (Object) archive_size

Returns the value of attribute archive_size



8
9
10
# File '../algorithm/paretogp_simplified.rb', line 8

def archive_size
  @archive_size
end

- (Object) generations_per_cascade

Returns the value of attribute generations_per_cascade



8
9
10
# File '../algorithm/paretogp_simplified.rb', line 8

def generations_per_cascade
  @generations_per_cascade
end

- (Object) mutation_probability

Returns the value of attribute mutation_probability



8
9
10
# File '../algorithm/paretogp_simplified.rb', line 8

def mutation_probability
  @mutation_probability
end

- (Object) tournament_size

Returns the value of attribute tournament_size



8
9
10
# File '../algorithm/paretogp_simplified.rb', line 8

def tournament_size
  @tournament_size
end

Instance Method Details

- (Object) setup(config)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File '../algorithm/paretogp_simplified.rb', line 10

def setup config
  super

  @population_tourney = ParetoTourney.new 
  @population_tourney.tournament_size = @tournament_size

  @population = []

  @archive = load_or_init( @store, @archive_size )
 
  @steps = 0
  @generation = 0
  return @report       
end

- (Object) step



31
32
33
34
35
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
88
89
90
# File '../algorithm/paretogp_simplified.rb', line 31

def step
  @report.next       
  @report << "--------- step #{@steps += 1}, generation #{@generation}" 

   # init population   
  if @generation == 0
    @report << "initializing population"  
    @population = []
    init_population( @population, @population_size )   
  end

  # create a new population from the current one
  population_pipe = []
  archive_pipe = []
  new_population = [] 
  while new_population.size < @population_size

    population_pipe = @population_tourney.select_front @population while population_pipe.empty?
    archive_pipe = Util.permutate @archive while archive_pipe.empty?

    parent1, parent2 = [ population_pipe.shift, archive_pipe.shift ]
    chromozome1, chromozome2 = @crossover.crossover( parent1.genotype, parent2.genotype, parent1.track_support, parent2.track_support )     

    individual = @cfg.factory( 'individual', @mapper, chromozome1 )
    if individual.valid? and rand < @mutation_probability      
      chromozome1 = @mutation.mutation( chromozome1, individual.track_support )
      individual = @cfg.factory( 'individual', @mapper, chromozome1 ) 
    end
      
    new_population << individual if individual.valid?

    individual = @cfg.factory( 'individual', @mapper, chromozome2 ) 
    new_population << individual if individual.valid?
     
  end

  @evaluator.run new_population if defined? @evaluator

  @population = new_population
 
  # keep population extremes
  @population.first.objective_symbols.each do |obj|
    best = Pareto.objective_best( @population, @population.first.class, obj )
    @archive.push best
    @report['pop_best_' + obj.to_s] << best.send(obj)
  end

  if @generation == @generations_per_cascade 

    # archive merging     
    @archive = phenotypic_truncation( Pareto.nondominated( @archive ), @archive_size )

    @report.report @archive      
    @generation = 0
  else
    @generation += 1
  end # consolidation

  return @report 
end

- (Object) teardown



25
26
27
28
29
# File '../algorithm/paretogp_simplified.rb', line 25

def teardown
  @report << "--------- finished:"
  @store.save @archive
  return @report   
end