MOGAL
Public Member Functions | Protected Member Functions

mogal::GAFactory Class Reference

A genetic algorithm factory, which contains all problem-specific code. More...

#include <gafactory.h>

Inheritance diagram for mogal::GAFactory:
Inheritance graph
[legend]
Collaboration diagram for mogal::GAFactory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual GAFactoryParamscreateParamsInstance () const =0
 Allocate an instace of the GAFactoryParams implementation which corresponds to this factory (should be deleted afterwards).
virtual const GAFactoryParamsgetCurrentParameters () const =0
 Returns an instance of the GAFactoryParams containing the parameters with which this factory was initialized.
virtual bool init (const GAFactoryParams *pFactoryParams)=0
 Initialize the factory.
virtual size_t getNumberOfFitnessComponents () const =0
 Returns the number of fitness components.
virtual GenomecreateNewGenome () const =0
 Creates a new, randomly initialized genome that corresponds to this particular genetic algorithm.
virtual size_t getMaximalGenomeSize () const =0
 Returns the maximum number of bytes that are needed for serializing a genome belonging to this factory.
virtual size_t getMaximalFitnessSize () const =0
 Returns the maximum number of bytes that are needed for serializing the fitness measures belonging to this factory.
virtual bool writeGenome (serut::SerializationInterface &si, const Genome *pGenome) const =0
 Serializes the genome information in pGenome.
virtual bool writeGenomeFitness (serut::SerializationInterface &si, const Genome *pGenome) const =0
 Serializes the fitness information in the genome pGenome.
virtual bool writeCommonGenerationInfo (serut::SerializationInterface &si) const =0
 Writes some additional information after the pGenerationInfoChanged flag in GAFactory::onGeneticAlgorithmStep was set (you probably won't need this).
virtual bool readGenome (serut::SerializationInterface &si, Genome **pGenome) const =0
 De-serialize a genome and store it in pGenome.
virtual bool readGenomeFitness (serut::SerializationInterface &si, Genome *pGenome) const =0
 De-serialize the fitness information and store it in genome pGenome.
virtual bool readCommonGenerationInfo (serut::SerializationInterface &si)=0
 Read some additional information (see GAFactory::writeCommonGenerationInfo).
virtual void onGeneticAlgorithmStep (int generation, bool *pGenerationInfoChanged, bool *pStopAlgorithm)=0
 This function is called each time a generation has been processed.
virtual void onGeneticAlgorithmStart ()
 This is called when the algorithm is started.
virtual void onGeneticAlgorithmStop ()
 This is called when the algorithm is stopped.
virtual void onSortedPopulation (const std::vector< GenomeWrapper > &population)
 This is called after the population has been sorted using the GAFactory::sort function.
virtual void sort (std::vector< GenomeWrapper > &population)=0
 Sort the genomes in population according to their fitness.
virtual void updateBestGenomes (std::vector< GenomeWrapper > &population)=0
 Inspect the genomes in population and update the current set of best genomes.
virtual void breed (const std::vector< GenomeWrapper > &population, std::vector< GenomeWrapper > &newPopulation)=0
 Create a new population based on an existing one.
virtual void introduceMutations (std::vector< GenomeWrapper > &population)=0
 Introduce mutations in the genomes in population.
virtual GenomeselectPreferredGenome (const std::list< Genome * > &bestGenomes) const =0
 From the genomes in bestGenomes, select the preferred one (this is necessary in a multi-objective genetic algorithm.
virtual const
RandomNumberGenerator
getRandomNumberGenerator () const =0
 Return the random number generator used by this factory.

Protected Member Functions

GeneticAlgorithmgetCurrentAlgorithm ()
 Returns a pointer to the current genetic algorithm instance.
GeneticAlgorithmParams getCurrentAlgorithmParameters () const
 Returns a pointer to the current genetic algorithm parameters.

Detailed Description

A genetic algorithm factory, which contains all problem-specific code. This interface contains several purely virtual functions which have to be implemented. Some defaults for single-objective and multi-objective genetic algorithms are provided in the classes GAFactorySingleObjective and GAFactoryMultiObjective respectively.


Member Function Documentation

virtual void mogal::GAFactory::breed ( const std::vector< GenomeWrapper > &  population,
std::vector< GenomeWrapper > &  newPopulation 
) [pure virtual]
GeneticAlgorithm* mogal::GAFactory::getCurrentAlgorithm ( ) [inline, protected]
GeneticAlgorithmParams mogal::GAFactory::getCurrentAlgorithmParameters ( ) const [inline, protected]
virtual size_t mogal::GAFactory::getNumberOfFitnessComponents ( ) const [pure virtual]

Returns the number of fitness components. For a standard genetic algorithm, this will be one; in a multi-objective genetic algorithm, multiple fitness measures are optimized at the same time.

virtual const RandomNumberGenerator* mogal::GAFactory::getRandomNumberGenerator ( ) const [pure virtual]
virtual bool mogal::GAFactory::init ( const GAFactoryParams pFactoryParams) [pure virtual]

Initialize the factory.

Parameters:
pFactoryParamsParameters which should be used during the factory initialization. This information must be copied since this particular instance may be destroyed!
virtual void mogal::GAFactory::introduceMutations ( std::vector< GenomeWrapper > &  population) [pure virtual]
virtual void mogal::GAFactory::onGeneticAlgorithmStart ( ) [inline, virtual]
virtual void mogal::GAFactory::onGeneticAlgorithmStep ( int  generation,
bool *  pGenerationInfoChanged,
bool *  pStopAlgorithm 
) [pure virtual]

This function is called each time a generation has been processed.

Parameters:
generationThe current generation number.
pGenerationInfoChangedSet this to true if some additional information needs to be transmitted in a distributed calculation. This can be necessary if the fitness calculation procedure needs to be modified while the algorithm is running. You probably won't need this though.
pStopAlgorithmSet this to true when the stopping criterion for your algorithm has been reached. You must do this at some point, otherwise the algorithm will run forever.
virtual void mogal::GAFactory::onGeneticAlgorithmStop ( ) [inline, virtual]
virtual void mogal::GAFactory::onSortedPopulation ( const std::vector< GenomeWrapper > &  population) [inline, virtual]
virtual bool mogal::GAFactory::readCommonGenerationInfo ( serut::SerializationInterface &  si) [pure virtual]
virtual bool mogal::GAFactory::readGenome ( serut::SerializationInterface &  si,
Genome **  pGenome 
) const [pure virtual]
virtual bool mogal::GAFactory::readGenomeFitness ( serut::SerializationInterface &  si,
Genome pGenome 
) const [pure virtual]
virtual void mogal::GAFactory::sort ( std::vector< GenomeWrapper > &  population) [pure virtual]
virtual void mogal::GAFactory::updateBestGenomes ( std::vector< GenomeWrapper > &  population) [pure virtual]
virtual bool mogal::GAFactory::writeGenome ( serut::SerializationInterface &  si,
const Genome pGenome 
) const [pure virtual]
virtual bool mogal::GAFactory::writeGenomeFitness ( serut::SerializationInterface &  si,
const Genome pGenome 
) const [pure virtual]

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