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
SingletonGenAlgAPI Class Reference

This is a facade for the gen. More...

#include <SingletonGenAlgAPI.h>

Collaboration diagram for SingletonGenAlgAPI:

Public Member Functions

void select (bool createNextGeneration=true)
 starts the selection More...
 
void crossover (RandGen *random)
 create the children from to fill up the next generation More...
 
void update (double factor=1.5)
 update the internal statistical data More...
 
void prepare (int startSize, int numChildren, RandGen *random, bool withUpdate=true)
 prepares the first generation and optional the enabled measure More...
 
void prepare ()
 prepares the next generation and optional the enabled measure More...
 
void measureStep (double time)
 makes a step in the measure More...
 
void runGenAlg (int startSize, int numChildren, int numGeneration, RandGen *random)
 start the sequenz of select, crossover, update in a automatically loop More...
 
void enableMeasure (std::list< PlotOption > &plotOptions)
 enables data measure with more than one plotOption. More...
 
void enableMeasure (PlotOption &plotOption)
 enables da : public Storableta measure. More...
 
PlotOptionEnginegetPlotOptionEngine (void) const
 returns the active plotOptionEngine for data measure. More...
 
void enableGenContextMeasure (std::list< PlotOption > &plotOptions)
 enable data measure inside the GenContexts with more than one plotOption More...
 
void enableGenContextMeasure (PlotOption &plotOption)
 enable data measure inside the GenContexts. More...
 
PlotOptionEnginegetPlotOptionEngineForGenContext (void) const
 returns the active plotOptionEngine for data measure inside the GenContexts. More...
 
void setGenerationSizeStrategy (IGenerationSizeStrategy *strategy)
 set the generation size strategy More...
 
void setFitnessStrategy (IFitnessStrategy *strategy)
 set the fitness strategy More...
 
void setSelectStrategy (ISelectStrategy *strategy)
 set the select strategy More...
 
SingletonGenEnginegetEngine (void) const
 returns the GenAlgEngine More...
 
IFitnessStrategycreateSumFitnessStrategy () const
 creates a SumFitnessStrategy. More...
 
IFitnessStrategycreateEuclidicDistanceFitnessStrategy () const
 creates a EuclidicFitnessStrategy. More...
 
IFitnessStrategycreateExtreamTestFitnessStrategy (IFitnessStrategy *fitness) const
 creates a TestFitnessStrategy which is the hardest test for a gen. More...
 
IFitnessStrategycreateTestFitnessStrategy () const
 creates the test function fitness strategy from the papper tp this alg. More...
 
IFitnessStrategycreateInvertedFitnessStrategy (IFitnessStrategy *strategy) const
 returns a fitness strategy which calculate the inverse value from a other strategy. More...
 
IRandomStrategycreateDoubleRandomStrategy (RandGen *random, double base=0.0, double factor=1.0, double epsilon=0.0) const
 creates a random strategy for double values. More...
 
IMutationStrategycreateValueMutationStrategy (IMutationFactorStrategy *strategy, int mutationProbability) const
 creates mutation strategy which change the old values by add a other value More...
 
IMutationFactorStrategycreateFixMutationFactorStrategy (IValue *value) const
 creates a mutation factor strategy with a fix value More...
 
IMutationFactorStrategycreateStandartMutationFactorStrategy (void) const
 creates a mutation factor strategy with a optimized value (varianz about all existing gens) More...
 
IGenerationSizeStrategycreateFixGenerationSizeStrategy (int value) const
 creates a generation size strategy with a fix value More...
 
IGenerationSizeStrategycreateStandartGenerationSizeStrategy (int startSize, int numGeneration) const
 creates a generation size strategy with a optimized size for the generation (changing by speed of development) More...
 
ISelectStrategycreateEliteSelectStrategy (void) const
 creates a elite select strategy More...
 
ISelectStrategycreateTournamentSelectStrategy (RandGen *random) const
 creates a tournament SelctStrategy. More...
 
ISelectStrategycreateRandomSelectStrategy (RandGen *random) const
 creates a random select strategy. More...
 
IValuecreateDoubleValue (double value) const
 creates a IValue (TemplateValue<double) from type double. More...
 
bool storeGA (FILE *f) const
 stores the object to the given file stream (binary). More...
 
bool restoreGA (FILE *f) const
 loads the object from the given file stream (binary). More...
 
void insertGenPrototype (GenPrototype *prototype)
 add a GenPrototype to the alg. More...
 
GenPrototypecreatePrototype (std::string name, IRandomStrategy *randomStrategy, IMutationStrategy *mutationStrategy) const
 create a prototype. More...
 
IndividualgetBestIndividual (void) const
 returns the best individual which the alg. More...
 

Static Public Member Functions

static SingletonGenAlgAPIgetInstance (void)
 returns the one and only API to the alg. More...
 
