Class: Evolvable::EqualizeGoal

Inherits:
Goal
  • Object
show all
Defined in:
lib/evolvable/equalize_goal.rb

Overview

Prioritizes instances that equal the goal value.

The default goal value is 0, but it can be reassigned to any numeric value.

Instance Method Summary collapse

Methods inherited from Goal

#initialize

Constructor Details

This class inherits a constructor from Evolvable::Goal

Instance Method Details

#evaluate(evolvable) ⇒ Object



14
15
16
# File 'lib/evolvable/equalize_goal.rb', line 14

def evaluate(evolvable)
  -(evolvable.fitness - value).abs
end

#met?(evolvable) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/evolvable/equalize_goal.rb', line 18

def met?(evolvable)
  evolvable.fitness == value
end

#valueObject



10
11
12
# File 'lib/evolvable/equalize_goal.rb', line 10

def value
  @value ||= 0
end