Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SingletonGenEngine Class Reference

This is the engine of the gen. More...

#include <SingletonGenEngine.h>

Collaboration diagram for SingletonGenEngine:

Public Member Functions

const std::vector
< GenPrototype * > & 
getSetOfGenPrototyps (void) const
 this function returns a set of all registered GenPrototypes. More...
 
int getNumGeneration (void) const
 this function return the number of Generation inside. More...
 
GenerationgetGeneration (int x)
 this function returns one Generation More...
 
int getActualGenerationNumber (void) const
 returns the actual generation number, on which the alg. More...
 
GenerationgetActualGeneration (void)
 returns the actual Generation. More...
 
int getNumIndividual (void) const
 returns the number of individual inside the alg. More...
 
IndividualgetIndividual (int x) const
 returns one individual More...
 
void addGenPrototype (GenPrototype *prototype)
 registered a GenPrototype in the engine. More...
 
void addGen (Gen *gen)
 registered a Gen in the engine. More...
 
GengetGen (int x) const
 returns one gene More...
 
void addIndividual (Individual *individual)
 registered a individual in the engine. More...
 
void addGeneration (Generation *generation)
 add a Generation to the alg. More...
 
void generateFirstGeneration (int startSize, int numChildren, RandGen *random, bool withUpdate=true)
 prepare the alg. More...
 
void prepareNextGeneration (int size, int numChildren)
 prepare the next generation. More...
 
void prepare (int startSize, int numChildren, InspectableProxy *&proxyGeneration, InspectableProxy *&proxyGene, RandGen *random, PlotOptionEngine *plotEngine=0, PlotOptionEngine *plotEngineGenContext=0, bool withUpdate=true)
 prepare the first generation with "generateFirstGeneration" and init the measures. More...
 
int getNextGenerationSize ()
 return the size of the next generation. More...
 
void measureStep (double time, InspectableProxy *&proxyGeneration, InspectableProxy *&proxyGene, PlotOptionEngine *plotEngine=0, PlotOptionEngine *plotEngineGenContext=0)
 makes a step in the measure More...
 
void runGenAlg (int startSize, int numChildren, int numGeneration, RandGen *random, PlotOptionEngine *plotEngine=0, PlotOptionEngine *plotEngineGenContext=0)
 this function is for a automatically run of the gen. More...
 
void select (bool createNextGeneration=true)
 make the select of the actual generation and transfer it to the next generation More...
 
void crossover (RandGen *random)
 in the actual generation it will generate the children of the living individual More...
 
void update (double factor=1.5)
 this function makes a update on the statistical data of the gen. More...
 
void setSelectStrategy (ISelectStrategy *strategy)
 decid the select strategy More...
 
void setGenerationSizeStrategy (IGenerationSizeStrategy *strategy)
 decide the generation size strategy. More...
 
void setFitnessStrategy (IFitnessStrategy *strategy)
 decide the fitness strategy. More...
 
double getFitness (const Individual *individual)
 calculate for a individual the fitness value. More...
 
IndividualgetBestIndividual (void)
 returns the best individual (where the fitness is next to zero) which the alg. More...
 
std::string getIndividualRoot (bool withMutation=true) const
 returns a complete list of the inheritance of all individual. More...
 
std::string getAllIndividualAsString (void) const
 returns a list of all individual and there gens values. More...
 
virtual bool store (FILE *f) const
 stores the object to the given file stream (binary). More...
 
virtual bool restore (FILE *f, InspectableProxy *&proxyGeneration, InspectableProxy *&proxyGene, PlotOptionEngine *plotEngine, PlotOptionEngine *plotEngineGenContext)
 loads the object from the given file stream (binary). More...
 

Static Public Member Functions

static SingletonGenEnginegetInstance (void)
 returns the only existing engine. More...
 
static void destroyGenEngine (bool cleanStrategies=false)
 destroy the only existing engine. More...
 

Protected Attributes

std::vector< GenPrototype * > m_prototype
 managment storage for all Genprototypes. More...
 
std::vector< Generation * > m_generation
 managment storage for all Generation More...
 
std::vector< Individual * > m_individual
 management storage for all Individual More...
 
std::vector< Gen * > m_gen
 management storage for all Gens More...
 
int m_actualGeneration
 the number of the actual generation More...
 
ISelectStrategym_selectStrategy
 the select strategy of the alg. More...
 
IFitnessStrategym_fitnessStrategy
 the fitness strategy of the alg. More...
 
IGenerationSizeStrategym_generationSizeStrategy
 the generation size strategy of the alg. More...
 
