class

Talgene::Genome(T)

Inherits Indexable < Enumerable < Iterable < Talgene::Fittable < Comparable < Reference < Object

A convenience abstract class to avoid some boilerplate over the implementation of a #fitness method.

require "talgene"

class Model < Talgene::Genome(Int32)
  def fitness : Float64
    genes.each.slice(2).sum 0.0 do |(x, y)|
      y - x
    end
  end
end

model = Model.new [0, 1, 2, 3, 4, 5]
model.fitness # => 3.0

Constructors

new(genes : Array(T))

Creates a new Talgene::Genome instance with supplied array of genes.

Source

Instance methods

genes

Returns the underlying array of genes of this genetic representation.

Source
size

Returns the number of elements in this container.

Source
unsafe_fetch(index : Int)

Returns the element at the given index, without doing any bounds check.

Indexable makes sure to invoke this method with index in 0...size, so converting negative indices to positive ones is not needed here.

Clients never invoke this method directly. Instead, they access elements with #[](index) and #[]?(index).

This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.

Source