Algorithm::SimpleAlgorithms::GaSimpleAlgorithm Class Reference

Simple algorithm creates entirely new population of chromosomes at the end of each generation, only specified number of best chromosomes survive and they are copied into new generation. This algorithm uses two populations to avoid overlapping of generations which are used alternately. More...

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

Inherits Algorithm::GaMultithreadingAlgorithm.

List of all members.

Public Member Functions

GAL_API GaSimpleAlgorithm (GaPopulation *population, const GaSimpleAlgorithmParams &parameters)
 This constructor initializes algorithm with population on which evolution is performed and with parameters of algorithm. It also makes helper population with exactly the same setup as the original population which is used to prevent overlapping of generations.
virtual GAL_API ~GaSimpleAlgorithm ()
 The destructor destroys helper population and frees memory used by elitism buffer and result sets.
virtual const
GaAlgorithmParams &GACALL 
GetAlgorithmParameters () const
 This method is not thread-safe.
virtual GAL_API void GACALL SetAlgorithmParameters (const GaAlgorithmParams &parameters)
 This method should be called from classes which are inheriting this class when user changes algorithm parameters.
virtual const GaPopulation &GACALL GetPopulation (int index) const
 Population with index 0 is original population, and population with index 1 is helper population.
virtual const GaStatistics &GACALL GetAlgorithmStatistics () const
 GetAlgorithmStatistics method returns reference to object which stores statistical information about population which handles current generation.

Protected Member Functions

virtual GAL_API void GACALL Initialize ()
 This method initializes original population by calling GaPopulation::Initialize method, and clears helper population.
virtual GAL_API void GACALL BeforeWorkers ()
 This operation performs selection of chromosomes from population of current generation. It uses selection operation provided by the population.
virtual GAL_API void GACALL WorkStep (int workerId)
 This operation stores best chromosome in elitism buffer and performs coupling operation and produces offspring chromosomes by using previously selected chromosomes as parents. It uses coupling operation provided by the population.
virtual GAL_API void GACALL AfterWorkers ()
 This method inserts offspring chromosomes and chromosomes from elitism buffer into population which will handle next generation. It also transfers statistics from current population to next.

Private Attributes

GaPopulationType _currentPopulation
 Indicates which population, of two, is used for current generation.
GaChromosomePtr_elitismBuffer
 Pointer to array which is used to store best chromosomes which will survive to the next generation.
int _savedChromosomes
 Number of chromosomes which are stored in elitism buffer.
GaCouplingResultSet_buffers [2]
 Pointers to coupling result sets (and selection result sets) which are used for storing produced offspring which are going to be inserted in new generation. Each population has its own coupling and selection sets.
GaPopulation_populations [2]
 Array of pointers to two non-overlapping populations which are used by algorithm.
GaSimpleAlgorithmParams _parameters
 Parameters of genetic algorithm.


Detailed Description

Simple algorithm creates entirely new population of chromosomes at the end of each generation, only specified number of best chromosomes survive and they are copied into new generation. This algorithm uses two populations to avoid overlapping of generations which are used alternately.

This class has no built-in synchronizator, so LOCK_OBJECT and LOCK_THIS_OBJECT macros cannot be used with instances of this class, but all public method and operators are thread-safe.


Constructor & Destructor Documentation

Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::GaSimpleAlgorithm ( GaPopulation population,
const GaSimpleAlgorithmParams parameters 
)

This constructor initializes algorithm with population on which evolution is performed and with parameters of algorithm. It also makes helper population with exactly the same setup as the original population which is used to prevent overlapping of generations.

Parameters:
population pointer to population on which evolution is performed.
parameters reference to parameters of algorithm.

Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::~GaSimpleAlgorithm (  )  [virtual]

The destructor destroys helper population and frees memory used by elitism buffer and result sets.


Member Function Documentation

virtual const GaAlgorithmParams& GACALL Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::GetAlgorithmParameters (  )  const [inline, virtual]

This method is not thread-safe.

Returns:
Method returns reference to parameters of algorithm.

Implements Algorithm::GaAlgorithm.

void Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::SetAlgorithmParameters ( const GaAlgorithmParams parameters  )  [virtual]

This method should be called from classes which are inheriting this class when user changes algorithm parameters.

More details are given in specification of GaAlgorithm::SetAlgorithmParameters method.

This method is thread-safe.

Reimplemented from Algorithm::GaMultithreadingAlgorithm.

virtual const GaPopulation& GACALL Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::GetPopulation ( int  index  )  const [inline, virtual]

Population with index 0 is original population, and population with index 1 is helper population.

More details are given in specification of GaAlgorithm::SetPopulation method.

This method is thread-safe.

Implements Algorithm::GaAlgorithm.

virtual const GaStatistics& GACALL Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::GetAlgorithmStatistics (  )  const [inline, virtual]

GetAlgorithmStatistics method returns reference to object which stores statistical information about population which handles current generation.

More details are given in specification of GaAlgorithm::SetAlgorithmStatistics method.

This method is thread-safe.

Implements Algorithm::GaAlgorithm.

void Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::Initialize (  )  [protected, virtual]

This method initializes original population by calling GaPopulation::Initialize method, and clears helper population.

Implements Algorithm::GaBaseAlgorithm.

void Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::BeforeWorkers (  )  [protected, virtual]

This operation performs selection of chromosomes from population of current generation. It uses selection operation provided by the population.

Reimplemented from Algorithm::GaMultithreadingAlgorithm.

void Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::WorkStep ( int  workerId  )  [protected, virtual]

This operation stores best chromosome in elitism buffer and performs coupling operation and produces offspring chromosomes by using previously selected chromosomes as parents. It uses coupling operation provided by the population.

Parameters:
workerId identification number of working thread.

Reimplemented from Algorithm::GaMultithreadingAlgorithm.

void Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::AfterWorkers (  )  [protected, virtual]

This method inserts offspring chromosomes and chromosomes from elitism buffer into population which will handle next generation. It also transfers statistics from current population to next.

Reimplemented from Algorithm::GaMultithreadingAlgorithm.


Member Data Documentation

Indicates which population, of two, is used for current generation.

Pointer to array which is used to store best chromosomes which will survive to the next generation.

Number of chromosomes which are stored in elitism buffer.

Pointers to coupling result sets (and selection result sets) which are used for storing produced offspring which are going to be inserted in new generation. Each population has its own coupling and selection sets.

Array of pointers to two non-overlapping populations which are used by algorithm.

Parameters of genetic algorithm.


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

Genetic Algorithm Library
Coolsoft Software Development