Hide Comments
Hide Comments

Comments (0)

Provides the mapping for one gene in the chromosome of the population of the RSGeneticAlgorithm.TRSCustomGeneticAlgorithm component and its descendants. The TRSCustomGeneticAlgorithm class contains a population of individuals ( RSGeneticAlgorithm.TRSGAPopulation ), which contain chromosomes (    Bits property). These chromosomes are used to abstractly represent the solution to the search problem. They represent through their bits the DNA of each candidate solution (or individual), represented by a RSGeneticAlgorithm.TRSGAIndividual class. 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 TRSGAGene provides a mapping that gives meaning to the bits in the individual.

The TRSGAGene class is a helper class (available through the    Genes property of the TRSGeneticAlgorithm component) 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. The TRSGAGenes collection maintains the list of all genes.

NOTE: Genes are optional (instead, you can use the    GeneSize property). 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.
 

Namespace: RSGeneticAlgorithm

expandingInheritance Hierarchy

TCollectionItem
  RSGeneticAlgorithm.TRSGAGene
 

expandingSyntax

Delphi

type 
  TRSGAGene = class(TCollectionItem) 
  end;  
 

expandingConstructors

 

Name

Description

public constructor

Create(TCollection)

Initializes a new instance of the TRSGAGene class.

public destructor

Destroy

Represents the destructor of the TRSGAGene class.

Top

expandingProperties

 

Name

Description

public property

AsBoolean[Integer]

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.
 
 

public property

AsDouble[Integer]

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 double precision floating point values. The AsDouble access property will attempt to translate the chromosome bits of this gene to a double, 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.
 
 

public property

AsEnumeration[Integer]

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.
 
 

public property

AsFloat[Integer]

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 single precision floating point values. The AsFloat access property will attempt to translate the chromosome bits of this gene to a single, 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.
 
 

public property

AsInt64[Integer]

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 64-bit integer values. The AsInt64 access property will attempt to translate the chromosome bits of this gene to a 64-bit integer, 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.
 
 

public property

AsInteger[Integer]

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 integer values. The AsInteger access property will attempt to translate the chromosome bits of this gene to a integer, 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.
 
 

public property

Collection

Returns the RSGeneticAlgorithm.TRSGAGenes collection that owns this gene item.
 

published property

Enumerations

Defines the string labels or enumerated values for an gtEnumeration gene ( GeneType ). Use the AsEnumeration property to read and write the enumerated values into the bits of the chromosome. When you change the number of strings that are in the Enumerations string list, the TRSGAGene class automatically recalculates the   Size (number of bits) of the gene in order to properly store all enumerated values

published property

GeneType

Defines the simple type (e.g., integer, floating point number, etc) for this gene in the population's chromosomes. Use the GeneType property to know how to access the bits of the chromosomes using the AsXXX property accessors (e.g.,   AsInteger for gtInteger GeneType,   AsBoolean for gtBoolean, etc). For the gtEnumeration Gene Type, you also need to define the   Enumerations for the gene before accessing it.

published property

MaxValue

Constrain the floating point, integer, and enumerations gene types (see GeneType ) to a valid range. The TRSGAGene class uses these properties to ensure that when you are writing a numeric value to a RSGeneticAlgorithm.TRSGAIndividual 's chromosome, the value is in a valid range. Note that this won't stop mutations or anything else that operates on the bits directly from giving invalid values.

published property

MinValue

Constrain the floating point, integer, and enumerations gene types (see GeneType ) to a valid range. The TRSGAGene class uses these properties to ensure that when you are writing a numeric value to a RSGeneticAlgorithm.TRSGAIndividual 's chromosome, the value is in a valid range. Note that this won't stop mutations or anything else that operates on the bits directly from giving invalid values.

published property

Name

Allows you to specify a name for this gene

public property

Offset

Defines the starting bit for this gene within the   Population's Chromosome bits. Using both the   Offset and the   Size, the gene is able to read and write into a specific area of the bits. You cannot directly change the offset - instead it is calculated by taking the size of the genes before it within the   Genes collection.
 

published property

PreserveSignBit

The PreserveSignBit property controls whether the gene class should reserve one bit of the   Size as the sign bit for numeric values

published property

Size

Defines the number of bits that are used by this gene in the   Population's Chromosome bits. Use this property to create 6-bit integer genes, 24-bit floating point genes, etc. The TRSGAGene class automatically adjusts the size for you when the   GeneType is gtBoolean (1-bit) or gtEnumerations (minimum number of bits to hold all indices into the Enumerations string list), though you are allowed to change this later. Using both the   Offset and the   Size, the gene is able to read and write into a specific area of the bits.

