Class: Wallace::Termination
- Inherits:
-
Object
- Object
- Wallace::Termination
- Defined in:
- lib/core/termination.rb
Overview
This class is used to store and check against the termination criteria of the evolutionary process.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#fitness_limit ⇒ Object
readonly
Returns the value of attribute fitness_limit.
-
#generation_limit ⇒ Object
readonly
Returns the value of attribute generation_limit.
-
#stagnation_limit ⇒ Object
readonly
Returns the value of attribute stagnation_limit.
Instance Method Summary collapse
-
#finished?(state) ⇒ Boolean
Determines whether the evolutionary process has reached its termination criteria or not.
-
#initialize(opts = {}) ⇒ Termination
constructor
Constructs a new termination criteria.
Constructor Details
#initialize(opts = {}) ⇒ Termination
Constructs a new termination criteria.
Parameters:
-
opts, a hash of keyword options for this method. -> generations, limit on the total number of generations to perform. -> stagnation, limit on the successive number of generations without change to the best solution. -> fitness, target fitness value. -> error, the maximum allowed error in the target fitness value.
18 19 20 21 22 23 |
# File 'lib/core/termination.rb', line 18 def initialize(opts = {}) @generation_limit = opts[:generations] || 200 @stagnation_limit = opts[:stagnation] @fitness_limit = opts[:fitness] @error = opts[:error] || 0 end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/core/termination.rb', line 5 def error @error end |
#fitness_limit ⇒ Object (readonly)
Returns the value of attribute fitness_limit.
5 6 7 |
# File 'lib/core/termination.rb', line 5 def fitness_limit @fitness_limit end |
#generation_limit ⇒ Object (readonly)
Returns the value of attribute generation_limit.
5 6 7 |
# File 'lib/core/termination.rb', line 5 def generation_limit @generation_limit end |
#stagnation_limit ⇒ Object (readonly)
Returns the value of attribute stagnation_limit.
5 6 7 |
# File 'lib/core/termination.rb', line 5 def stagnation_limit @stagnation_limit end |
Instance Method Details
#finished?(state) ⇒ Boolean
Determines whether the evolutionary process has reached its termination criteria or not.
Parameters:
-
state, the current state of the evolution.
Returns true if it has finished and false if otherwise.
32 33 34 35 36 37 |
# File 'lib/core/termination.rb', line 32 def finished?(state) return true if not @generation_limit.nil? and state.generations == @generation_limit return true if not @fitness_limit.nil? and state.best.fitness.value <= @fitness_limit + @error return true if not @stagnation_limit.nil? and state.stagnation == @stagnation_limit return false end |