SingletonGenAlgAPI Class Reference

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

#include <SingletonGenAlgAPI.h>

Collaboration diagram for SingletonGenAlgAPI:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Static Public Member Functions

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

Protected Attributes

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

Static Protected Attributes

static SingletonGenAlgAPIm_api = 0
 the api

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  )  [inline, static]

destroy the api

Parameters:
cleanStrategies (bool) default = false set a flag to clean the strategies, which are seted.

void enableGenContextMeasure ( PlotOption plotOption  ) 

enable data measure inside the GenContexts.

Parameters:
plotOption (PlotOption&) the plot option

void enableGenContextMeasure ( std::list< PlotOption > &  plotOptions  ) 

enable data measure inside the GenContexts with more than one plotOption

Parameters:
plotOptions (list<PlotOption>&) the list

void enableMeasure ( PlotOption plotOption  ) 

enables da : public Storableta measure.

Parameters:
plotOption (PlotOption&) the plot option

void enableMeasure ( std::list< PlotOption > &  plotOptions  ) 

enables data measure with more than one plotOption.

Parameters:
plotOptions (list<PöotOption>&) the list

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   )  [inline, static]

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 (  ) 

prepares the next generation and optional the enabled 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"

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 [static, protected]

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:
Generated on Fri Oct 30 16:29:02 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7