Class: Evolvable::Evolution

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/evolvable/evolution.rb

Overview

After a population's instances are evaluated, they undergo evolution. The default evolution object is composed of selection, crossover, and mutation objects and applies them as operations to a population's evolvables in that order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selection: Selection.new, combination: GeneCombination.new, crossover: nil, mutation: Mutation.new) ⇒ Evolution

Initializes a new evolution object.

Keyword arguments:

selection

The default is Selection.new

crossover - deprecated

The default is GeneCrossover.new

mutation

The default is Mutation.new


26
27
28
29
30
31
32
33
# File 'lib/evolvable/evolution.rb', line 26

def initialize(selection: Selection.new,
               combination: GeneCombination.new,
               crossover: nil, # deprecated
               mutation: Mutation.new)
  @selection = selection
  @combination = crossover || combination
  @mutation = mutation
end

Instance Attribute Details

#combinationObject

Returns the value of attribute combination.


35
36
37
# File 'lib/evolvable/evolution.rb', line 35

def combination
  @combination
end

#mutationObject

Returns the value of attribute mutation.


35
36
37
# File 'lib/evolvable/evolution.rb', line 35

def mutation
  @mutation
end

#selectionObject

Returns the value of attribute selection.


35
36
37
# File 'lib/evolvable/evolution.rb', line 35

def selection
  @selection
end

Instance Method Details

#call(population) ⇒ Object


51
52
53
54
55
56
# File 'lib/evolvable/evolution.rb', line 51

def call(population)
  selection.call(population)
  combination.call(population)
  mutation.call(population)
  population
end