Hide Comments
Hide Comments

Comments (0)

Occurs when the  Initialize method is called. Use the OnInitialization event to react to the initialization of the genetic algorithm problem or to pre-seed the  Population with specific individuals. The OnInitialization event occurs after the Population is created but before their DNA are randomized and their fitness evaluated. Set the Initialized variable to True to prevent the Initialize method from randomizing the Population's DNA.

Namespace: RSGeneticBase

expandingSyntax

Delphi

public
  property OnInitialization: TRSInitializationEvent read FOnInitialization write FOnInitialization;
 

Value

Type: TRSInitializationEvent

expandingExamples

The following event handler code initializes the application's charts to track the fitness levels as they change throughout evolution:

Delphi

procedure TForm1.RSGeneticAlgorithm1Initialization(Sender: TObject;
   var Initialized: Boolean);
   function Summation( const Value: Integer ): Integer;
   begin
        if Value = 1 then
           result := 1
        else
            result := Value + Summation( Value - 1 );
   end;
 var
    i: Integer;
 begin
      // create the N-Queens genes
      with Sender as TRSGeneticAlgorithm do
      begin
           Genes.Clear;
           for i := 0 to NUM_QUEENS - 1 do
               with Genes.Add do
               begin
                    GeneType := gtInteger;
                    Name := 'Col '+IntToStr(i);
                    Size := BitsRequired( NUM_QUEENS-1 );
                    MaxValue := NUM_QUEENS - 1;
               end;
           FitnessCutoff := Summation( NUM_QUEENS-1 );
           RSChartPanel1.LeftAxis.Maximum := FitnessCutoff;
           MutationProbability := 1 / GeneSize;
           Memo1.Lines.Add('');
           Memo1.Lines.Add('Population Initialized.');
           Memo1.Lines.Add('     Number of queens is '+IntToStr(NUM_QUEENS));
           Memo1.Lines.Add('     Chromosome Size is '+IntToStr(GeneSize)+
                                 ' ('+IntToStr(Genes.Count)+' genes X ' +
                                 IntToStr(Genes[0].Size)+ ' bits)');
           Memo1.Lines.Add('     Population is '+IntToStr(Population.Count));
           Memo1.Lines.Add('     Fitness Cutoff is '+FloatToStr(FitnessCutoff));
           Memo1.Lines.Add('     Mutation probability is '+FloatToStr(MutationProbability));
           Memo1.Lines.Add('');
           sgChessBoard.ColCount := TRSGeneticAlgorithm(Sender).Genes.Count;
           sgChessBoard.RowCount := TRSGeneticAlgorithm(Sender).Genes.Count;
           sgChessBoard.DefaultColWidth := sgChessBoard.ClientWidth div TRSGeneticAlgorithm(Sender).Genes.Count;
           sgChessBoard.DefaultRowHeight := sgChessBoard.ClientHeight div TRSGeneticAlgorithm(Sender).Genes.Count;
      end;
      RouletteSeries.Values.Clear;
      RandomSeries.Values.Clear;
      TournamentSeries.Values.Clear;
      StochasticTournamentSeries.Values.Clear;
      ElitistSeries.Values.Clear;
 end;

expandingSee Also

Comments (0)