Hide Comments
Hide Comments

Comments (0)

Provides access to this gene's value from the chromosome of the indexed individual ( RSGeneticAlgorithm.TRSGAIndividual ) in the genetic    Population. The property allows read and write access to the gene as boolean values. The AsBoolean access property will attempt to translate the chromosome bits of this gene to a boolean, irregardless of the type specified in    GeneType. In other words, the gene does not enforce types, it just helps you to translate bits into a type. You should use the GeneType property to determine the type of the gene before using the accessor functions.

Index specifies the position of the individual in the Population, from 0 to Population.Count - 1.

Note: The TRSGAGene class automatically stores and retrieves the appropriate value from the correct place in the RSGeneticAlgorithm.TRSGAIndividual.Bits chromosome using the    Offset and    Size properties.
 
 

Namespace: RSGeneticAlgorithm

expandingSyntax

Delphi

public
  property AsBoolean[ Index: Integer ]: Boolean read GetAsBoolean write SetAsBoolean;
 

Parameters

Index

Type: Integer

Property Value

Type: Boolean

expandingExamples

To access the specific gene values for an individual in the population, you use the accessor properties (AsBoolean, AsInteger, etc) and index the values by the index for the individual in the population. To sum all integer genes for every individual, you would do the following:

Delphi

var
   iGene, iPop, Sum, IndividualSum: Integer;
 begin
   Sum := 0;
   // for every individual in the population
   for iPop := 0 to RSGeneticAlgorithm1.Population.Count - 1 do
   begin
     // sum the gene values for this individual
     IndividualSum := 0;
     for iGene := 0 to RSGeneticAlgorithm1.Genes.Count - 1 do
       if RSGeneticAlgorithm1.Genes[iGene].GeneType = gtInteger then
          IndividualSum := IndividualSum + RSGeneticAlgorithm1.Genes[iGene].AsInteger[iPop];
     // write out the sum for this individual
     ListBox1.Items.Add('Individual #'+IntToStr(iPop)+' genes equal '+IntToStr(IndividualSum));
     // add the sum to the running total
     Sum := Sum + IndividualSum;
   end;
   // write out the sum for all individuals
   ListBox1.Items.Add('Total = '+IntToStr(Sum));
 end; 

expandingSee Also

Comments (0)