Hide Comments
Hide Comments

TRSCustomGeneticComponent.Reproduce(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual) Method

Comments (0)

The Reproduce method takes the two Parents and "mates" them to create the new Children. The Child parameters must exist but all of their information will be overwritten by the Parents. Child1 is copied from the first parent and Child2 is copied from the second parent, and then    Crossover,    Mutate, and    Invert are called according to the Operations property and the respective probability of the operation. Finally, an    OnReproduction event occurs.

The Evolve method calls the Reproduce methods.
 

Namespace: RSGeneticBase

expandingSyntax

Delphi

public
  function Reproduce( const Parent1, Parent2, Child1, Child2: TRSIndividual ): Boolean; overload; virtual;
 

Parameters

Parent1

Type: TRSIndividual

Parent2

Type: TRSIndividual

Child1

Type: TRSIndividual

Child2

Type: TRSIndividual

Return Value

Type: Boolean

expandingExamples

This example goes through the population, which is current a copy of the PreviousGeneration, selects parents and reproduces them:

Delphi

var
    i: Integer;
    Parent1, Parent2: TRSGAIndividual;
 begin
      Population.BeginUpdate;
      try
         // now go through the population and based on percentages apply
         // crossover, mutation and inversion
         i := 0;
         while i < Population.Count - 1 do
         begin
              // get two parents
              Parent1 := SelectParent( PreviousGeneration );
              Parent2 := SelectParent( PreviousGeneration );
              // reproduce
              if (i = (Population.Count - 1)) then
                Reproduce( Parent1, Parent2, Population[i] )
              else
                Reproduce( Parent1, Parent2, Population[i], Population[i+1] );
              Inc(i, 2);
         end;
         // update fitness evaluations
         EvaluateFitness;
      finally
         Population.EndUpdate;
      end;
 end;

expandingSee Also

Comments (0)