Class: Wallace::State

Inherits:
Object
  • Object
show all
Defined in:
lib/core/state.rb

Overview

This class is used to record information about the state of the evolution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(population) ⇒ State

Constructs a new state object.

Parameters

  • population, the population of the state.



14
15
16
17
18
19
# File 'lib/core/state.rb', line 14

def initialize(population)
  @population = population
  @generations = 0
  @stagnation = 0
  @best = population.best
end

Instance Attribute Details

#bestObject (readonly)

Allow all information to be read, but not changed.



5
6
7
# File 'lib/core/state.rb', line 5

def best
  @best
end

#generationsObject (readonly)

Allow all information to be read, but not changed.



5
6
7
# File 'lib/core/state.rb', line 5

def generations
  @generations
end

#populationObject (readonly)

Allow all information to be read, but not changed.



5
6
7
# File 'lib/core/state.rb', line 5

def population
  @population
end

#stagnationObject (readonly)

Allow all information to be read, but not changed.



5
6
7
# File 'lib/core/state.rb', line 5

def stagnation
  @stagnation
end

Instance Method Details

#next!Object

Updates the state object with the current state of the evolver.



22
23
24
25
26
27
# File 'lib/core/state.rb', line 22

def next!
  @generations += 1
  @stagnation += 1
  pbest = population.best
  @best = pbest if pbest < @best
end