Genetic Algorithm Common Interface. More...

Inheritance diagram for GeneticAlgo:

Public Member Functions

 GeneticAlgo ()
 Constructor.
virtual ~GeneticAlgo ()
 Destructor.
void addObserver (GeneticAlgoObserver *observer)
 add the observer to the list of current observers
QVector< QVector< double > > averageFits () const
 Return the Average objective values over generation done.
QVector< QVector< double > > bestFits () const
 Return the Best objective values over generation done.
virtual QVector< Evaluation * > evaluationPool ()=0
 Return the Evaluation Pool containing the Evaluations effectively used during evolution.
virtual EvaluationevaluationPrototype ()=0
 Returns the Evaluation object used as prototype to eventually generate other evaluators.
void evolve (unsigned int generationToReach)
 Evolve Genome until reach the generation specified.
void evolve ()
 Evolve Genome until condition isEvolutionEnded has been reached.
virtual void finalize ()=0
 Finalize the Genetic Algorithm Process.
virtual void gaStep ()=0
 Execute a single minor step and return.
unsigned int generation () const
 Return the current generation number.
Genomegenome ()
 Return the current Genome.
const Genomegenome () const
 Return the current Genome.
GeneticAlgoIODelegategetIODelegate () const
 Return the current GeneticAlgoIODelegate.
ParameterSettableUIgetUIManager ()
 return the UI Manager for accessing to the viewers of GeneticAlgo
virtual void initialize ()=0
 Initialize the Genetic Algorithm Process.
bool isEvaluationDone ()
 returns true if we have evaluated genomes for the current generation
bool isEvolutionEnded ()
 returns true if the evolution process has reached the end
QVector< double > meanHammingDist () const
 Return the Mean of Hamming distance over generation done.
int numGenerations ()
 Return the number of Generations.
void removeObserver (GeneticAlgoObserver *observer)
 remove the observer from the list of current observers
void setGeneration (unsigned int gen)
 Set the generation number.
void setGenome (Genome *gen)
 Set the Genome to use as current population.
void setIODelegate (GeneticAlgoIODelegate *iodelegate)
 Set the GeneticAlgoIODelegate to use.
void setNumGenerations (int g)
 Set the number of Generations to do.
virtual void skipEvaluation ()=0
 Skip the evaluation phase and put the algorithm in the state just after the evaluation.
QVector< double > standardDeviationHammingDist () const
 Return the Standard Deviation of Hamming distance over generation done.
QVector< double > varianceHammingDist () const
 Return the Variance of Hamming distance over generation done.
- Public Member Functions inherited from ParameterSettableWithConfigureFunction
void addObserver (RuntimeParameterObserver *obs)
virtual void configure (ConfigurationParameters &params, QString prefix)=0
getRuntimeParameter (QString paramName)
 ParameterSettable ()
virtual void postConfigureInitialization ()
void removeObserver (RuntimeParameterObserver *obs)
virtual void save (ConfigurationParameters &params, QString prefix)=0
void setRuntimeParameter (QString paramName, T newvalue)
QString typeName () const

Protected Member Functions

void notifyEndGeneration ()
 notify that a generation has been done
void updateStats ()
 Update statistical data of current generation and Genome (Mean, Variance, Standard Deviation)
- Protected Member Functions inherited from ParameterSettableWithConfigureFunction
void notifyChangesToParam (QString paramName)

Protected Attributes

QVector< QVector< double > > avgfits
 Statistical Data: report the Average value for each objective for each generation.
QVector< QVector< double > > bestfits
 Statistical Data: report the Best value for each objective for each generation.
bool evaluationDone
 setted by implementors to signal that genomes have been evaluated
when true means that the genomes of the current generation have been evaluated (we are at the end of the end of the generation, next step will be reproduction and start of a new generation), when false means that genomes haven't still not been evaluated (we are at the beginning of a generation, next step will be evaluation of genomes)
bool evolutionEnd
 setted by implementors to signal the finish of evolution process
