Hide Comments
Hide Comments

Comments (0)

Allows you to define the genes that make up the DNA of the Population's chromosomes. The chromosomes are created by taking the parameters or factors (integers, booleans, floats, and enumerations) of your search problem and concatenating them together into a sequence of bits. The Genes property allows you to define the sequence of genes ( RSGeneticAlgorithm.TRSGAGene ) that make up these bits.

Each TRSGAGene provides a mapping that gives meaning to a certain number of bits in the individual. The TRSGAGene class is a helper class which helps you define and manipulate the genes of your population easily by defining n-bit integers, booleans, floats, etc. Each gene defines a characteristic of an individual. While the chromosomes are specific to an individual, the gene definition (TRSGAGene) defines the meaning of each gene for the entire population.

noteNote

Genes are optional. These classes help you decode the bits of an individual but if you don't want to use them, you do not have to. If they are defined, the size of the chromosomes for every individual is the same.

As an alternative to defining the genes of your population, you can use the GeneSize property to just define the number of bits in the chromosome with no mapping.
 

Namespace: RSGeneticAlgorithm

expandingSyntax

Delphi

public
  property Genes: TRSGAGenes read FGenes write SetGenes;
 

Property Value

Type: TRSGAGenes

expandingExamples

The following example creates four genes, making a chromosome of 19 bits:

Delphi

procedure TForm2.Button1Click(Sender: TObject);
 var
    Gene: TRSGAGene;
 begin
      Gene := RSGeneticAlgorithm1.Genes.Add;
      Gene.Name := '1-bit Boolean';
      Gene.GeneType := gtBoolean;
      Gene.Size := 1;
      Memo1.Lines.Add(Gene.Name);
      Memo1.Lines.Add(IntToStr(Gene.Size)+'-bit '+GetEnumName(TypeInfo(TGeneType), Ord(Gene.GeneType)));
      Memo1.Lines.Add(FloatToStr(Gene.MinValue)+'-'+FloatToStr(Gene.MaxValue));
 
      Gene := RSGeneticAlgorithm1.Genes.Add;
      Gene.Name := '5-bit Integer';
      Gene.GeneType := gtInteger;
      Gene.Size := 5;
      Memo1.Lines.Add(Gene.Name);
      Memo1.Lines.Add(IntToStr(Gene.Size)+'-bit '+GetEnumName(TypeInfo(TGeneType), Ord(Gene.GeneType)));
      Memo1.Lines.Add(FloatToStr(Gene.MinValue)+'-'+FloatToStr(Gene.MaxValue));
 
      Gene := RSGeneticAlgorithm1.Genes.Add;
      Gene.Name := '10-bit float';
      Gene.GeneType := gtFloat;
      Gene.Size := 10;
      Memo1.Lines.Add(Gene.Name);
      Memo1.Lines.Add(IntToStr(Gene.Size)+'-bit '+GetEnumName(TypeInfo(TGeneType), Ord(Gene.GeneType)));
      Memo1.Lines.Add(FloatToStr(Gene.MinValue)+'-'+FloatToStr(Gene.MaxValue));
 
      Gene := RSGeneticAlgorithm1.Genes.Add;
      Gene.Name := '3-bit Enumeration';
      Gene.GeneType := gtEnumeration;
      // Gene.Size is automatically calculated for us
      Gene.Enumerations.Add('one');
      Gene.Enumerations.Add('two');
      Gene.Enumerations.Add('three');
      Gene.Enumerations.Add('four');
      Gene.Enumerations.Add('five');
      Memo1.Lines.Add(Gene.Name);
      Memo1.Lines.Add(IntToStr(Gene.Size)+'-bit '+GetEnumName(TypeInfo(TGeneType), Ord(Gene.GeneType)));
      Memo1.Lines.Add(FloatToStr(Gene.MinValue)+'-'+FloatToStr(Gene.MaxValue));
 end;

expandingSee Also

Comments (0)