static void destroyAPI (bool cleanStrategies=false)
 destroy the api More...
 

Protected Attributes

PlotOptionEnginem_plotEngine
 plot option engine for data measure More...
 
PlotOptionEnginem_plotEngineGenContext
 plot option engine for gen contexts More...
 

Static Protected Attributes

static SingletonGenAlgAPIm_api = 0
 the api More...
 

Detailed Description

This is a facade for the gen.

alg.

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

Member Function Documentation

IRandomStrategy * createDoubleRandomStrategy ( RandGen random,
double  base = 0.0,
double  factor = 1.0,
double  epsilon = 0.0 
) const

creates a random strategy for double values.

The values will be generated in the intervals [base-epsilon:-epsilon] or [epsilon:factor+base+epsilon]

This means a random value in the interval [0:1] will be mul. with factor => [0:factor] After this it will be shifted by base => [base:factor+base] And than divided at the point zero and moved away by epsilon from the point zero => [base-epsilon:-epsilon], [epsilon:factor+base+epsilon]

For example: We want values in the intervals [-10:-5] and [5:10]. ==> epsilon=5 ==> [-5:5] ==> base=-5 ==> [0:10] ==> factor=10

Parameters
random(RandGen*) random generator
base(double) normal=0.0 moves the ground interval
factor(double) normal=1.0 resize the interval
epsilon(double) normal=0.0 devided the interval at the point zero and move the values by epsilon away from point zero
Returns
(IRandomStrategy*) the strategy
IValue * createDoubleValue ( double  value) const

creates a IValue (TemplateValue<double) from type double.

Parameters
value(double) the value
Returns
(IValue*) the new object
ISelectStrategy * createEliteSelectStrategy ( void  ) const

creates a elite select strategy

Returns
(ISelectStrategy*) the strategy
IFitnessStrategy * createEuclidicDistanceFitnessStrategy ( ) const

creates a EuclidicFitnessStrategy.

This strategy calculate the euclidic distance of all gens with a double value.

Returns
(IFitnessStrategy*) the strategy
IFitnessStrategy * createExtreamTestFitnessStrategy ( IFitnessStrategy fitness) const

creates a TestFitnessStrategy which is the hardest test for a gen.

alg. Only a smale area has a fitness. All other gives no information!

Parameters
fitness(IFitnessStrategy*) a other fitness strat* Over this is the class as singleton concepted. Only one engine for a run.egy which define the smal area.
Returns
(IFitnessStrategy*) the strategy
IGenerationSizeStrategy * createFixGenerationSizeStrategy ( int  value) const

creates a generation size strategy with a fix value

Parameters
value(int) the size of the generation
Returns
(IGenerationSizeStrategy*) the strategy
IMutationFactorStrategy * createFixMutationFactorStrategy ( IValue value) const

creates a mutation factor strategy with a fix value

Parameters
value(IValue*) the fix value.
Returns
(IMutationFactorStrategy*) the strategy
IFitnessStrategy * createInvertedFitnessStrategy ( IFitnessStrategy strategy) const

returns a fitness strategy which calculate the inverse value from a other strategy.

Parameters
strategy(IFitnessStrategy*) the other strategy
Returns
(IFitnessStrategy*) the resulting strategy
GenPrototype * createPrototype ( std::string  name,
IRandomStrategy randomStrategy,
IMutationStrategy mutationStrategy 
) const

create a prototype.

Parameters
name(STRING) THE NAME OF THE PROTOTYPE
randomStrategy(IRandomStrategy*) the random strategy to generate values of the type which the prototype represent
mutationStrategy(IMutationStrategy*) the mutation strategy to change a value (Gen)
Returns
(GenPrototype*) the prototype
ISelectStrategy * createRandomSelectStrategy ( RandGen random) const

creates a random select strategy.

By this strategy will a random selected individual fight again a random number. If the random number higher than the fitness from the individual, than it will be die.

Parameters
random(RandGen*) ranom generator
Returns
(ISelectStrategy*) the strategy
IGenerationSizeStrategy * createStandartGenerationSizeStrategy ( int  startSize,
int  numGeneration 
) const

creates a generation size strategy with a optimized size for the generation (changing by speed of development)

