GPLIB++
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gplib::GeneralGA Class Referenceabstract

General genetic algorithm class. More...

#include <GeneralGA.h>

Inheritance diagram for gplib::GeneralGA:
Inheritance graph
[legend]

Public Types

typedef std::vector< gplib::rvec > tparamvector
 We provide some typedefs that are used in other parts as well. More...
 
typedef std::vector
< boost::shared_ptr
< GeneralObjective > > 
tObjectiveVector
 
typedef std::vector
< std::vector< int > > 
tparamindv
 

Public Member Functions

const std::vector< double > & GetWeights ()
 Return the weight for each objecive function. More...
 
void SetupParams (const ttranscribed &member, tparamvector &params)
 Copy the appropriate parameter values from the transcribed vector for use with the objective functions. More...
 
const std::vector< double > & GetAvgFit ()
 Return the average fitness for each objective function. More...
 
void SetElitist (const bool IsElitist)
 Do we want elitist behaviour, effect depends on the GA implementetion in the derived class. More...
 
void SetWeights (const std::vector< double > &LocalWeights)
 Set the weights for each objective function. More...
 
void SetParameterIndices (const tparamindv &Indices)
 Configure which parts of the complete parameter vector are used in each objective function. More...
 
void PrintFitStat (std::ostream &output)
 Print Fitness statistics for each objective function to output. More...
 
void PrintMisfit (std::ostream &output)
 Print misfit for each member to output. More...
 
void PrintTranscribed (std::ostream &output)
 Print transcribed values for each member to output. More...
 
void PrintUniquePop (std::ostream &output)
 Print each population member exactly once. More...
 
void PrintBestMisfit (std::ostream &output)
 Print misfit of the best population members. More...
 
unsigned virtual int GetNBestmodels ()=0
 This has to be implemented in the derived class to return the number of best models. More...
 
virtual std::vector< int > GetBestModelIndices ()=0
 Return the indices of the best models. More...
 
virtual void DoIteration (const int iterationnumber, const bool last)
 Do one iteration of the GA. More...
 
virtual void CalcProbabilities (const int iterationnumber, gplib::rmat &LocalMisFit, GeneralPopulation &LocalPopulation)=0
 Calculate the Probabilities. More...
 
 GeneralGA (GeneralPropagation *const LocalPropagation, GeneralPopulation *const LocalPopulation, GeneralTranscribe *const LocalTranscribe, const tObjectiveVector &IndObjective, const int nthreads=1)
 
virtual ~GeneralGA ()
 

Protected Member Functions

virtual void Elitism (const int iterationnumber)
 default implementation does nothing, this can be overriden More...
 

Protected Attributes

gplib::rmat OldMisFit
 
const unsigned int nobjective
 The number of objective functions we're using. More...
 
gplib::rmat Transcribed
 A matrix holding the numerical model vectors (transcribed from the genes) for each population member. More...
 
gplib::rmat MisFit
 Misfit first index objective function second index population member. More...
 
tObjectiveVector Objective
 The vector holding the objective functions. More...
 
GeneralPropagation *const Propagation
 A pointer to an object dealing with propagation. More...
 
GeneralPopulation *const Population
 A pointer to an object holding the population. More...
 
GeneralTranscribe *const Transcribe
 A pointer to an object translating genes to model vectors. More...
 

Detailed Description

General genetic algorithm class.

GeneralGA implements the functionality that is common to all genetic algorithms it declares a bunch of virtual functions, that are implemented in derived classes and pointers to several other objects that together make up the genetic algorithm

Definition at line 25 of file GeneralGA.h.

Member Typedef Documentation

typedef std::vector<boost::shared_ptr<GeneralObjective> > gplib::GeneralGA::tObjectiveVector

Definition at line 31 of file GeneralGA.h.

typedef std::vector<std::vector<int> > gplib::GeneralGA::tparamindv

Definition at line 32 of file GeneralGA.h.

typedef std::vector<gplib::rvec> gplib::GeneralGA::tparamvector

We provide some typedefs that are used in other parts as well.

Definition at line 29 of file GeneralGA.h.

Constructor & Destructor Documentation

gplib::GeneralGA::GeneralGA ( GeneralPropagation *const  LocalPropagation,
GeneralPopulation *const  LocalPopulation,
GeneralTranscribe *const  LocalTranscribe,
const tObjectiveVector IndObjective,
const int  nthreads = 1 
)

Definition at line 54 of file GeneralGA.cpp.

gplib::GeneralGA::~GeneralGA ( )
virtual

Definition at line 72 of file GeneralGA.cpp.

Member Function Documentation

virtual void gplib::GeneralGA::CalcProbabilities ( const int  iterationnumber,
gplib::rmat &  LocalMisFit,
GeneralPopulation LocalPopulation 
)
pure virtual

Calculate the Probabilities.