bool m_cleanStrategies
 flag for clean the seted strategies More...
 
std::map< int,
RESTORE_GA_GENERATION * > 
m_restoreGeneration
 Map for restoring the generations from a run before. More...
 
std::map< int,
RESTORE_GA_INDIVIDUAL * > 
m_restoreIndividual
 Map for restoring the individuals from a run before. More...
 
std::map< int, std::vector< int > > m_restoreIndividualInGeneration
 Map for restoring the individual generation link from a run before. More...
 
std::map< int, std::vector< int > > m_restoreGeneInIndividual
 Map for restoring the genes individual link from a run before. More...
 
std::map< int, std::string > m_restoreNameOfIndividuals
 Map for restoring the names of the individuals. More...
 

Static Protected Attributes

static SingletonGenEnginem_engine = 0
 the one and only GenEngine. More...
 

Detailed Description

This is the engine of the gen.

alg.

Over this is the class as singleton concepted. Only one engine for a run.

Member Function Documentation

void addGen ( Gen gen)
inline

registered a Gen in the engine.

Normal only used by the alg. self.

Parameters
gen(Gen*) the Gen which should be registered.
void addGeneration ( Generation generation)
inline

add a Generation to the alg.

Normal only used by the alg. self.

Parameters
generation(Generation*) the generation
void addGenPrototype ( GenPrototype prototype)
inline

registered a GenPrototype in the engine.

Parameters
prototype(GenPrototype*) the prototype which should be registered.
void addIndividual ( Individual individual)
inline

registered a individual in the engine.

Normal only used by the alg. self.

Parameters
individual(Individual*) the individual
void crossover ( RandGen random)

in the actual generation it will generate the children of the living individual

Parameters
random(RanGen*) random generator
static void destroyGenEngine ( bool  cleanStrategies = false)
inlinestatic

destroy the only existing engine.

void generateFirstGeneration ( int  startSize,
int  numChildren,
RandGen random,
bool  withUpdate = true 
)

prepare the alg.

and create his fisrt generation.

Parameters
startSize(int) Number of individual with which the alg. will be start.
numChildren(int) Number of individual which will be created by crossover.
random(RandGen*) A random generator
withUpdate(bool) if true, than makes this function on the end a update.
Generation* getActualGeneration ( void  )
inline

returns the actual Generation.

Returns
(Generation*) the actual generation
int getActualGenerationNumber ( void  ) const
inline

returns the actual generation number, on which the alg.

work

Returns
(int) the actual generation number
std::string getAllIndividualAsString ( void  ) const

returns a list of all individual and there gens values.

Returns
(string) the list
Individual * getBestIndividual ( void  )

returns the best individual (where the fitness is next to zero) which the alg.

have found.

Returns
(Individual*) the best.
double getFitness ( const Individual individual)

calculate for a individual the fitness value.

Parameters
individual(Individual*) the individual for which the fitness should be calculated
Returns
(double) the fitness value.
Gen* getGen ( int  x) const
inline

returns one gene

Parameters
x(int) index of the gene which is searched
Returns
(Gen*) the searched gene
Generation* getGeneration ( int  x)
inline

this function returns one Generation

Parameters
x(int) the index of the Generation which is searched
Returns
(Generation*) the searched Generation. If x not a right index, than the result is zero.
Individual* getIndividual ( int  x) const
inline

returns one individual

Parameters
x(int) index of the individual which is searched.
Returns
(Individual*) the searched individual
std::string getIndividualRoot ( bool  withMutation = true) const

returns a complete list of the inheritance of all individual.

Parameters
withMutation(bool) normal=true. if every individual should be marked if it mutated.
Returns
(string) the list
static SingletonGenEngine* getInstance ( void  )
inlinestatic

returns the only existing engine.

Returns
(SingletonGenEngine*) the engine
int getNextGenerationSize ( )

return the size of the next generation.

Returns
(int) the size
int getNumGeneration ( void  ) const
inline

this function return the number of Generation inside.

Returns
(int) the number of Generation in the storage
int getNumIndividual ( void  ) const
inline

returns the number of individual inside the alg.

Returns
(int) number of individual
const std::vector<GenPrototype*>& getSetOfGenPrototyps ( void  ) const
inline

this function returns a set of all registered GenPrototypes.

Returns
(vector<GenPrototype*>&) the set
void measureStep ( double  time,
InspectableProxy *&  proxyGeneration,
InspectableProxy *&  proxyGene,
PlotOptionEngine plotEngine = 0,
PlotOptionEngine plotEngineGenContext = 0 
)

makes a step in the measure

