TPopulation

List of predecestors:
TObj
Files:
pop.h, pop.cpp
Desc. & Idea Warnings Methods Atributes Operators Specials


Description

Class representing a population. It is realized as array of TGen objects. The gens have a position (index) in population, but this can vary during the life of population.

Up.gif (1072 bytes)


Warnings

TPopulation has two two different atributes specifing its size. First is size that means the number of actually present gens in population. Second allocated is the size of space prepared for gens created in future.

Up.gif (1072 bytes)


Methods

Public:
TPopulation(uint ialloc,TFitness* AFitFunc,uint iinc = 1)
TPopulation(uint isize, uint ialloc, uint igenlength, TFitness* AFitFunc,uint iinc=1, ini_type itype=rndm)
TPopulation(TPopulation& pop)
TPopulation(TGen& gen)
TPopulation(BYTE** rawbytes,uint len,BOOL subclass=FALSE)
virtual ~TPopulation()

virtual char* Dump()
virtual uint GetSerSize(BOOL subclass=FALSE)
virtual uint Serialize(BYTE **rawbytes,BOOL subclass=FALSE)

uint GetSize()
uint GetAllocated()
uint GetInc()
uint SetInc(uint i)
virtual TFitness *GetFitFunc()
virtual void SetFitFunc(TFitness *val)
BOOL Insert (TGen& gen)
BOOL Delete (uint i, BOOL destroy = TRUE)
BOOL InsertPop (TPopulation& pop)
BOOL FillToSize (TPopulation& from, uint nsize = 0)
void Empty()
Protected:
Private:


TPopulation(uint ialloc,TFitness *AFitFunc,uint iinc = 1)

Constructor of TPopulation. Allocates requested space, but no gen is created.

Arguments:

ialloc ... number of gens (TGen*) to allocate space for
iinc ... expansion increment (default 1)

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation(uint isize, uint ialloc, uint igenlength, TFitness* AFitFunc,uint iinc=1, ini_type itype=rndm)

Constructor of TPopulation. Allocates requested space and requested number of gens is created and initialized.

Arguments:

isize ... number of gens to create
ialloc ... number of gens (TGen*) to allocate space for
igenlength ... bit length of the gen
AFitFunc ... pointer to the fitness function
iinc ... expansion increment (default 1)
iini ... type of gen initialization (default rndm)

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation(TPopulation& pop)

Copy constructor.

Arguments:

pop ... source population

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation(TGen& gen)

Constructor of TPopulation. Creates population of size 1. Allocated space is also 1. The only gen in population is exact copy of the argument. Usage: when you need to use gen as a population (temporaly)
SomeProcUsingPopulation( TPopulation(gen) );

Arguments:

gen ... string for population

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL Insert (TGen& gen)

Inserts copy of argument into population. If there is not enough allocated space,then the population's space will be expanded by inc

Arguments:

gen ... string to insert

Returns:

TRUE if no error occurs

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL Delete (uint i, BOOL destroy = TRUE)

Releases the gen from the population. The object TGen is destroyed if requested. The empty space in array is filled by the last TGen in the array, so the indexes of gens are changed by this method!

Arguments:

i ... index of gen to delete
destroy ... should be the gen destructed? (default TRUE)

Returns:

TRUE if no error occurs

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL InsertPop (TPopulation& pop)

Inserts copy of population.

Arguments:

pop ... population to insert

Returns:

TRUE if no error occurs

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


BOOL FillToSize (TPopulation& from, uint nsize = 0)

Inserts copy of population up to specified size. If size is zero, the allocated space of this population is filled up.

Arguments:

from ... population to copy from
nsize ... size to fill this population up (default 0)

Returns:

TRUE if size of this population is exactly nsize

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


void Empty()

Empties the population, all gens are destructed, size is set to zero. The allocated space doesn't change.

Arguments:

none

Returns:

nothing

arrow3u.gif (362 bytes) Up.gif (1072 bytes)




Atributes

Public:
TGen **individual
Protected:
uint size
uint inc
uint allocated
Private:
TFitness *FitFunc


TGen **individual

An array of pointers to the population members.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


uint size

The actual number of gens present in the population.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


uint inc

The allocation increment used when the population should expand.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


uint allocated

The size of the allocated array of gens. Not all must be actualy present!

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TFitness *FitFunc

Pointer to the object representing fitness function. See TFitness class for more info.

arrow3u.gif (362 bytes) Up.gif (1072 bytes)




Operators

Public:
operator TGen&()
TGen& operator [] (uint i)
TPopulation& operator = (TPopulation& pop)
TPopulation& operator << (TGen& gen)
TPopulation& operator << (TPopulation& pop)
Protected:
Private:


operator TGen&()

Conversion operator to class TGen. Call everytime the TPopulation is used instead of TGen. Then the first gen of population is used.

Arguments:

none

Returns:

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TGen& operator [] (uint i)

Gives access to the member (gen) of population.

Arguments:

i ... index of string, 0 is the first string

Returns:

requested string

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation& operator = (TPopulation& pop)

Population assignment. Content of this population is deleted and it is filled up with a copy of the argument.

Arguments:

pop ... population to copy from

Returns:

itself

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation& operator << (TGen& gen)

Moves gen to this population (fast pointer change). If the gen is a member of some other population, then it's removed from it. Needed space is allocated.

Arguments:

gen ... gen to move

Returns:

itself

arrow3u.gif (362 bytes) Up.gif (1072 bytes)


TPopulation& operator << (TPopulation& pop)

Moves argument to this population (fast pointer change). Needed space is allocated.

Arguments:

pop ... population to move, will be empty after this operator

Returns:

itself

arrow3u.gif (362 bytes) Up.gif (1072 bytes)




Specials

None.

Up.gif (1072 bytes)