Implemented in gplib::AnnealingGA, and gplib::ParetoGA.

Referenced by DoIteration().

void gplib::GeneralGA::DoIteration ( const int  iterationnumber,
const bool  last 
)
virtual
virtual void gplib::GeneralGA::Elitism ( const int  iterationnumber)
inlineprotectedvirtual

default implementation does nothing, this can be overriden

See Also
ParetoGA

Reimplemented in gplib::ParetoGA, and gplib::AnnealingGA.

Definition at line 78 of file GeneralGA.h.

Referenced by DoIteration().

const std::vector<double>& gplib::GeneralGA::GetAvgFit ( )
inline

Return the average fitness for each objective function.

Definition at line 92 of file GeneralGA.h.

virtual std::vector<int> gplib::GeneralGA::GetBestModelIndices ( )
pure virtual

Return the indices of the best models.

Implemented in gplib::AnnealingGA, and gplib::ParetoGA.

Referenced by PrintBestMisfit().

unsigned virtual int gplib::GeneralGA::GetNBestmodels ( )
pure virtual

This has to be implemented in the derived class to return the number of best models.

Implemented in gplib::AnnealingGA, and gplib::ParetoGA.

const std::vector<double>& gplib::GeneralGA::GetWeights ( )
inline

Return the weight for each objecive function.

Definition at line 84 of file GeneralGA.h.

void gplib::GeneralGA::PrintBestMisfit ( std::ostream &  output)

Print misfit of the best population members.

Definition at line 141 of file GeneralGA.cpp.

References GetBestModelIndices(), and MisFit.

void gplib::GeneralGA::PrintFitStat ( std::ostream &  output)

Print Fitness statistics for each objective function to output.

Definition at line 100 of file GeneralGA.cpp.

References nobjective.

void gplib::GeneralGA::PrintMisfit ( std::ostream &  output)

Print misfit for each member to output.

Definition at line 111 of file GeneralGA.cpp.

References MisFit.

void gplib::GeneralGA::PrintTranscribed ( std::ostream &  output)

Print transcribed values for each member to output.

Definition at line 127 of file GeneralGA.cpp.

References Transcribed.

void gplib::GeneralGA::PrintUniquePop ( std::ostream &  output)
inline

Print each population member exactly once.

Definition at line 114 of file GeneralGA.h.

References gplib::UniquePop::PrintAll().

void gplib::GeneralGA::SetElitist ( const bool  IsElitist)
inline

Do we want elitist behaviour, effect depends on the GA implementetion in the derived class.

Definition at line 98 of file GeneralGA.h.

void gplib::GeneralGA::SetParameterIndices ( const tparamindv Indices)

Configure which parts of the complete parameter vector are used in each objective function.

Definition at line 95 of file GeneralGA.cpp.

void gplib::GeneralGA::SetupParams ( const ttranscribed member,
tparamvector params 
)

Copy the appropriate parameter values from the transcribed vector for use with the objective functions.

Definition at line 77 of file GeneralGA.cpp.

References nobjective.

void gplib::GeneralGA::SetWeights ( const std::vector< double > &  LocalWeights)

Set the weights for each objective function.

Definition at line 87 of file GeneralGA.cpp.

Member Data Documentation

gplib::rmat gplib::GeneralGA::MisFit
protected

Misfit first index objective function second index population member.

Definition at line 68 of file GeneralGA.h.

Referenced by DoIteration(), PrintBestMisfit(), and PrintMisfit().

const unsigned int gplib::GeneralGA::nobjective
protected

The number of objective functions we're using.

Definition at line 64 of file GeneralGA.h.

Referenced by DoIteration(), PrintFitStat(), and SetupParams().

tObjectiveVector gplib::GeneralGA::Objective
protected

The vector holding the objective functions.

Definition at line 70 of file GeneralGA.h.

gplib::rmat gplib::GeneralGA::OldMisFit
protected

Definition at line 62 of file GeneralGA.h.

Referenced by DoIteration().

GeneralPopulation* const gplib::GeneralGA::Population
protected

A pointer to an object holding the population.

Definition at line 74 of file GeneralGA.h.

Referenced by DoIteration(), and gplib::AnnealingGA::GetBestIndex().

GeneralPropagation* const gplib::GeneralGA::Propagation
protected

A pointer to an object dealing with propagation.

Definition at line 72 of file GeneralGA.h.

Referenced by DoIteration().

GeneralTranscribe* const gplib::GeneralGA::Transcribe
protected

A pointer to an object translating genes to model vectors.

Definition at line 76 of file GeneralGA.h.

gplib::rmat gplib::GeneralGA::Transcribed
protected

A matrix holding the numerical model vectors (transcribed from the genes) for each population member.

Definition at line 66 of file GeneralGA.h.

Referenced by PrintTranscribed().


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