Class: Wallace::State
- Inherits:
-
Object
- Object
- Wallace::State
- Defined in:
- lib/core/state.rb
Overview
This class is used to record information about the state of the evolution.
Instance Attribute Summary collapse
-
#best ⇒ Object
readonly
Allow all information to be read, but not changed.
-
#generations ⇒ Object
readonly
Allow all information to be read, but not changed.
-
#population ⇒ Object
readonly
Allow all information to be read, but not changed.
-
#stagnation ⇒ Object
readonly
Allow all information to be read, but not changed.
Instance Method Summary collapse
-
#initialize(population) ⇒ State
constructor
Constructs a new state object.
-
#next! ⇒ Object
Updates the state object with the current state of the evolver.
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
#best ⇒ Object (readonly)
Allow all information to be read, but not changed.
5 6 7 |
# File 'lib/core/state.rb', line 5 def best @best end |
#generations ⇒ Object (readonly)
Allow all information to be read, but not changed.
5 6 7 |
# File 'lib/core/state.rb', line 5 def generations @generations end |
#population ⇒ Object (readonly)
Allow all information to be read, but not changed.
5 6 7 |
# File 'lib/core/state.rb', line 5 def population @population end |
#stagnation ⇒ Object (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 |