Class: EvoSynth::MinimizingIndividual

Inherits:
Individual
  • Object
show all
Defined in:
lib/evosynth/core/minimizing_individual.rb

Overview

Basic individual for for minimizing problems

Instance Attribute Summary

Attributes inherited from Individual

#fitness, #genome

Instance Method Summary collapse

Methods inherited from Individual

#<=>, #changed?, #deep_clone, #maximizes?, #minimizes?

Constructor Details

#initialize(genome = nil) ⇒ MinimizingIndividual

:call-seq: MinimizingIndividual.new -> MinimizingIndividual MinimizingIndividual.new(genome) -> MinimizingIndividual (with given genome)

Returns a new MinimizingIndividual. In the first form, the genome is nil. In the second it creates a MinimizingIndividual with the given genome.

EvoSynth::MinimizingIndividual.new
EvoSynth::MinimizingIndividual.new( EvoSynth::ArrayGenome.new(10) { EvoSynth.rand_bool } )


41
42
43
44
45
# File 'lib/evosynth/core/minimizing_individual.rb', line 41

def initialize(genome = nil)
	super()
	@genome = genome
	@fitness = Float::MAX
end

Instance Method Details

#compare_fitness_values(one, two) ⇒ Object

:call-seq: compare_fitness_values(one, two) -> Number

Compares two fitness values for minimizing problems. It uses the <=> of the given fitness values and inverts the result.



53
54
55
# File 'lib/evosynth/core/minimizing_individual.rb', line 53

def compare_fitness_values(one, two)
	-1 * (one <=> two)
end

#to_sObject

:call-seq: to_s -> string

Returns description of this individual

i = EvoSynth::MinimizingIndividual.new
i.to_s                                     #=> "minimizing individual <fitness = 1.79769313486232e+308, genome = [nil]>"


65
66
67
# File 'lib/evosynth/core/minimizing_individual.rb', line 65

def to_s
	"minimizing individual <fitness = #{fitness}, genome = [#{genome}]>"
end