Class: AlgorithmBase

Inherits:
Object
  • Object
show all
Defined in:
../algorithm/support/algorithm_base.rb

Direct Known Subclasses

AgeHierarchyTree, Alps, AlpsStrict, Generational, MuLambda, Nsga2, ParetoGPSimplified, Spea2, SteadyState

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) init

Returns the value of attribute init



10
11
12
# File '../algorithm/support/algorithm_base.rb', line 10

def init
  @init
end

- (Object) population_size

Returns the value of attribute population_size



10
11
12
# File '../algorithm/support/algorithm_base.rb', line 10

def population_size
  @population_size
end

- (Object) probabilities

Returns the value of attribute probabilities



10
11
12
# File '../algorithm/support/algorithm_base.rb', line 10

def probabilities
  @probabilities
end

- (Object) termination

Returns the value of attribute termination



10
11
12
# File '../algorithm/support/algorithm_base.rb', line 10

def termination
  @termination
end

Instance Method Details

- (Boolean) finished?

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File '../algorithm/support/algorithm_base.rb', line 57

def finished?
  t1 = Time.now
  @time_total += (t1 - @time_now)
  @time_now = t1
  @report['time_total'] << @time_total 

  max_steps = @termination['max_steps']
  on_individual = @termination['on_individual']
  max_evaluations = @termination['max_evaluations']

  if ( not max_steps.nil? and @steps >= max_steps.to_i ) or
     ( not on_individual.nil? and @population.detect { |individual| individual.send on_individual } ) or
     ( not max_evaluations.nil? and defined?( @evaluator ) and @evaluator.jobs_processed >= max_evaluations.to_i )

    @report.report @population

    return true
  end
  return false
end

- (Object) setup(config)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File '../algorithm/support/algorithm_base.rb', line 12

def setup config
  @cfg = config
  @report = @cfg.factory('report')
  @report << "--------- initialization:"
  
  @store = @cfg.factory('store')
  @grammar = @cfg.factory('grammar')
  @mapper = @cfg.factory('mapper', @grammar)
  @crossover = @cfg.factory('crossover')
  @mutation = @cfg.factory('mutation', @grammar)   

  unless @cfg['selection'].nil?
    @selection = @cfg['selection_rank'].nil? ? 
                 @cfg.factory('selection') : 
                 @cfg.factory('selection', @cfg.factory('selection_rank') ) 
  end

 
  @evaluator = @cfg.factory('evaluator') unless @cfg['evaluator'].nil? 

  unless @cfg['codon'].nil?
    codon = @cfg.factory('codon')
    codon.grammar = @grammar if codon.respond_to? :grammar=

    @mapper.codon = codon if @mapper.respond_to? :codon= 
    @crossover.codon = codon if @crossover.respond_to? :codon=        
    @mutation.codon = codon if @mutation.respond_to? :codon= 
  end

  @time_total = 0
  @time_eval = 0 
  @time_now = Time.now

  @steps = 0
  @invalid_individuals = 0
  
  return @report    
end

- (Object) teardown



51
52
53
54
55
# File '../algorithm/support/algorithm_base.rb', line 51

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