Class: EvoSynth::Individual
- Inherits:
-
Object
- Object
- EvoSynth::Individual
- Includes:
- Comparable
- Defined in:
- lib/evosynth/core/individual.rb
Overview
Base class for individuals
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fitness ⇒ Object
Returns the fitness of this individual.
-
#genome ⇒ Object
Genome of the Individual, it should provide a changed attribute.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
If you compare individuals the semantic of “<=>” is the following:.
-
#changed? ⇒ Boolean
Returns true, if this individual (most of the time its genome) has changed.
-
#compare_fitness_values(one, two) ⇒ Object
Should be implemented by subclasses.
-
#deep_clone ⇒ Object
Clones and returns a individual and its genome (deep copy).
-
#maximizes? ⇒ Boolean
Returns wether this Individual needs to be maximized.
-
#minimizes? ⇒ Boolean
Returns wether this Individual needs to be minimized.
Instance Attribute Details
#fitness ⇒ Object
Returns the fitness of this individual
38 39 40 |
# File 'lib/evosynth/core/individual.rb', line 38 def fitness @fitness end |
#genome ⇒ Object
Genome of the Individual, it should provide a changed attribute
34 35 36 |
# File 'lib/evosynth/core/individual.rb', line 34 def genome @genome end |
Instance Method Details
#<=>(another) ⇒ Object
If you compare individuals the semantic of “<=>” is the following:
a > b -> individual a is a better solution than individual b a < b -> individual b is a better solution than individual a a == b -> a and b have a equal fitness value
68 69 70 |
# File 'lib/evosynth/core/individual.rb', line 68 def <=>(another) compare_fitness_values(fitness, another.fitness) end |
#changed? ⇒ Boolean
Returns true, if this individual (most of the time its genome) has changed. Otherwise it will return false.
50 51 52 |
# File 'lib/evosynth/core/individual.rb', line 50 def changed? @genome.changed? end |
#compare_fitness_values(one, two) ⇒ Object
Should be implemented by subclasses
74 75 76 |
# File 'lib/evosynth/core/individual.rb', line 74 def compare_fitness_values(one, two) raise NotImplementedError, "please implement compare_fitness_values!" end |
#deep_clone ⇒ Object
Clones and returns a individual and its genome (deep copy).
56 57 58 59 60 |
# File 'lib/evosynth/core/individual.rb', line 56 def deep_clone my_clone = self.clone my_clone.genome = Marshal.load( Marshal.dump( self.genome ) ) my_clone end |
#maximizes? ⇒ Boolean
Returns wether this Individual needs to be maximized.
86 87 88 |
# File 'lib/evosynth/core/individual.rb', line 86 def maximizes? compare_fitness_values(1,0) > 0 end |
#minimizes? ⇒ Boolean
Returns wether this Individual needs to be minimized.
80 81 82 |
# File 'lib/evosynth/core/individual.rb', line 80 def minimizes? compare_fitness_values(1,0) < 0 end |