#include <SingletonGenAlgAPI.h>
Collaboration diagram for SingletonGenAlgAPI:
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. | |
PlotOptionEngine * | getPlotOptionEngine (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. | |
PlotOptionEngine * | getPlotOptionEngineForGenContext (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 | |
SingletonGenEngine * | getEngine (void) const |
returns the GenAlgEngine | |
IFitnessStrategy * | createSumFitnessStrategy () const |
creates a SumFitnessStrategy. | |
IFitnessStrategy * | createEuclidicDistanceFitnessStrategy () const |
creates a EuclidicFitnessStrategy. | |
IFitnessStrategy * | createExtreamTestFitnessStrategy (IFitnessStrategy *fitness) const |
creates a TestFitnessStrategy which is the hardest test for a gen. | |
IFitnessStrategy * | createTestFitnessStrategy () const |
creates the test function fitness strategy from the papper tp this alg. | |
IFitnessStrategy * | createInvertedFitnessStrategy (IFitnessStrategy *strategy) const |
returns a fitness strategy which calculate the inverse value from a other strategy. | |
IRandomStrategy * | createDoubleRandomStrategy (RandGen *random, double base=0.0, double factor=1.0, double epsilon=0.0) const |
creates a random strategy for double values. | |
IMutationStrategy * | createValueMutationStrategy (IMutationFactorStrategy *strategy, int mutationProbability) const |
creates mutation strategy which change the old values by add a other value | |
IMutationFactorStrategy * | createFixMutationFactorStrategy (IValue *value) const |
creates a mutation factor strategy with a fix value | |
IMutationFactorStrategy * | createStandartMutationFactorStrategy (void) const |
creates a mutation factor strategy with a optimized value (varianz about all existing gens) | |
IGenerationSizeStrategy * | createFixGenerationSizeStrategy (int value) const |
creates a generation size strategy with a fix value | |
IGenerationSizeStrategy * | createStandartGenerationSizeStrategy (int startSize, int numGeneration) const |
creates a generation size strategy with a optimized size for the generation (changing by speed of development) | |
ISelectStrategy * | createEliteSelectStrategy (void) const |
creates a elite select strategy | |
ISelectStrategy * | createTournamentSelectStrategy (RandGen *random) const |
creates a tournament SelctStrategy. | |
ISelectStrategy * | createRandomSelectStrategy (RandGen *random) const |
creates a random select strategy. | |
IValue * | createDoubleValue (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. | |
GenPrototype * | createPrototype (std::string name, IRandomStrategy *randomStrategy, IMutationStrategy *mutationStrategy) const |
create a prototype. | |
Individual * | getBestIndividual (void) const |
returns the best individual which the alg. | |
Static Public Member Functions | |
static SingletonGenAlgAPI * | getInstance (void) |
returns the one and only API to the alg. | |
static void | destroyAPI (bool cleanStrategies=false) |
destroy the api | |
Protected Attributes | |
PlotOptionEngine * | m_plotEngine |
plot option engine for data measure | |
PlotOptionEngine * | m_plotEngineGenContext |
plot option engine for gen contexts | |
Static Protected Attributes | |
static SingletonGenAlgAPI * | m_api = 0 |
the api |
alg.
Over this is the class as singleton concepted. Only one API for a run.
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
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 |
IValue * createDoubleValue | ( | double | value | ) | const |
creates a IValue (TemplateValue<double) from type double.
value | (double) the value |
ISelectStrategy * createEliteSelectStrategy | ( | void | ) | const |
creates a elite select strategy
IFitnessStrategy * createEuclidicDistanceFitnessStrategy | ( | ) | const |
creates a EuclidicFitnessStrategy.
This strategy calculate the euclidic distance of all gens with a double value.
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!
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. |
IGenerationSizeStrategy * createFixGenerationSizeStrategy | ( | int | value | ) | const |
creates a generation size strategy with a fix value
value | (int) the size of the generation |
IMutationFactorStrategy * createFixMutationFactorStrategy | ( | IValue * | value | ) | const |
creates a mutation factor strategy with a fix value
value | (IValue*) the fix value. |
IFitnessStrategy * createInvertedFitnessStrategy | ( | IFitnessStrategy * | strategy | ) | const |
returns a fitness strategy which calculate the inverse value from a other strategy.
strategy | (IFitnessStrategy*) the other strategy |
GenPrototype * createPrototype | ( | std::string | name, | |
IRandomStrategy * | randomStrategy, | |||
IMutationStrategy * | mutationStrategy | |||
) | const |
create a prototype.
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) |
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.
random | (RandGen*) ranom generator |
IGenerationSizeStrategy * createStandartGenerationSizeStrategy | ( | int | startSize, | |
int | numGeneration | |||
) | const |
creates a generation size strategy with a optimized size for the generation (changing by speed of development)
startSize | (int) the size at the start time | |
numGeneration | (int) number of generation. (needed for the speed calculation |
IMutationFactorStrategy * createStandartMutationFactorStrategy | ( | void | ) | const |
creates a mutation factor strategy with a optimized value (varianz about all existing gens)
IFitnessStrategy * createSumFitnessStrategy | ( | ) | const |
creates a SumFitnessStrategy.
This strategy make the sum of all gens with a double value.
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²
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).
random | (RandGen*) random generator |
IMutationStrategy * createValueMutationStrategy | ( | IMutationFactorStrategy * | strategy, | |
int | mutationProbability | |||
) | const |
creates mutation strategy which change the old values by add a other value
strategy | (IMutationFactorStrategy*) this strategy define what the other value is. | |
mutationProbability | (int) the probability of mutation in one per tausend (1/1000) |
void crossover | ( | RandGen * | random | ) |
create the children from to fill up the next generation
random | (RandGen*) random generator |
static void destroyAPI | ( | bool | cleanStrategies = false |
) | [inline, static] |
destroy the api
cleanStrategies | (bool) default = false set a flag to clean the strategies, which are seted. |
void enableGenContextMeasure | ( | PlotOption & | plotOption | ) |
void enableGenContextMeasure | ( | std::list< PlotOption > & | plotOptions | ) |
enable data measure inside the GenContexts with more than one plotOption
plotOptions | (list<PlotOption>&) the list |
void enableMeasure | ( | PlotOption & | plotOption | ) |
void enableMeasure | ( | std::list< PlotOption > & | plotOptions | ) |
enables data measure with more than one plotOption.
plotOptions | (list<PöotOption>&) the list |
Individual* getBestIndividual | ( | void | ) | const [inline] |
returns the best individual which the alg.
have found
SingletonGenEngine * getEngine | ( | void | ) | const |
returns the GenAlgEngine
static SingletonGenAlgAPI* getInstance | ( | void | ) | [inline, static] |
returns the one and only API to the alg.
PlotOptionEngine* getPlotOptionEngine | ( | void | ) | const [inline] |
returns the active plotOptionEngine for data measure.
PlotOptionEngine* getPlotOptionEngineForGenContext | ( | void | ) | const [inline] |
returns the active plotOptionEngine for data measure inside the GenContexts.
void insertGenPrototype | ( | GenPrototype * | prototype | ) |
void measureStep | ( | double | time | ) |
makes a step in the measure
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
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
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
createNextGeneration | (bool) normal=true should be the next generation be prepare? |
void setFitnessStrategy | ( | IFitnessStrategy * | strategy | ) | [inline] |
set the fitness strategy
strategy | (IFitnessStrategy*) the strategy |
void setGenerationSizeStrategy | ( | IGenerationSizeStrategy * | strategy | ) | [inline] |
set the generation size strategy
strategy | (IGenerationSizeStrategy*) the strategy |
void setSelectStrategy | ( | ISelectStrategy * | strategy | ) | [inline] |
set the select strategy
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
factor | (double) normal=1.5 is needed for the whisker distance |
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