Top

expandingMethods

 

Name

Description

public method

Assign(TPersistent)

Represents method Assign(TPersistent).

public method

AsString(Integer)

Overloaded.  Converts the genetic encoding of a RSGeneticAlgorithm.TRSGAIndividual 's Bits into a string representation based on     GeneType. The AsString function extracts the gene's bits (using the Offset and Size properties to specify where) and then converts the bits into a string representation, e.g., for numeric types, you see the decimal representation of the number, for booleans, you see "True" or "False, and for enumerations, you see the correct string from the     Enumerations property.

The Index parameter specifies the index of an individual in the     Population and automatically extracts the RSGeneticAlgorithm.TRSGAIndividual.Bits chromosome property to call the overloaded AsString function.
 

public method

AsString(TRSEncodedBits)

Overloaded.  Converts the genetic encoding in the Bits into a string representation based on     GeneType. The AsString function extracts the gene's bits (using the Offset and Size properties to specify where) and then converts the bits into a string representation, e.g., for numeric types, you see the decimal representation of the number, for booleans, you see "True" or "False, and for enumerations, you see the correct string from the     Enumerations property.

The Bits parameter should be at least of the correct size for this gene and all preceding genes in the Genes collection (e.g., its size should be at least Offset + Size bits). The overloaded     AsString function accepts an index of an individual in the Population and automatically extracts the RSGeneticAlgorithm.TRSGAIndividual.Bits chromosome property.
 

protected method

EnumerationsChange(TObject)

Represents method EnumerationsChange(TObject).

public method