when true means that evolution is ended
unsigned int generationv
 current generation
Genomegenomev
 current genome
GeneticAlgoIODelegateiodelegate
 the IODelegate
QVector< double > meanHdists
 Statistical Data: report the mean of all hamming distance between genotypes for each generation.
unsigned int numGens
 number of generations
QList< GeneticAlgoObserver * > observers
 the List of Observers
QVector< double > stdHdists
 Statistical Data: report the standard variation of all hamming distance between genotypes for each generation.
QVector< double > varHdists
 Statistical Data: report the variance of all hamming distance between genotypes for each generation.

Additional Inherited Members

- Public Types inherited from ParameterSettableWithConfigureFunction
enum  Property
- Static Public Member Functions inherited from ParameterSettableWithConfigureFunction
static void describe (QString type)
static QString fullParameterDescriptionPath (QString type, QString param)
static QString fullSubgroupDescriptionPath (QString type, QString sub)
- Public Attributes inherited from ParameterSettableWithConfigureFunction
 AllowMultiple
 Default
 IsList
 IsMandatory
- Static Public Attributes inherited from ParameterSettableWithConfigureFunction
static const double Infinity
static const int MaxInteger
static const int MinInteger
- Static Protected Member Functions inherited from ParameterSettableWithConfigureFunction
static Descriptor addTypeDescription (QString type, QString shortHelp, QString longHelp=QString(""))
static void setGraphicalEditor (QString type)

Detailed Description

Genetic Algorithm Common Interface.

Interface of the Genetic Algorithm Process
This class is highly abstract and there is no methods here for setting Selection, Crossover, Mutation and Reproduction processes in order to allow to each sub-class to choose which subset of operator to use.
Hence, it would be possible to create a GA which allow to specify only Mutation and fix the other in some pre-determined ways.

Definition at line 78 of file geneticalgo.h.

Constructor & Destructor Documentation

Constructor.

Definition at line 28 of file geneticalgo.cpp.

~GeneticAlgo ( )
virtual

Destructor.

Definition at line 44 of file geneticalgo.cpp.

References GeneticAlgo::genomev.

Member Function Documentation

void addObserver ( GeneticAlgoObserver observer)

add the observer to the list of current observers

Definition at line 52 of file geneticalgo.cpp.

References GeneticAlgo::observers.

Referenced by GeneticAlgoUI::GeneticAlgoUI().

QVector< QVector< double > > averageFits ( ) const

Return the Average objective values over generation done.

Definition at line 120 of file geneticalgo.cpp.

References GeneticAlgo::avgfits.

Referenced by GeneticAlgoUI::onEndGeneration().

QVector< QVector< double > > bestFits ( ) const

Return the Best objective values over generation done.

Warning
each entry of the vector contains a vector of max values for each objective, but it does not means that exists a genotype scoring all values for all objectives

Definition at line 116 of file geneticalgo.cpp.

References GeneticAlgo::bestfits.

Referenced by GeneticAlgoUI::onEndGeneration().

virtual QVector<Evaluation*> evaluationPool ( )
pure virtual

Return the Evaluation Pool containing the Evaluations effectively used during evolution.

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

virtual Evaluation* evaluationPrototype ( )
pure virtual

Returns the Evaluation object used as prototype to eventually generate other evaluators.

This object could or could not be used to compute the fitness of genotypes (depending on the specific genetic algorithm)

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

void evolve ( unsigned int  generationToReach)

Evolve Genome until reach the generation specified.

This function exists after haveing evaluated individuals of the generationToReach generation

Warning
this method is Blocking

Definition at line 61 of file geneticalgo.cpp.

References GeneticAlgo::evaluationDone, GeneticAlgo::gaStep(), GeneticAlgo::generationv, and GeneticAlgo::isEvolutionEnded().

void evolve ( )

Evolve Genome until condition isEvolutionEnded has been reached.

Warning
this method is Blocking

