Common::GaStatistics Class Reference

GaStatistics class keeps track of statistical information about populations, groups of populations or algorithms. It contains information about previous and current statistics, and provides information about progress of statistical values. More...

#include <D:/Temp/vs/gal/source/Statistics.h>

List of all members.

Public Member Functions

 GaStatistics (const GaFitnessComparator *comarator)
 Default constructor initializes all statistical values to zeros and restart generation counter.
GAL_API void GACALL Clear ()
 Clear method clears all statistical information and restarts generation counter.
GAL_API void GACALL NextGeneration ()
 NextGeneration method prepares statistical values for next generation (shifts current values to previous) and increments generation counter.
GAL_API void GACALL CopyFrom (const GaStatistics &stats, bool previous, bool current, bool currentGeneration)
 CopyFrom method copies statistical information and/or generation counter from another object.
int GACALL GetCurrentGeneration () const
 This method is not thread-safe.
GAL_API float GACALL GetValueProgress (GaStatValueType value, bool percent) const
 GetValueProgress method calculates progress of statistical value between previous and current generation.
GAL_API void GACALL ChangeValue (GaStatValueType type, float value, bool relative)
 The method changes statistical value of current generation, change can be absolute or a relative offset to the current value. If GSV_TOTAL_FITNESS, GSV_TOTAL_FITNESS_SCALED or GSV_POPULATION_SIZE values are changed, GSV_AVG_FITNESS and GSV_AVG_FITNESS_SCALED values are updated automatically.
const GaFloatStatValue &GACALL GetValue (GaStatValueType value) const
 This method is not thread-safe.
const GaFitnessComparator *GACALL GetFitnessComarator () const
 This method is not thread-safe.
void GACALL SetFitnessComparator (const GaFitnessComparator *comparator)
 SetFitnessComparator method sets fitness comparator which is going to be used to compare statistical values.
GaStatistics GACALL operator+ (const GaStatistics &rhs)
 This operator produce new object by combining two instances of GaStatistic class. For detailed description of combining statistical values see operator += operator.
GAL_API GaStatistics &GACALL operator+= (const GaStatistics &rhs)
 This operator combines statistical values of two instances of GaStatistics class. Result of combining is stored in this object. Combining is done in fallowing way:
1. Better value between two GSV_BEST_FITNESS values is chosen for new GSV_BEST_FITNESS value.
2. Worse value between two GSV_WORST_FITNESS values is chosen for new GSV_WORST_FITNESS.
3. Two GSV_TOTAL_FITNESS values are summed and the sum becomes new GSV_TOTAL_FITNESS value.
4. Two GSV_POPULATION_SIZE values are summed and the sum becomes new GSV_POPULATION_SIZE.
5. GSV_AVG_FITNES is calculated as: GSV_TOTAL_FITNESS/GSV_POPULATION_SIZE, where GSV_TOTAL_FITNESS and GSV_POPULATION_SIZE have new values.
6. All scaled fitness values are restarted to zeros. These values cannot be combined because they are calculated differently for different populations.

Private Attributes

int _currentGeneration
 Generation counter keeps track of current generation of a population or an algorithm.
GaFloatStatValue _values [GaNumberOfStatValueTypes]
 Array of statistical information. All statistical values are single precision floating-point numbers.
const GaFitnessComparator_fitnessComparator
 Fitness comparator used to compare statistical values.


Detailed Description

GaStatistics class keeps track of statistical information about populations, groups of populations or algorithms. It contains information about previous and current statistics, and provides information about progress of statistical values.

This class has no built-in synchronizator, so LOCK_OBJECT and LOCK_THIS_OBJECT macros cannot be used with instances of this class. No public or private methods are thread-safe.


Constructor & Destructor Documentation

Common::GaStatistics::GaStatistics ( const GaFitnessComparator comarator  )  [inline]

Default constructor initializes all statistical values to zeros and restart generation counter.

Parameters:
comarator fitness comparator used to compare statistical values.


Member Function Documentation

void Common::GaStatistics::Clear (  ) 

Clear method clears all statistical information and restarts generation counter.

This method is not thread-safe.

void Common::GaStatistics::NextGeneration (  ) 

NextGeneration method prepares statistical values for next generation (shifts current values to previous) and increments generation counter.

This method is not thread-safe

