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 enumerated values. The AsEnumeration access property will attempt to translate the chromosome bits of this gene to an enumerated value from the Enumerations property, 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.

The AsEnumeration property translates the enumerated values from their strings into an integer index and encodes the index (and vice versa). So if Enumerations contains 4 enumerated values, you only need 2 bits for the encoding. If the Enumerations property is empty or, when writing, the string does not equal a string in the Enumerations property, you will get an exception.

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 AsEnumeration[ Index: Integer ]: String read GetAsEnumeration write SetAsEnumeration;
 

Parameters

Index

Type: Integer

Property Value

Type: String

expandingExamples

The following example sets up and uses an enumeration with four values:

Delphi

begin
      with RSGeneticAlgorithm1.Genes.Add do
      begin
           GeneType := gtEnumeration;
           // define the enumerations
           Enumerations.Add('one');
           Enumerations.Add('two');
           Enumerations.Add('three');
           Enumerations.Add('four');
           // set all individual's chromosome for this gene to the enumerated value 'two'
           for i := 0 to RSGeneticAlgorithm1.Population.Count - 1 do
             AsEnumeration[i] := 'two';
      end;
 end;

expandingSee Also

Comments (0)