#include <D:/Temp/vs/gal/source/SimpleAlgorithm.h>
Inherits Algorithm::GaMultithreadingAlgorithm.
Public Member Functions | |
GAL_API | GaSimpleAlgorithm (GaPopulation *population, const GaSimpleAlgorithmParams ¶meters) |
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 ¶meters) |
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. |
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.
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.
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.
virtual const GaAlgorithmParams& GACALL Algorithm::SimpleAlgorithms::GaSimpleAlgorithm::GetAlgorithmParameters | ( | ) | const [inline, virtual] |
This method is not thread-safe.
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.
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.
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.