TGPopulation component

Genetic Programming Population.

Properties
Methods
Events
Variables

Copyright © 1999-2001 Adi Andrei - aandrei@writeme.com


Properties

property BestIndex : Integer

Index of the best individual in the population. To get the body of this individual:

var MyBody:string; begin MyBody := Gp.Ind[BestIndex].Body; .... end;


property CrossoverP : Percent

Percent of individuals to perform crossover on when creating a new population/generation. Default is 50.


property Elite : Boolean

Keep the best individual in the next generation. Default is True.

property FitStop : Integer

Fitness Stop Condition. Default is 90.

property GenCount : Integer

No of generations to run when using Execute method. Default is 50.

property IndCount : Integer

No of individuals. Default is 100.

property IndLength : Integer

Maximum length for an individual. Default is 1024.

property InstantFitness : Integer

Used with OnIndEval event. Default is 0.

property ZeroFnP : Percent

Probability of functions in generation zero. Default is 50.

property ZeroIndLenP : Percent

Max length of an individual in gen zero, as percent of IndLength. Default is 50.


Methods

procedure AddFn(f: string; p:integer)

Add function to the function set. ( function name ; no of parameters)


procedure AddTerm(t:string)

Add a terminal to the terminal symbols set.

function Best:integer

Returns the index of the best individual.

constructor Create(AOwner: TComponent); override

Constructor.

destructor Destroy; override

Destructor.

procedure Err(m:string)

Generate an error.

procedure Eval

Evaluate Population.

function Execute : Boolean

Automatically run the following sequence :

Running:=true; Gen:=0; GenZero; Result:=GoOn;


procedure GenX


procedure GenZero

Run Generation Zero.

function GetFnCount:integer

Returns the number of functions in the function set.

function GetTermCount : integer

Returns the number of terminals in the terminal set.

function GoON:boolean

Automatically run the remaining generations until reaching the end or until the FitStop condition is satisfied.


procedure Init

Initialize population. Clears the terminal / function set. Clears all individuals.


procedure InitRoulete

Initialize the roulete.

procedure Loaded; override


procedure NextGen

Run (evolve) the next generation.

procedure Stop

Stop running started by Execute method.

function cross(s1:string;s2:string):string

Perform crossover on to s-expressions.

function draw:integer



Events

event OnAfterIndEval(Sender : TObject)

Occurs after evaluating one individual.


event OnAfterPopEval(Sender : TObject)


event OnBeforeIndEval(Sender : TObject)

Occurs before evaluating one individual.


event OnBeforePopEval(Sender : TObject)


event OnFitReached(Sender : TObject)

Minimum specified fitness reached.

event OnIndEval(Sender : TObject; Body:string)

Custom individual evaluation function to be designed by the user. In the body of the event handling function, set the Instantfitness property.

ex:

procedure TForm1.GPIndEval(Sender: TObject; Body: String); Begin Gp.InstantFitness:= user_eval(Body); End;

where: - Body is the body of the individual (s-expression) to evaluate. - InstantFitness is the fitness that will be associated to that individual. - Gp is an instance of the GPopulation component, used for the example. - user_eval(Body) is the fitness function writen by the user



Variables

variable FnCount : Integer

No of functions in the function set. Initial value is 0.

variable FnSet : Fn_Array

Function set.

variable Gen : Integer

Generation running. Initial value is 0.

variable Ind : Ind_array

Original population.

variable Ind2 : Ind_array

Mating pool.

variable Roulete : Rulete_array

Selection roulete.

variable Running : Boolean

Is the 'execute' method running ? Initial value is False.

variable TermCount : Integer

No of terminals in the terminal symbols set. Initial value is 0.

variable TermSet : Term_array

Terminal symbols set.

variable X : TIndividual

maneuver individual.