GeneAsBoolean(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as boolean values. The equivalent     SetGeneAsBoolean method provides write access. The GeneAsBoolean function 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded     GeneAsBoolean method allows you to change the offset into the bits you want to use.
 

public method

GeneAsBoolean(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as boolean values. The equivalent     SetGeneAsBoolean method provides write access. The GeneAsBoolean function 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsBoolean method will also automatically use the     Offset property.
 

public method

GeneAsDouble(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as double floating-point values. The equivalent     SetGeneAsDouble method provides write access. The GeneAsDouble function will attempt to translate the chromosome bits of this gene to a double, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded     GeneAsDouble method allows you to change the offset into the bits you want to use.
 

public method

GeneAsDouble(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as double floating-point values. The equivalent     SetGeneAsDouble method provides write access. The GeneAsDouble function will attempt to translate the chromosome bits of this gene to a double, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsDouble method will also automatically use the     Offset property.
 

public method

GeneAsEnumeration(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as enumerated values. The equivalent  SetGeneAsEnumeration method provides write access. The GeneAsEnumeration 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 GeneAsEnumeration/SetGeneAsEnumeration methods translate the enumerated values from their strings into an integer index and encode 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsEnumeration method allows you to change the offset into the bits you want to use.
 

public method

GeneAsEnumeration(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as enumerated values. The equivalent  SetGeneAsEnumeration method provides write access. The GeneAsEnumeration 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 GeneAsEnumeration/SetGeneAsEnumeration methods translate the enumerated values from their strings into an integer index and encode 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsEnumeration method will also automatically use the     Offset property.
 

public method

GeneAsFloat(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as double floating-point values. The equivalent     SetGeneAsDouble method provides write access. The GeneAsFloat function will attempt to translate the chromosome bits of this gene to a single, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded     GeneAsFloat method allows you to change the offset into the bits you want to use.
 

public method

GeneAsFloat(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as double floating-point values. The equivalent     SetGeneAsDouble method provides write access. The GeneAsFloat function will attempt to translate the chromosome bits of this gene to a single, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsDouble method will also automatically use the     Offset property.
 

public method

GeneAsInt64(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as 64-bit integer values. The equivalent     SetGeneAsInt64 method provides write access. The GeneAsInt64 function will attempt to translate the chromosome bits of this gene to a 64-bit integer, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded     GeneAsInt64 method allows you to change the offset into the bits you want to use.
 

public method

GeneAsInt64(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as 64-bit integer values. The equivalent     SetGeneAsInt64 method provides write access. The GeneAsInt64 function will attempt to translate the chromosome bits of this gene to a 64-bit integer, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsInt64 method will also automatically use the     Offset property.
 

public method

GeneAsInteger(TRSEncodedBits)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as integer values. The equivalent     SetGeneAsInteger method provides write access. The GeneAsInteger function will attempt to translate the chromosome bits of this gene to an integer, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded     GeneAsInteger method allows you to change the offset into the bits you want to use.
 

public method

GeneAsInteger(TRSEncodedBits,Integer)

Overloaded.  Extracts this gene's value from the Bits chromosome parameter. The function allows read access to the gene as integer values. The equivalent     SetGeneAsInteger method provides write access. The GeneAsInteger function will attempt to translate the chromosome bits of this gene to an integer, 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the Offset and Size properties. The overloaded GeneAsInteger method will also automatically use the     Offset property.
 

protected method

GetDisplayName

Represents method GetDisplayName.

protected method

RecalcMinMax

Represents method RecalcMinMax.

public method

SetGeneAsBoolean(TRSEncodedBits,Boolean)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as boolean values. The equivalent     GeneAsBoolean method provides read access. The SetGeneAsBoolean function will translate boolean into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value into the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsBoolean method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsBoolean(TRSEncodedBits,Integer,Boolean)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as boolean values. The equivalent     GeneAsBoolean method provides read access. The SetGeneAsBoolean function will translate boolean into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value using the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be stored. The overloaded SetGeneAsBoolean method will also automatically use the     Offset property.
 

public method

SetGeneAsDouble(TRSEncodedBits,Double)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as double precision floating point values. The equivalent     GeneAsDouble method provides read access. The SetGeneAsDouble function will translate double values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value into the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsDouble method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsDouble(TRSEncodedBits,Integer,Double)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as double precision floating point values. The equivalent     GeneAsDouble method provides read access. The SetGeneAsDouble function will translate double values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value using the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be stored. The overloaded SetGeneAsDouble method will also automatically use the     Offset property.
 

public method

SetGeneAsEnumeration(TRSEncodedBits,Integer,String)

Overloaded.  Writes the value into the Bits chromosome parameter at the specified Offset. The function allows write access to the bits as enumerated values. The equivalent     GeneAsEnumeration method provides read access. The SetGeneAsEnumeration function attempts to translate string values into the chromosome bits representing the index of the 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 GeneAsEnumeration/SetGeneAsEnumeration methods translate the enumerated values from their strings into an integer index and encode 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be retrieved. The overloaded SetGeneAsEnumeration method will also automatically use the     Offset property.
 

public method

SetGeneAsEnumeration(TRSEncodedBits,String)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as enumerated values. The equivalent     GeneAsEnumeration method provides read access. The SetGeneAsEnumeration function attempts to translate string values into the chromosome bits representing the index of the 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 GeneAsEnumeration/SetGeneAsEnumeration methods translate the enumerated values from their strings into an integer index and encode 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.

Note: The TRSGAGene class automatically retrieves the appropriate value from the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsEnumeration method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsFloat(TRSEncodedBits,Integer,Single)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as floating point values. The equivalent     GeneAsFloat method provides read access. The SetGeneAsFloat function will translate floating point values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value using the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be stored. The overloaded SetGeneAsFloat method will also automatically use the     Offset property.
 

public method

SetGeneAsFloat(TRSEncodedBits,Single)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as floating point values. The equivalent     GeneAsFloat method provides read access. The SetGeneAsFloat function will translate floating point values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value into the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsFloat method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsInt64(TRSEncodedBits,Int64)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as 64-bit integer values. The equivalent     GeneAsInt64 method provides read access. The SetGeneAsInt64 function will translate 64-bit integer values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value into the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsInt64 method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsInt64(TRSEncodedBits,Integer,Int64)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as 64-bit integer values. The equivalent     GeneAsInt64 method provides read access. The SetGeneAsInt64 function will translate 64-bit integer values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value using the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be stored. The overloaded SetGeneAsInt64 method will also automatically use the     Offset property.
 

public method

SetGeneAsInteger(TRSEncodedBits,Integer)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as integer values. The equivalent     GeneAsInteger method provides read access. The SetGeneAsInteger function will translate integer values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value into the correct place in the Bits chromosome using the     Offset and     Size properties. The overloaded SetGeneAsInteger method allows you to change the offset into the bits you want to use.
 

public method

SetGeneAsInteger(TRSEncodedBits,Integer,Integer)

Overloaded.  Writes the value into the Bits chromosome parameter. The function allows write access to the bits as integer values. The equivalent     GeneAsInteger method provides read access. The SetGeneAsInteger function will translate integer values into the chromosome bits, 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.

Note: The TRSGAGene class automatically stores the appropriate value using the correct size in the Bits chromosome using the     Size property but allows you to specify where in the bits the gene should be stored. The overloaded SetGeneAsInteger method will also automatically use the     Offset property.
 

protected method

SetOffset(Integer)

Represents method SetOffset(Integer).

protected method

SizeChange

Represents method SizeChange.

Top

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)