void Common::GaStatistics::CopyFrom ( const GaStatistics stats,
bool  previous,
bool  current,
bool  currentGeneration 
)

CopyFrom method copies statistical information and/or generation counter from another object.

This method is not thread-safe.

Parameters:
stats object form which information is going to be copied.
previous if it is set to true, then statistical information form previous generation is copied.
current if it is set to true, then statistical information from current generation is copied.
currentGeneration if it is set to true, then generation counter is copied.

int GACALL Common::GaStatistics::GetCurrentGeneration (  )  const [inline]

This method is not thread-safe.

Returns:
Returns value of generation counter.

float Common::GaStatistics::GetValueProgress ( GaStatValueType  value,
bool  percent 
) const

GetValueProgress method calculates progress of statistical value between previous and current generation.

This method is not thread-safe.

Parameters:
value statistical value which progress is queried.
percent if it is set to true, the method returns progress of the value in percents, otherwise it returns absolute progress.
Returns:
Returns progress of statistical value between previous and current generation. If percent parameter is true, the method return progress in percents, otherwise it returns absolute progress.

void Common::GaStatistics::ChangeValue ( GaStatValueType  type,
float  value,
bool  relative 
)

The method changes statistical value of current generation, change can be absolute or a relative offset to the current value. If GSV_TOTAL_FITNESS, GSV_TOTAL_FITNESS_SCALED or GSV_POPULATION_SIZE values are changed, GSV_AVG_FITNESS and GSV_AVG_FITNESS_SCALED values are updated automatically.

This method is not thread-safe.

Parameters:
type statistical value which is going to be changed.
value new value or relative offset to the current value.
relative if is set to true, value parameter is interpreted as relative offset to the current value, if it is set to false, value parameter is interpreted as new value.

const GaFloatStatValue& GACALL Common::GaStatistics::GetValue ( GaStatValueType  value  )  const [inline]

This method is not thread-safe.

Parameters:
value statistical value which is queried.
Returns:
Returns reference to queried statistical value.

const GaFitnessComparator* GACALL Common::GaStatistics::GetFitnessComarator (  )  const [inline]

This method is not thread-safe.

Returns:
Returns pointer to fitness comparator used to compare statistical values.

void GACALL Common::GaStatistics::SetFitnessComparator ( const GaFitnessComparator comparator  )  [inline]

SetFitnessComparator method sets fitness comparator which is going to be used to compare statistical values.

This method is not thread-safe.

Parameters:
comparator fitness comparator.

GaStatistics GACALL Common::GaStatistics::operator+ ( const GaStatistics rhs  )  [inline]

This operator produce new object by combining two instances of GaStatistic class. For detailed description of combining statistical values see operator += operator.

This operator is not thread-safe.

Parameters:
rhs reference to the second instance of GaStatistic, the first instance is this object.
Returns:
Operator returns new instance of GaStatistic class by value.

GaStatistics & Common::GaStatistics::operator+= ( const GaStatistics rhs  ) 

This operator combines statistical values of two instances of GaStatistics class. Result of combining is stored in this object. Combining is done in fallowing way:
1. Better value between two GSV_BEST_FITNESS values is chosen for new GSV_BEST_FITNESS value.
2. Worse value between two GSV_WORST_FITNESS values is chosen for new GSV_WORST_FITNESS.
3. Two GSV_TOTAL_FITNESS values are summed and the sum becomes new GSV_TOTAL_FITNESS value.
4. Two GSV_POPULATION_SIZE values are summed and the sum becomes new GSV_POPULATION_SIZE.
5. GSV_AVG_FITNES is calculated as: GSV_TOTAL_FITNESS/GSV_POPULATION_SIZE, where GSV_TOTAL_FITNESS and GSV_POPULATION_SIZE have new values.
6. All scaled fitness values are restarted to zeros. These values cannot be combined because they are calculated differently for different populations.

This operation is not thread-safe.

Parameters:
rhs reference to the instance of class GaStatistics which is used for combining result statistical values of this object.
Returns:
The operator returns reference to this object.


Member Data Documentation

Generation counter keeps track of current generation of a population or an algorithm.

Array of statistical information. All statistical values are single precision floating-point numbers.

Fitness comparator used to compare statistical values.


The documentation for this class was generated from the following files:

Genetic Algorithm Library
Coolsoft Software Development