TGen

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


Description

Class representing a gene. In fact it contains binary string and methods supporting its editing.

Up.gif (1072 bytes)


Warnings

TGen knows its parent population (parent) and its place in it (index) and uses it while moving from one population to another.

Up.gif (1072 bytes)


Methods

Public:
TGen(uint ilength, ini_type itype = all0, TPopulation* iparent = NULL, uint iindx = 0)
TGen()
TGen(BYTE** rawbytes,uint len,BOOL subclass=FALSE)
virtual ~TGen()

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

BOOL SetFit(TFit fit)
TFit GetFit()
BOOL SetScaledFit(TFit fit)
TFit GetScaledFit()
uint GetLength()
uint GetByte(uint i,BYTE** byte)
BOOL SetBit(uint i, BOOL value = TRUE)
TFitness *GetFitFunc()
void SetDirty()
BOOL GetDirty()
Protected:
Private:


TGen(uint ilength, ini_type itype = all0, TPopulation* iparent = NULL, uint iindx = 0)

Basic constructor. Creates new gene and initis it.

Arguments:

ilength ... length of string in bits
itype ... type of string initialisation (default all0)
iparent ... pointer to the population owning this object (default NULL)
iindx ... index of this object in population (default 0)

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


TGen()

Creates an empty gene. Everythig is set to zero and the bit string is not allocated.

Arguments:

none

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


uint GetLength()

Returns the bit length of the bit string.

Arguments:

none

Returns:

The bit length of the string.

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


uint GetByte(uint i,BYTE** byte)

Gives access to the part (byte) of the bit string.

Arguments:

i ... index of requested byte (0 is the first byte)
byte ... points to pointer to requested byte (*byte points finaly to the requested byte)

Returns:

The number of valid bits in requested byte (**byte).
ie. 3 means that 3 highest bits in **byte are valid, returns 0 if argument i is too big.

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


BOOL SetBit(uint i, BOOL value = TRUE)

Gives access to the single bit of the bit string.

Arguments:

i ... index of bit (0 is the first bit of the string)
value ... new value of the specified bit (default TRUE)

Returns:

old value of the specified bit

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


TFitness *GetFitFunc()

Gives access to the object responsible for fitness measuring. See TFitness class for more info.

Arguments:

none

Returns:

pointer to the fitness function

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




Atributes

Public:
TPopulation *parent
uint index
Protected:
BYTE *bitarray
TFit fitness
TFit scfitness
uint genlength
uint length
BOOL dirty
Private:


TPopulation *parent

Pointer to the population owning this individual.

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


uint index

Index of this individual in the parent population.

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


BYTE *bitarray

The bit string representing the genetic info of the individual.

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


TFit fitness

The current fitness evaluation value of the individual.

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


TFit scfitness

The current fitness evaluation value of the individual scaled to the wider range of values.

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


uint genlength

The length (in bits) of the string.

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


uint length

The length (in bytes) of the string.

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


BOOL dirty

TRUE when the fitness evaluation value is not valid and should be recomputed before usage.

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




Operators

Public:
int MyOper(void) TGen& operator = (TGen& gen)
BOOL operator [] (uint i)
BOOL operator == (TGen& gen)
BOOL operator >> (TGen& gen)
Protected:
Private:


TGen& operator = (TGen& gen)

The content of this object is deleted and refilled with copy of content of argument. Index and parent population remain unchanged.

Arguments:

gen ... gen for assignment

Returns:

itself

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


BOOL operator [] (uint i)

Gives acces to the value(!!) of bit in the bit string. Expression "gen[i] = 0;" isn't possible, use method SetBit instead.

Arguments:

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

Returns:

value of requested bit

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


BOOL operator == (TGen& gen)

Compares contents of two strings. Gens are equal if their lengths and bit strings are equal.

Arguments:

gen ... gen to compare

Returns:

TRUE if strings are equal

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


BOOL operator >> (TGen& gen)

Moves this gen into another population instead of gen specifed by argument. Argument is destroyed and parent population of this gen is reduced by 1. This operator moves only pointers, doesn't copy contents. Both gens (this and specified by argument) must be a member of some population.

Arguments:

gen ... string to replace

Returns:

FALSE if the parent population doesn't exist

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




Specials

None.

Up.gif (1072 bytes)