Class: Evolvable::Evaluation
- Inherits:
-
Object
- Object
- Evolvable::Evaluation
- Defined in:
- lib/evolvable/evaluation.rb
Overview
Constant Summary collapse
- GOALS =
Mapping of goal type symbols to their corresponding goal objects. See the readme section above for details on each goal type.
{ maximize: Evolvable::MaximizeGoal.new, minimize: Evolvable::MinimizeGoal.new, equalize: Evolvable::EqualizeGoal.new }.freeze
- DEFAULT_GOAL_TYPE =
The default goal type used if none is specified.
:maximize
Instance Attribute Summary collapse
-
#goal ⇒ Evolvable::Goal
The goal object used for evaluation.
Instance Method Summary collapse
-
#best_evolvable(population) ⇒ Evolvable
Returns the best evolvable in the population according to the goal.
-
#call(population) ⇒ Array<Evolvable>
Evaluates and sorts all evolvables in the population according to the goal.
-
#initialize(goal = DEFAULT_GOAL_TYPE) ⇒ Evaluation
constructor
Initializes a new evaluation object.
-
#met_goal?(population) ⇒ Boolean
Checks if the goal has been met by any evolvable in the population.
Constructor Details
#initialize(goal = DEFAULT_GOAL_TYPE) ⇒ Evaluation
Initializes a new evaluation object.
80 81 82 |
# File 'lib/evolvable/evaluation.rb', line 80 def initialize(goal = DEFAULT_GOAL_TYPE) @goal = normalize_goal(goal) end |
Instance Attribute Details
#goal ⇒ Evolvable::Goal
The goal object used for evaluation.
88 89 90 |
# File 'lib/evolvable/evaluation.rb', line 88 def goal @goal end |
Instance Method Details
#best_evolvable(population) ⇒ Evolvable
Returns the best evolvable in the population according to the goal.
106 107 108 |
# File 'lib/evolvable/evaluation.rb', line 106 def best_evolvable(population) population.evolvables.max_by { |evolvable| goal.evaluate(evolvable) } end |
#call(population) ⇒ Array<Evolvable>
Evaluates and sorts all evolvables in the population according to the goal.
96 97 98 |
# File 'lib/evolvable/evaluation.rb', line 96 def call(population) population.evolvables.sort_by! { |evolvable| goal.evaluate(evolvable) } end |
#met_goal?(population) ⇒ Boolean
Checks if the goal has been met by any evolvable in the population.
116 117 118 |
# File 'lib/evolvable/evaluation.rb', line 116 def met_goal?(population) goal.met?(population.evolvables.last) end |