Hide Comments
Hide Comments

Comments (0)

The TRSGeneticAlgorithm component is the descendant class of the RSGeneticAlgorithm.TRSCustomGeneticAlgorithm component which publishes all the properties needed to use genetic algorithms in your programs.

Genetic algorithms seek to solve optimization or search problems. They are inspired by evolutionary biology and approach the search problem as a task of 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. It uses evolutionary biology techniques such as inheritance, mutation, selection, and crossover (also called recombination).

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 RSGeneticAlgorithm.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) 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.

After setting up the genes of your population (either by using the    Genes property to define each gene separately or the    GeneSize property to just define the number of bits in the chromosome with no mapping), you set the    InitialPopulation, define a fitness function (    OnEvaluateFitness event) to properly "score" each individual, and then Evolve your solution.
 

Namespace: RSGeneticAlgorithm

expandingInheritance Hierarchy

TComponent
  RSGeneticBase.TRSCustomGeneticComponent
    RSGeneticAlgorithm.TRSCustomGeneticAlgorithm
      RSGeneticAlgorithm.TRSGeneticAlgorithm
 

expandingSyntax

Delphi

type
  TRSGeneticAlgorithm = class(TRSCustomGeneticAlgorithm)
  end; 
 

expandingConstructors

 

Name

Description

public constructor

Create(TComponent)

Initializes a new instance of the TRSCustomGeneticAlgorithm class. (Overrides RSGeneticBase.TRSCustomGeneticComponent.Create(TComponent).)

Top

expandingProperties

 

Name

Description

public property

AvgFitness

Returns the average fitness level of the   Population.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

AvgWeightedFitness

Returns the average weighted fitness level of the   Population.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

CrossoverMethod

Represents property CrossoverMethod.

published property

CrossoverProbability

Represents property CrossoverProbability.

protected property

CumNormFitnesses