Definition at line 68 of file geneticalgo.cpp.

References GeneticAlgo::gaStep(), and GeneticAlgo::isEvolutionEnded().

virtual void finalize ( )
pure virtual

Finalize the Genetic Algorithm Process.

In order to create specific Algorithms, re-implement this method

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

virtual void gaStep ( )
pure virtual

Execute a single minor step and return.

In order to create specific Algorithms, re-implement this method

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

Referenced by GeneticAlgo::evolve().

const Genome * genome ( ) const

Return the current Genome.

Definition at line 90 of file geneticalgo.cpp.

References GeneticAlgo::genomev.

ParameterSettableUI * getUIManager ( )
virtual

return the UI Manager for accessing to the viewers of GeneticAlgo

Reimplemented from ParameterSettableWithConfigureFunction.

Definition at line 48 of file geneticalgo.cpp.

virtual void initialize ( )
pure virtual

Initialize the Genetic Algorithm Process.

In order to create specific Algorithms, re-implement this method

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

bool isEvaluationDone ( )

returns true if we have evaluated genomes for the current generation

Definition at line 78 of file geneticalgo.cpp.

References GeneticAlgo::evaluationDone.

bool isEvolutionEnded ( )

returns true if the evolution process has reached the end

Definition at line 74 of file geneticalgo.cpp.

References GeneticAlgo::evolutionEnd.

Referenced by GeneticAlgo::evolve().

QVector< double > meanHammingDist ( ) const

Return the Mean of Hamming distance over generation done.

Definition at line 124 of file geneticalgo.cpp.

References GeneticAlgo::meanHdists.

void notifyEndGeneration ( )
protected
int numGenerations ( )

Return the number of Generations.

Definition at line 112 of file geneticalgo.cpp.

References GeneticAlgo::numGens.

Referenced by StefanoSteadyStateGA::save(), SimpleGA::save(), NSGA2::save(), ParallelGA::save(), and LaralGA::save().

void removeObserver ( GeneticAlgoObserver observer)

remove the observer from the list of current observers

Definition at line 57 of file geneticalgo.cpp.

References GeneticAlgo::observers.

void setGeneration ( unsigned int  gen)

Set the generation number.

Warning
be careful on when you use this function. If you set the generation when isEvaluationDone() is true, the next generation to be evaluated will be gen + 1

Definition at line 94 of file geneticalgo.cpp.

References GeneticAlgo::generationv.

Referenced by StefanoSteadyStateGA::gaStep(), NSGA2::gaStep(), SimpleGA::gaStep(), ParallelGA::gaStep(), LaralGA::gaStep(), StefanoSteadyStateGA::initialize(), SimpleGA::initialize(), NSGA2::initialize(), ParallelGA::initialize(), and LaralGA::initialize().

void setIODelegate ( GeneticAlgoIODelegate iodelegate)

Set the GeneticAlgoIODelegate to use.

Warning
it will not take the owership, so it will be no destroyed by the GeneticAlgo object

Definition at line 139 of file geneticalgo.cpp.

References GeneticAlgo::iodelegate.

void setNumGenerations ( int  g)

Set the number of Generations to do.

Definition at line 108 of file geneticalgo.cpp.

References GeneticAlgo::numGens.

Referenced by StefanoSteadyStateGA::configure(), SimpleGA::configure(), NSGA2::configure(), ParallelGA::configure(), and LaralGA::configure().

virtual void skipEvaluation ( )
pure virtual

Skip the evaluation phase and put the algorithm in the state just after the evaluation.

This can be used after restarting an interrupted evolution to prevent re-evaluation of the genome that was loaded from file.

Implemented in LaralGA, ParallelGA, NSGA2, SimpleGA, and StefanoSteadyStateGA.

QVector< double > standardDeviationHammingDist ( ) const

Return the Standard Deviation of Hamming distance over generation done.

Definition at line 132 of file geneticalgo.cpp.

References GeneticAlgo::stdHdists.

void updateStats ( )
protected