Parameters
startSize(int) the size at the start time
numGeneration(int) number of generation. (needed for the speed calculation
Returns
(IGenerationSizeStrategy*) the strategy
IMutationFactorStrategy * createStandartMutationFactorStrategy ( void  ) const

creates a mutation factor strategy with a optimized value (varianz about all existing gens)

Returns
(IMutationFactorStrategy*) the strategy
IFitnessStrategy * createSumFitnessStrategy ( ) const

creates a SumFitnessStrategy.

This strategy make the sum of all gens with a double value.

Returns
(IFitnessStrategy*) the strategy
IFitnessStrategy * createTestFitnessStrategy ( ) const

creates the test function fitness strategy from the papper tp this alg.

f(x,y) = 10.0 * (x² + 2.5y² - y) * exp(1 - (x² + y²)) + 2.4 + 0.1x² + 0.1y²

Returns
(IFitnessStrategy*) the strategy
ISelectStrategy * createTournamentSelectStrategy ( RandGen random) const

creates a tournament SelctStrategy.

By this strategy will two individual fight again (the individual with the higher fitness lives longer).

Parameters
random(RandGen*) random generator
Returns
(ISelectStrategy*) the strategy
IMutationStrategy * createValueMutationStrategy ( IMutationFactorStrategy strategy,
int  mutationProbability 
) const

creates mutation strategy which change the old values by add a other value

Parameters
strategy(IMutationFactorStrategy*) this strategy define what the other value is.
mutationProbability(int) the probability of mutation in one per tausend (1/1000)
Returns
(IMutationStrategy*) the strategy
void crossover ( RandGen random)

create the children from to fill up the next generation

Parameters
random(RandGen*) random generator
static void destroyAPI ( bool  cleanStrategies = false)
inlinestatic

destroy the api

Parameters
cleanStrategies(bool) default = false set a flag to clean the strategies, which are seted.
void enableGenContextMeasure ( std::list< PlotOption > &  plotOptions)

enable data measure inside the GenContexts with more than one plotOption

Parameters
plotOptions(list<PlotOption>&) the list
void enableGenContextMeasure ( PlotOption plotOption)

enable data measure inside the GenContexts.

Parameters
plotOption(PlotOption&) the plot option
void enableMeasure ( std::list< PlotOption > &  plotOptions)

enables data measure with more than one plotOption.

Parameters
plotOptions(list

&) the list

void enableMeasure ( PlotOption plotOption)

enables da : public Storableta measure.

Parameters
plotOption(PlotOption&) the plot option
Individual* getBestIndividual ( void  ) const
inline

returns the best individual which the alg.

have found

Returns
(Individual*) the best
SingletonGenEngine * getEngine ( void  ) const

returns the GenAlgEngine

Returns
(SingletonGenEngine*) the engine
static SingletonGenAlgAPI* getInstance ( void  )
inlinestatic

returns the one and only API to the alg.

Returns
(SingletonGenAlgAPI*) the api
PlotOptionEngine* getPlotOptionEngine ( void  ) const
inline

returns the active plotOptionEngine for data measure.

Returns
(PlotOptionEngine*) the plot option engine
PlotOptionEngine* getPlotOptionEngineForGenContext ( void  ) const
inline

returns the active plotOptionEngine for data measure inside the GenContexts.

Returns
(PlotOptionEngine*) the plot option engine.
void insertGenPrototype ( GenPrototype prototype)

add a GenPrototype to the alg.

Parameters
prototype(GenPrototype*) the prototype
void measureStep ( double  time)

makes a step in the measure

Parameters
time(double) time stamp in the measure
void prepare ( int  startSize,
int  numChildren,
RandGen random,
bool  withUpdate = true 
)

prepares the first generation and optional the enabled measure

Parameters
startSize(int) Number of individual at begin of the gen. alg.
startChildren(int) Number of individual which will be created by crossover
random(RandGen*) A random generator
withUpdate(bool) is needed for "generateFirstGeneration"
void prepare ( )

prepares the next generation and optional the enabled measure

bool restoreGA ( FILE *  f) const

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

void runGenAlg ( int  startSize,
int  numChildren,
int  numGeneration,
RandGen random 
)

start the sequenz of select, crossover, update in a automatically loop

Parameters
startSize(int) Number of individual at begin of the gen. alg.
numChildren(int) Number of individual which will be created by crossover
numGeneration(int) Number of generation which the alg. max. runs
random(RandGen*) random generator
void select ( bool  createNextGeneration = true)

starts the selection

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

set the fitness strategy

Parameters
strategy(IFitnessStrategy*) the strategy
void setGenerationSizeStrategy ( IGenerationSizeStrategy strategy)
inline

set the generation size strategy

Parameters
strategy(IGenerationSizeStrategy*) the strategy
void setSelectStrategy ( ISelectStrategy strategy)
inline

set the select strategy

Parameters
strategy(ISelectStrategy*) the strategy
bool storeGA ( FILE *  f) const

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

void update ( double  factor = 1.5)

update the internal statistical data

Parameters
factor(double) normal=1.5 is needed for the whisker distance

Member Data Documentation

SingletonGenAlgAPI * m_api = 0
staticprotected

the api

PlotOptionEngine* m_plotEngine
protected

plot option engine for data measure

PlotOptionEngine* m_plotEngineGenContext
protected

plot option engine for gen contexts


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