Class: Wallace::Operator
- Inherits:
-
Object
- Object
- Wallace::Operator
- Defined in:
- lib/core/operator.rb
Overview
Operators are used to produce individuals for the next generation using members of the current population as their inputs.
TODO: Feed state data into the operator (size of population, fitness, generations, etc).
Direct Known Subclasses
Koza::Operators::SubtreeCrossoverOperator, Koza::Operators::SubtreeMutationOperator, Wallace::Operators::BitFlipMutationOperator, Wallace::Operators::BoundaryMutationOperator, Wallace::Operators::CycleCrossoverOperator, Wallace::Operators::GaussianMutationOperator, Wallace::Operators::HalfUniformCrossoverOperator, Wallace::Operators::MergingCrossoverOperator, Wallace::Operators::OnePointCrossoverOperator, Wallace::Operators::OrderCrossoverOperator, Wallace::Operators::PartiallyMappedCrossoverOperator, Wallace::Operators::PointMutationOperator, Wallace::Operators::PositionCrossoverOperator, Wallace::Operators::ReverseSequenceMutationOperator, Wallace::Operators::ShuffleMutationOperator, Wallace::Operators::SpliceCrossoverOperator, Wallace::Operators::SubtourExchangeCrossoverOperator, Wallace::Operators::SwapMutationOperator, Wallace::Operators::ThreeParentCrossoverOperator, Wallace::Operators::TwoPointCrossoverOperator, Wallace::Operators::TworsMutationOperator, Wallace::Operators::UniformCrossoverOperator, Wallace::Operators::UniformMutationOperator, Wallace::Operators::VariableOnePointCrossoverOperator
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Operator
constructor
Constructs an instance of an Operator.
-
#operate(rng, inputs) ⇒ Object
Performs this genetic operation on the genetic data of a given number of individuals to return the genetic data for their offspring.
-
#produce(rng, inputs) ⇒ Object
Produces an arbitrary number of individuals according to the rules of this operator using .
Constructor Details
#initialize(opts = {}) ⇒ Operator
Constructs an instance of an Operator.
Parameters:
-
opts, a hash of keyword options for this method. -> id, the unique identifier for this operator.
18 19 20 |
# File 'lib/core/operator.rb', line 18 def initialize(opts = {}) @id = opts[:id] end |
Class Attribute Details
.name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/core/operator.rb', line 10 def name @name end |
Instance Method Details
#operate(rng, inputs) ⇒ Object
Performs this genetic operation on the genetic data of a given number of individuals to return the genetic data for their offspring.
Unlike ‘produce’, this method operates only on the genetic data (we refrain from the term chromosome since an individual may have multiple chromosomes).
Parameters:
-
rng, the RNG to use within this operation.
-
inputs, input individuals to the operation.
Returns: An array containing the genetic data for each produced offspring.
50 51 52 |
# File 'lib/core/operator.rb', line 50 def operate(rng, inputs) raise NotImplementedError, "No 'operate' function was implemented by this operator." end |
#produce(rng, inputs) ⇒ Object
Produces an arbitrary number of individuals according to the rules of this operator using
Parameters:
-
rng, random number generator to use within the operation.
-
inputs, input individuals to the operation.
Returns: An array of the offspring individuals produced by this operation.
31 32 33 34 35 36 |
# File 'lib/core/operator.rb', line 31 def produce(rng, inputs) operate(rng, inputs.map { |i| i.data }).each_with_index do |data, i| inputs[i].data = data end return inputs end |