Update statistical data of current generation and Genome (Mean, Variance, Standard Deviation)

This method should be called by the user when it re-implement GeneticAlgo just afert the evaluation of all Genotypes in the Genome

Warning
remember to call it at the right moment, otherwise you will have wrong statistic data

Definition at line 147 of file geneticalgo.cpp.

References Genome::at(), GeneticAlgo::avgfits, GeneticAlgo::bestfits, GeneticAlgo::generationv, GeneticAlgo::genomev, GeneticAlgo::meanHdists, Genotype::numOfObjectives(), Genotype::objective(), Genome::size(), GeneticAlgo::stdHdists, and GeneticAlgo::varHdists.

Referenced by StefanoSteadyStateGA::gaStep(), SimpleGA::gaStep(), NSGA2::gaStep(), ParallelGA::gaStep(), and LaralGA::gaStep().

QVector< double > varianceHammingDist ( ) const

Return the Variance of Hamming distance over generation done.

Definition at line 128 of file geneticalgo.cpp.

References GeneticAlgo::varHdists.

Member Data Documentation

QVector< QVector<double> > avgfits
protected

Statistical Data: report the Average value for each objective for each generation.

Definition at line 206 of file geneticalgo.h.

Referenced by GeneticAlgo::averageFits(), and GeneticAlgo::updateStats().

QVector< QVector<double> > bestfits
protected

Statistical Data: report the Best value for each objective for each generation.

Definition at line 204 of file geneticalgo.h.

Referenced by GeneticAlgo::bestFits(), and GeneticAlgo::updateStats().

bool evaluationDone
protected

setted by implementors to signal that genomes have been evaluated
when true means that the genomes of the current generation have been evaluated (we are at the end of the end of the generation, next step will be reproduction and start of a new generation), when false means that genomes haven't still not been evaluated (we are at the beginning of a generation, next step will be evaluation of genomes)

Definition at line 191 of file geneticalgo.h.

Referenced by GeneticAlgo::evolve(), StefanoSteadyStateGA::gaStep(), NSGA2::gaStep(), SimpleGA::gaStep(), ParallelGA::gaStep(), LaralGA::gaStep(), StefanoSteadyStateGA::initialize(), SimpleGA::initialize(), NSGA2::initialize(), ParallelGA::initialize(), LaralGA::initialize(), GeneticAlgo::isEvaluationDone(), StefanoSteadyStateGA::skipEvaluation(), SimpleGA::skipEvaluation(), NSGA2::skipEvaluation(), ParallelGA::skipEvaluation(), and LaralGA::skipEvaluation().

bool evolutionEnd
protected
unsigned int generationv
protected
GeneticAlgoIODelegate* iodelegate
protected

the IODelegate

Definition at line 215 of file geneticalgo.h.

Referenced by GeneticAlgo::getIODelegate(), and GeneticAlgo::setIODelegate().

QVector<double> meanHdists
protected

Statistical Data: report the mean of all hamming distance between genotypes for each generation.

Definition at line 208 of file geneticalgo.h.

Referenced by GeneticAlgo::meanHammingDist(), and GeneticAlgo::updateStats().

QList<GeneticAlgoObserver*> observers
protected

the List of Observers

Definition at line 217 of file geneticalgo.h.

Referenced by GeneticAlgo::addObserver(), GeneticAlgo::notifyEndGeneration(), and GeneticAlgo::removeObserver().

QVector<double> stdHdists
protected

Statistical Data: report the standard variation of all hamming distance between genotypes for each generation.

Definition at line 212 of file geneticalgo.h.

Referenced by GeneticAlgo::standardDeviationHammingDist(), and GeneticAlgo::updateStats().

QVector<double> varHdists
protected

Statistical Data: report the variance of all hamming distance between genotypes for each generation.

Definition at line 210 of file geneticalgo.h.

Referenced by GeneticAlgo::updateStats(), and GeneticAlgo::varianceHammingDist().


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