Hide Comments
Hide Comments

Comments (0)

Represents the entire population of candidate individuals ( RSGeneticAlgorithm.TRSGAIndividual ) in the current Generation, including the    FittestIndividual.

The TRSCustomGeneticAlgorithm component seeks to solve your optimization or search problems by evolving a group or population of candidate individuals through successive generations, selecting fitter (or better) child individuals for each generation, until a solution is found. After every call to Evolve , the Population property contains the next generation of individuals (the children), with the    PreviousGeneration property holding the previous generation (the parents, what was the Population before the Evolve call).

Namespace: RSGeneticAlgorithm

expandingSyntax

Delphi

public
  property Population: TRSGAPopulation read GetPopulation write SetPopulation;
 

Property Value

Type: TRSGAPopulation

expandingExamples

The following example loops through the entire population and sets their integer genes to a random number. Then, it goes back through and outputs those integer genes:
 

Delphi

var
   iGene, iPop, : Integer;
 begin
   // for every individual in the population, write random integer gene values
   for iPop := 0 to RSGeneticAlgorithm1.Population.Count - 1 do
   begin
     // Go through the genes
     for iGene := 0 to RSGeneticAlgorithm1.Genes.Count - 1 do
       if RSGeneticAlgorithm1.Genes[iGene].GeneType = gtInteger then
          RSGeneticAlgorithm1.Genes[iGene].SetGeneAsInteger(RSGeneticAlgorithm1.Population[iPop].Bits, Random(256));
   end;
   // for every individual in the population, read their integer genes
   for iPop := 0 to RSGeneticAlgorithm1.Population.Count - 1 do
   begin
     // write out the Name for this individual
     Memo1.Lines.Add('Individual #'+IntToStr(iPop)+': '+RSGeneticAlgorithm1.Population[iPop].DisplayName);
     // Go through the genes
     for iGene := 0 to RSGeneticAlgorithm1.Genes.Count - 1 do
       if RSGeneticAlgorithm1.Genes[iGene].GeneType = gtInteger then
          Memo1.Lines.Add(IntToStr(RSGeneticAlgorithm1.Genes[iGene].GeneAsInteger(RSGeneticAlgorithm1.Population[iPop].Bits)));
   end;
 end; 

expandingSee Also

Comments (0)