Contains the cumulative normalized fitnesses of the current generation (   Population) (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

Diversity

Returns the genetic diversity of the current Population, which is the   AvgFitness /   MaxFitness. In other words, how different (based upon fitness) are the individuals in the population from each other? If the population is not diverse enough, it is hard to breed a solution as everyone is alike. The genetic component can use the Diversity with the   DiversityLimit to automatically abort evolution if the diversity indicates we are in an evolutionary dead-end.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

DiversityLimit

Represents property DiversityLimit.

published property

ElitistPct

Represents property ElitistPct.

published property

FitnessCutoff

Represents property FitnessCutoff.

published property

FitnessMethod

Represents property FitnessMethod.

protected property

FitnessSum

Contains the sum of all fitness values for the entire population (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

FittestIndividual

Returns the fittest individual in the   Population. The individual is chosen based on the FitnessMethod and the Fitness evaluations of all the individuals in the population. The FittestIndividual is re-chosen every time the population is evolved.
 (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

published property

Generation

Represents property Generation.

published property

GenerationLimit

Represents property GenerationLimit.

published property

Genes

Represents property Genes.

published property

GeneSize

Represents property GeneSize.

public property

Halt

Controls   Evolve method execution. Set Halt to true to stop evolution (useful for multi-threading) (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

InitialDuplicatesRetries

Represents property InitialDuplicatesRetries.

public property

Initialized

Returns true if the genetic component has been initialized (and initial population has been created and evaluated for fitness) (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

InitialPopulation

Represents property InitialPopulation.

published property

InversionProbability

Represents property InversionProbability.

public property

MaxFitness

Returns the highest fitness level of the   Population.
 
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

MaxWeightedFitness

Returns the highest weighted fitness level of the   Population.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

MinFitness

Returns the lowest fitness level of the   Population.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public property

MinWeightedFitness

Returns the lowest weighted fitness level of the   Population.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

MutationProbability

Represents property MutationProbability.

published property

OnCrossover

Represents property OnCrossover.

published property

OnEvaluateFitness

Represents property OnEvaluateFitness.

published property

OnEvolve

Represents property OnEvolve.

published property

OnInitialization

Represents property OnInitialization.

published property

OnInitializeChild

Represents property OnInitializeChild.

published property

OnMutation

Represents property OnMutation.

published property

OnReproduction

Represents property OnReproduction.

published property

OnSelection

Represents property OnSelection.

published property

Operations

Represents property Operations.

published property

Population

Represents property Population.

public property

PreviousGeneration

Contains the parents of the current generation, which is represented by the   Population property. 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). (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

protected property

PriorityQueue

Returns the population sorted by fitness (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected property

RouletteIndex

Index of the individual next up in Elitist selection method or index of winner of roulette wheel selection method (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

published property

SelectionMethod

Represents property SelectionMethod.

published property

TournamentField

Represents property TournamentField.

published property

UseDiversityLimit

Represents property UseDiversityLimit.

published property

UseFitnessCutoff

Represents property UseFitnessCutoff.

published property

UseGenerationLimit

Represents property UseGenerationLimit.

protected property

WeightedFitnessSum

Contains the sum of all weighted fitness values for the entire population (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

Top

expandingMethods

 

Name

Description

public method

Assign(TPersistent)

Represents method Assign(TPersistent). (Overrides RSGeneticBase.TRSCustomGeneticComponent.Assign(TPersistent).)

protected method

CalculateCumulativeNormalizedFitnesses

Calculates the cumulative normalized fitness values of the   Population (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

CompareFitness(TRSIndividual,TRSIndividual,Boolean)

Compares the two individuals and returns an evaluation of who is fitter. If the result is -1, Parent1 is fitter. If the result is 1, Parent2 is fitter. If the two individuals are equally fit, the function returns 0.

The function uses the RSGeneticBase.TRSIndividual.Fitness property or RSGeneticBase.TRSIndividual.WeightedFitness to determine which parent is fitter. The     FitnessMethod controls the interpretation of the fitness.

The UsePureFitness parameter tells the function if it should ignore WeightedFitness or not.

protected method

CreateGenes(TRSGeneClass)

Creates the Genes collection (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

protected method

CreatePopulation(TRSIndividualClass)

Creates the population collection (Overrides RSGeneticBase.TRSCustomGeneticComponent.CreatePopulation(TRSIndividualClass).)

public method

Crossover(TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded.  Combines the DNA of the two parents to make the DNA of the children. Note that crossover is not guaranteed to occur but is dependent on the     CrossoverProbability. The function calls the     OnCrossover event and then  DoCrossover method.

The Crossover method is called by the     Reproduce method. The function returns true if crossover occurred.
 

public method

Crossover(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded.  Combines the DNA of the two parents to make the DNA of the children. Note that crossover is not guaranteed to occur but is dependent on the     CrossoverProbability. The function calls the     OnCrossover event and then  DoCrossover method.

The Crossover method is called by the     Reproduce method. The function returns true if crossover occurred.
 

protected method

DefineProperties(TFiler)

Represents method DefineProperties(TFiler). (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

Describe(TStrings,String)

Provides a description of the genetic programming component and its important properties. The description is added to the Strings parameter. The TabStr parameter specifies the indentation to use when adding sub-strings. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoCalculateFitnessStatistics

Calculates the fitness statistics (max, min, avg) for one generation. The method accesses each individual's Fitness property which may force a fitness evaulation to occur. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoCalculateWeightedFitnessStatistics

Calculates the weighted fitness statistics (max, min, avg) for one generation. The method accesses each individual's WeightedFitness property which may force a fitness evaulation to occur. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoCrossover(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual)

Performs the actual crossover operation. The decision to crossover has already been decided by the time this method is called. (Overrides RSGeneticBase.TRSCustomGeneticComponent.DoCrossover(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual).)

protected method

DoEvaluateWeightedFitness(TRSIndividual)

Calls the OnEvaluateWeightedFitness event and returns the result. If the event handler has not been defined, this method returns the regular fitness (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoEvolve

Performs the actual evolve for one generation with each new pair of children being created in sequence (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoEvolveOneStep(Integer)

Performs the actual evolve for one pair of children (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoFinishEvolve

Performs final steps for one evolution phase. Called by DoEvolve. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoInitialize

Performs the actual initialization of the Population before evolution occurs.

The method returns number of duplicates fixed.

protected method

DoInvert(TRSIndividual)

Performs the actual inversion of the individual. The decision to invert the individual has already been made before calling this method. (Overrides RSGeneticBase.TRSCustomGeneticComponent.DoInvert(TRSIndividual).)

protected method

DoMutate(TRSIndividual)

Performs the actual mutation of the individual. The decision to mutat the individual has already been made before calling this method. (Overrides RSGeneticBase.TRSCustomGeneticComponent.DoMutate(TRSIndividual).)

protected method

DoParallelEvolveOneStep(Integer)

Performs the actual evolve for one pair of children (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoReproduce(TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded. Performs the actual reproduction operation by combining the two parents to make the new Child. The Child must already exist but may be uninitialized. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoReproduce(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded. Performs the actual reproduction operation by combining the two parents to make two new children. The children must already exist but may be uninitialized. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoSelectionPreparation

Performs any steps necessary for selecting parents in the newly evolved Population.

This method is called when evaluating fitness for everyone.
 

protected method

DoSelectParent(TRSPopulation)

Performs the selection of a parent from the Population. This method is only called if the   SelectionMethod is Custom. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

DoStartEvolve

Performs initial steps for one evolution phase. Called by DoEvolve. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

EvaluateFitness

Overloaded.  Evaluates the fitness for every individual of the Population (and calculates the     MaxFitness,     MinFitness, and     AvgFitness). It calculates a fitness estimation for every RSGeneticBase.TRSIndividual by calling the overloaded     EvaluateFitness method. It uses your     OnEvaluateFitness event handler to calculate values. After every individual is evaluated, it sets the MaxFitness, MinFitness, and AvgFitness values and sets the     FittestIndividual property.

Defining your fitness function is a highly important part of defining a genetic algorithm or genetic program. The fitness function returns a floating point value that specifies the correctness of the individual solution. The fitness function needs to be able to allow the genetic component to decide which solution is better than another. The genetic component will seek to either maximize the solution (e.g., keep evolving for individuals whose fitness are greater than other individuals in the population) or to minimize the solution (e.g., find the individuals whose fitness are less than other individuals). Note you can specify which direction to evolve towards with the     FitnessMethod property.
 

public method

EvaluateFitness(TRSIndividual,Boolean)

Overloaded.  Returns a fitness estimation of the passed in RSGeneticBase.TRSIndividual . It uses your     OnEvaluateFitness event handler to return the value.

Defining your fitness function is a highly important part of defining a genetic algorithm or genetic program. The fitness function returns a floating point value that specifies the correctness of the individual solution. The fitness function needs to be able to allow the genetic component to decide which solution is better than another. The genetic component will seek to either maximize the solution (e.g., keep evolving for individuals whose fitness are greater than other individuals in the population) or to minimize the solution (e.g., find the individuals whose fitness are less than other individuals). Note you can specify which direction to evolve towards with the     FitnessMethod property.

The overloaded     EvaluateFitness method evaluates the fitness for every individual of the Population (and calculates the     MaxFitness,     MinFitness, and     AvgFitness).
 

public method

Evolve

Overloaded.  The Evolve method is the heart of the genetic component. The Evolve method is responsible for "breeding" the     Population towards an answer for your goal. Each generation, the Evolve method selects parents and then     Reproduces children for the new generation by using the genetic operations: first crossover, then mutation, and finally inversion. Each call to Evolve with breed one new generation. If you want to evolve many new generations at once (perhaps with a cutoff using the     FitnessCutoff,     GenerationLimit and     DiversityLimit properties), use the overloaded Evolve method. Successive calls to the Evolve method continues the evolutionary process from where the Evolve method stopped (use     Initialize to reset the process). If this is your first call to Evolve, it automatically calls the Initialize method.

Specify the     Operations to control which operations are performed while evolving: crossover, mutation, and inversion operations. You can also specify the chances of each operation occurring every generation using the     CrossoverProbability,     MutationProbability, and     InversionProbability properties.

The     SelectionMethod property (or     OnSelection event) specifies how the genetic component selects individuals from the current generation to be used as parents of the next generation.

The FitnessCutoff property aborts the evolutionary process when any child meets or exceeds (if FitnessMethod is fmMaximize) or is less than (if FitnessMethod is fmMinimize) the cutoff value. The     UseFitnessCutoff property must be true to use the fitness cutoff.

The DiversityLimit property aborts the evolutionary process when the diversity of the children falls below the DiversityLimit, e.g., all the children are too alike to go any further. The     UseDiversityLimit property must be true to use the diversity limit.

The GenerationLimit property aborts the evolutionary process when the required number of generations have been evolved. The     UseGenerationLimit property must be true to use the generation limit.
 
 

public method

Evolve(Integer)

Overloaded.  The Evolve method is the heart of the genetic component. The Evolve method is responsible for "breeding" the     Population towards an answer for your goal. Each generation, the Evolve method selects parents and then     Reproduces children for the new generation by using the genetic operations: first crossover, then mutation, and finally inversion. You can specify the number of generations to evolve or use the     FitnessCutoff,     GenerationLimit and     DiversityLimit properties to automatically stop the genetic process. Successive calls to the Evolve method continues the evolutionary process from where the Evolve method stopped (use     Initialize to reset the process). If this is your first call to Evolve, it automatically calls the Initialize method.

Specify the     Operations to control which operations are performed while evolving: crossover, mutation, and inversion operations. You can also specify the chances of each operation occurring every generation using the     CrossoverProbability,     MutationProbability, and     InversionProbability properties.

The     SelectionMethod property (or     OnSelection event) specifies how the genetic component selects individuals from the current generation to be used as parents of the next generation.

The FitnessCutoff property aborts the evolutionary process when any child meets or exceeds (if FitnessMethod is fmMaximize) or is less than (if FitnessMethod is fmMinimize) the cutoff value. The     UseFitnessCutoff property must be true to use the fitness cutoff.

The DiversityLimit property aborts the evolutionary process when the diversity of the children falls below the DiversityLimit, e.g., all the children are too alike to go any further. The     UseDiversityLimit property must be true to use the diversity limit.

The GenerationLimit property aborts the evolutionary process when the required number of generations have been evolved. The     UseGenerationLimit property must be true to use the generation limit.
 
 
 

public method

Fittest(TRSIndividual,TRSIndividual,Boolean)

Returns the "fitter" of the two parent individuals. It compares the Fitness properties (or WeightedFitness) of both individuals, and, based on the FitnessMethod, selects the better individual. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

GeneNotify(TRSGAGene,TCollectionNotification)

Called when a gene is added or deleted (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

protected method

GenesSizeChange

Called when the size of the entire genome has changed (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

protected method

GeneUpdate(TRSGAGene)

Called when a gene is changed (Inherited from RSGeneticAlgorithm.TRSCustomGeneticAlgorithm.)

protected method

GetAdjustedFitness(TGAFitness)

Calculates the adjusted fitness, a value between 0 and 1, where a bigger value (closer to 1) represents better individuals.

The adjusted fitness equals 1/(1 + StandardizedFitness) when minimizing, and 1/(1+(MaxFitness - StandardizedFitness)) when maximizing.
 

protected method

GetNormalizedFitness(TGAFitness)

Calculates the normalized fitness, a value between 0 and 1.

The normalized fitness equals Fitness / Sum of All Fitness

protected method

GetNormalizedWeightedFitness(TGAFitness)

Calculates the normalized weighted fitness, a value between 0 and 1.

The normalized fitness equals Fitness / Sum of All Weighted Fitness

public method

Initialize

Prepares the genetic component for evolution (or resets the genetic population to start over). On calling the Initialization method, the Population is set to the   InitialPopulation size. The   OnInitialization method is called. Then, the Population's DNA are randomized and each individual's fitness is evaluated. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

InitializeChild(TRSIndividual,TRSIndividual,TRSIndividual)

Initializes the Child with the two parents (usually just a copy of the first parent) (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

Invert(TRSIndividual)

Inverts the DNA of the individual. Inversion for genetic algorithms means flipping the bits of the chromosome. For genetic programs, inversion means a point mutation (replacing a node with another node of the same arity in the tree).

Note that inversion is not guaranteed to occur but is dependent on the     InversionProbability. The function calls the     OnInversion event and then DoInvert method.
 
The Invert method is called by the     Reproduce method. The function returns true if inversion occurred.
 

protected method

IsCustomSelection

Returns true if   SelectionMethod is custom (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

IsFinished

Returns true if the evolution process is complete. The process is complete if the Fitness meets the   FitnessCutoff (if   UseFitnessCutoff is true) or the population diversity meets the   DiversityLimit (if   UseDiversityLimit is true) or the   Generation exceeds the   GenerationLimit (if   UseGenerationLimit is true). (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

LoadFromFile(string)

Loads the entire genetic component from the XML file specified by the Filename parameter, including the Genes (genetic algorithms) or Instructions (genetic programming) and the Population. Use the LoadFromFile and SaveToFile methods to stream in and out the genetic component in XML format. The format of the XML is defined in the GeneticAlgorithm.xsd and GeneticProgramming.xsd schema files. (Overrides RSGeneticBase.TRSCustomGeneticComponent.LoadFromFile(string).)

public method

LoadFromStream(TStream)

Loads the entire genetic component from the XML stream specified by the stream parameter, including the Genes (genetic algorithms) or Instructions (genetic programming) and the Population. Use the LoadFromStream and SaveToStream methods to stream in and out the genetic component in XML format. The format of the XML is defined in the GeneticAlgorithm.xsd and GeneticProgramming.xsd schema files. (Overrides RSGeneticBase.TRSCustomGeneticComponent.LoadFromStream(TStream).)

public method

LoadFromXML(IXMLGADomainType)

Overloaded.  Loads the Genes and the Population from the IXMLGADomainType interface. Use the     LoadFromXML and     SaveToXML methods to read and write only the Genes and Population to XML. The format of the XML is defined in the GeneticAlgorithm.xsd schema file. The TRSCustomGeneticAlgorithm component uses the RSGeneticAlgorithmXML.pas unit and its IXMLGADomainType interface to the XML.

Use the overloaded     LoadFromXML and     SaveToXML methods to read and write the entire TRSCustomGeneticAlgorithm component in XML.
 

public method

LoadFromXML(IXMLGeneticAlgorithm)

Overloaded.  Loads the entire genetic algorithm component from the IXMLGeneticAlgorithm interface, including the     Genes and the     Population. Use the     LoadFromXML and     SaveToXML methods to read and write the genetic algorithm component to XML. The format of the XML is defined in the GeneticAlgorithm.xsd schema file. The TRSCustomGeneticAlgorithm component uses the RSGeneticAlgorithmXML.pas unit and its IXMLGeneticAlgorithm interface to the XML.

Use the overloaded     LoadFromXML and     SaveToXML methods to only read and write the Genes and Population in XML (without the rest of the TRSCustomGeneticAlgorithm properties).
 

public method

Mutate(TRSIndividual)

Mutates the DNA of the individual. Mutation for genetic algorithms means flipping the bits of the chromosome. For genetic programs, mutation means changing nodes of the program tree.

Note that mutation is not guaranteed to occur but is dependent on the     MutationProbability. The function calls the     OnMutation event and then DoMutate method.
 
The Mutate method is called by the     Reproduce method. The function returns true if mutation occurred.
 

protected method

PopulationNotify(TRSIndividual,TCollectionNotification)

Called when an individual is added or removed from the   Population (Overrides RSGeneticBase.TRSCustomGeneticComponent.PopulationNotify(TRSIndividual,TCollectionNotification).)

protected method

PopulationUpdate(TRSIndividual)

Called when an individual has changed (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

PrioritizePopulation

Prioritizes or sorts the population based on Fitness or WeightedFitness and the   FitnessMethod. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

Reproduce(TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded.  The Reproduce method takes the two Parents and "mates" them to create the new Children. The Child parameters must exist but all of their information will be overwritten by the Parents. The New Child is copied from its first parent and then     Crossover,     Mutate, and     Invert are called according to the Operations property and the respective probability of the operation. Finally, an     OnReproduction event occurs.

The Evolve method calls the Reproduce methods.
 

public method

Reproduce(TRSIndividual,TRSIndividual,TRSIndividual,TRSIndividual)

Overloaded.  The Reproduce method takes the two Parents and "mates" them to create the new Children. The Child parameters must exist but all of their information will be overwritten by the Parents. Child1 is copied from the first parent and Child2 is copied from the second parent, and then     Crossover,     Mutate, and     Invert are called according to the Operations property and the respective probability of the operation. Finally, an     OnReproduction event occurs.

The Evolve method calls the Reproduce methods.
 

public method

SaveToFile(string)

Saves the entire genetic component to the XML file specified by the Filename parameter, including the Genes (genetic algorithms) or Instructions (genetic programming) and the Population. Use the LoadFromFile and SaveToFile methods to stream in and out the genetic component in XML format. The format of the XML is defined in the GeneticAlgorithm.xsd and GeneticProgramming.xsd schema files. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

SaveToStream(TStream)

Saves the entire genetic component to the XML stream specified by the stream parameter, including the Genes (genetic algorithms) or Instructions (genetic programming) and the Population. Use the LoadFromFile and SaveToFile methods to stream in and out the genetic component in XML format. The format of the XML is defined in the GeneticAlgorithm.xsd and GeneticProgramming.xsd schema files. (Overrides RSGeneticBase.TRSCustomGeneticComponent.SaveToStream(TStream).)

public method

SaveToXML(IXMLGADomainType)

Overloaded.  Saves the Genes and the Population to the IXMLGADomainType interface. Use the     LoadFromXML and     SaveToXML methods to read and write only the Genes and Population to XML. The format of the XML is defined in the GeneticAlgorithm.xsd schema file. The TRSCustomGeneticAlgorithm component uses the RSGeneticAlgorithmXML.pas unit and its IXMLGADomainType interface to the XML.

Use the overloaded     LoadFromXML and     SaveToXML methods to read and write the entire TRSCustomGeneticAlgorithm component in XML.
 

public method

SaveToXML(IXMLGeneticAlgorithm)

Overloaded.  Saves the entire genetic algorithm component to the IXMLGeneticAlgorithm interface, including the     Genes and the     Population. Use the     LoadFromXML and     SaveToXML methods to read and write the genetic algorithm component to XML. The format of the XML is defined in the GeneticAlgorithm.xsd schema file. The TRSCustomGeneticAlgorithm component uses the RSGeneticAlgorithmXML.pas unit and its IXMLGeneticAlgorithm interface to the XML.

Use the overloaded     LoadFromXML and     SaveToXML methods to only read and write the Genes and Population in XML (without the rest of the TRSCustomGeneticAlgorithm properties).
 

public method

SaveToXML(IXMLGeneticDocumentType)

Overloaded. Saves the entire genetic component to the XML specified by the parameter, including the Genes (genetic algorithms) or Instructions (genetic programming) and the Population. Use the LoadFromFile and SaveToFile methods to stream in and out the genetic component in XML format. The format of the XML is defined in the GeneticAlgorithm.xsd and GeneticProgramming.xsd schema files. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

SelectElitist(TObject,TRSPopulation,TRSIndividual)

Selected a Parent individual from the Population using the Elitist method.

The top nth percentile parents are chosen (and re-chosen) using this method. Elitist is a heavy-weight selection algorithm (in our implementation at least) because we must figure out the top nth percentile population first
 

public method

SelectParent(TRSPopulation)

Selects a parent for the new generation using the   SelectionMethod or the   OnSelection event. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

SelectRandom(TObject,TRSPopulation,TRSIndividual)

Selected a Parent individual from the Population at random.
 (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

protected method

SelectRoulette(TObject,TRSPopulation,TRSIndividual)

Selected a Parent individual from the Population using the Roulette Wheel (fitness proportional) method.

The better "fit" parents are more likely to be chosen (and re-chosen), e.g., the probability of selection is proportional to the fitness of the parent. Also known as fitness proportionate selection.
 

protected method

SelectStochasticTournament(TObject,TRSPopulation,TRSIndividual)

Selected a Parent individual from the Population using the Elitist method.

Select "best" (in this case using roulette wheel) parents from a tournament field (size of tournament field is determined by the     TournamentField property), e.g., select the best parent by selecting better fit individuals proportionally TournamentField times and then choosing the "winner" of the tournament. Note: for speed purposes, this selection method does not ensure that the same individual cannot be picked twice
 

protected method

SelectTournament(TObject,TRSPopulation,TRSIndividual)

Selected a Parent individual from the Population using the Tournament method.

Select "best" parents from a tournament field (size of tournament field is determined by the     TournamentField property), e.g., select the best parent from randomly selecting individuals TournamentField times and then choosing the "winner" of the tournament. Note: for speed purposes, this selection method does not ensure that the same individual cannot be picked twice
 

public method

SwapGenerations

Swaps the Population and PreviousGeneration collections in preparation for evolving a new generation. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

ToString

Provides a strings description of the genetic programming component and its important properties. The function uses the  Describe method to build the string. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

public method

UnfitFitness

Returns a value that represents extreme unfitness. Useful for breeding out an individual by settings its fitness to this value (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

Top

expandingEvents

 

Name

Description

public event

OnEvaluateWeightedFitness

Occurs when the genetic component needs to evaluate weighted fitness for an individual.

Weighted Fitness allows weighting the fitness for searching the solution space to guide the search. Fitness still evaluates if an individual solves the problem, but the weighted fitness can help constrain the search. For example, genetic programs can weight the fitness by reducing the fitness by the size of the program (limiting growth).

alert_cautionImportant Note

Do not repeat your RSGeneticBase.TRSCustomGeneticComponent.OnEvaluateFitness event code here (this is just wasteful) Rather, weight the Individual.Fitness by some function.

public event

OnInversion

Occurs when two parents (TRSIndividual) have reproduced to create a new child and some portion of the child's DNA is about to be inverted. The DoMutation parameter controls whether the inversion will occur. It has already been set based on the   InversionProbability (and so sometimes will be True and sometimes will be False). Set the DoMutation parameter either to force the inversion to occur or to prohibit it from occurring. (Inherited from RSGeneticBase.TRSCustomGeneticComponent.)

Top

expandingExamples

The basic steps for adding genetic algorithms to your applications are:

Drop a RSGeneticAlgorithm.TRSGeneticAlgorithm component on your form
Set up the      Genes or Chromosomes of your population
Define a fitness function ( RSGeneticAlgorithm.TRSGeneticAlgorithm.OnEvaluateFitness event) to properly assess the fitness of each individual, and
Evolve your solution.

 

expandingSee Also

Comments (0)