Parameters
time(double) the time stamp in the measure
proxyGeneration(InspectableProxy*&) the generation which is controlled by measures
proxyGene(InspectableProxy*&) the proxy for control measure
void prepare ( int  startSize,
int  numChildren,
InspectableProxy *&  proxyGeneration,
InspectableProxy *&  proxyGene,
RandGen random,
PlotOptionEngine plotEngine = 0,
PlotOptionEngine plotEngineGenContext = 0,
bool  withUpdate = true 
)

prepare the first generation with "generateFirstGeneration" and init the measures.

Parameters
startSize(int) Number of individual with which the alg. will be start.
numChildren(int) Number of individual which will be created by crossover
proxyGeneration(InspectableProxy*&) the generation which is controlled by measures
proxyGene(InspectableProxy*&) the proxy for control measure
random(RandGen*) A random generator
plotEngine(PlotOptionEngine*) logging the data for later control
plotEngineGenContext(PlotOptionEngine*) logging the data of the GenContext for later control
withUpdate(bool) is needed for the function "generateFirstGeneration"
void prepareNextGeneration ( int  size,
int  numChildren 
)

prepare the next generation.

Mean create the GenContext for every GenPrototype.

Parameters
size(int) size of the next generation
numChildren(int) Number of individual which will be created by crossover
bool restore ( FILE *  f,
InspectableProxy *&  proxyGeneration,
InspectableProxy *&  proxyGene,
PlotOptionEngine plotEngine,
PlotOptionEngine plotEngineGenContext 
)
virtual

loads the object from the given file stream (binary).

void runGenAlg ( int  startSize,
int  numChildren,
int  numGeneration,
RandGen random,
PlotOptionEngine plotEngine = 0,
PlotOptionEngine plotEngineGenContext = 0 
)

this function is for a automatically run of the gen.

alg.

Parameters
startSize(int) Number of individual with which the alg. will be start.
numChildren(int) Number of individual which will be created by crossover.
numGeneration(int) Number of generation after this the alg. will end.
random(RandGen*) a random generator
plotEngine(PlotOptionEngine*) logging the data for later control
plotEngineGenContext(PlotOptionEngine*) logging the data of the GenContext for later control
void select ( bool  createNextGeneration = true)

make the select of the actual generation and transfer it to the next generation

Parameters
createNextGeneration(bool) normal=true. should be the next generation prepare
void setFitnessStrategy ( IFitnessStrategy strategy)
inline

decide the fitness strategy.

Parameters
strategy(IFitnessStrategy*) the fitness strategy of the alg.
void setGenerationSizeStrategy ( IGenerationSizeStrategy strategy)
inline

decide the generation size strategy.

Parameters
strategy(IGenerationSizeStrategy*) the generation size strategy of the alg.
void setSelectStrategy ( ISelectStrategy strategy)
inline

decid the select strategy

Parameters
strategy(ISelectStrategy*) the select strategy of the alg.
bool store ( FILE *  f) const
virtual

stores the object to the given file stream (binary).

void update ( double  factor = 1.5)

this function makes a update on the statistical data of the gen.

alg.

Parameters
factor(double) the factor is for the whisker distance

Member Data Documentation

int m_actualGeneration
protected

the number of the actual generation

bool m_cleanStrategies
protected

flag for clean the seted strategies

SingletonGenEngine * m_engine = 0
staticprotected

the one and only GenEngine.

IFitnessStrategy* m_fitnessStrategy
protected

the fitness strategy of the alg.

std::vector<Gen*> m_gen
protected

management storage for all Gens

std::vector<Generation*> m_generation
protected

managment storage for all Generation

IGenerationSizeStrategy* m_generationSizeStrategy
protected

the generation size strategy of the alg.

std::vector<Individual*> m_individual
protected

management storage for all Individual

std::vector<GenPrototype*> m_prototype
protected

managment storage for all Genprototypes.

std::map<int,std::vector<int> > m_restoreGeneInIndividual
protected

Map for restoring the genes individual link from a run before.

std::map<int,RESTORE_GA_GENERATION*> m_restoreGeneration
protected

Map for restoring the generations from a run before.

std::map<int,RESTORE_GA_INDIVIDUAL*> m_restoreIndividual
protected

Map for restoring the individuals from a run before.

std::map<int,std::vector<int> > m_restoreIndividualInGeneration
protected

Map for restoring the individual generation link from a run before.

std::map<int,std::string> m_restoreNameOfIndividuals
protected

Map for restoring the names of the individuals.

ISelectStrategy* m_selectStrategy
protected

the select strategy of the alg.


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