Evoga Class Reference
Genetic algorithm from evorobot more or less (spare parts) More...

Classes | |
class | Population |
A class modelling a population of genomes. | |
Public Slots | |
void | doNextStep () |
Go ahead of one step if the EvoGa is in step-by-step modality, otherwise do nothing. | |
void | enableStepByStep (bool enable) |
enable/disable the step-by-step modality of evolution process | |
Signals | |
void | endGeneration (int generation, int fmax, int faverage, int fmin) |
emitted when a generation is ended | |
void | finished () |
emitted when the evolution has been finished or stopped | |
void | recoveredInterruptedEvolution (QString statfile) |
emitted when an interrupted evolution has been recovered and it's going to start from there | |
void | startingReplication (int replication) |
emitted when a replication is going to start | |
Public Member Functions | |
Evoga () | |
Constructor. | |
~Evoga () | |
Destructor. | |
virtual QString | bestsFilename (unsigned int seed) |
Returns the name of the file with the best genomes for the given seed. | |
virtual QString | bestsFilename () |
Returns the template name (regular expression) for "best genomes" files. | |
bool | commitStep () |
this method marks the point on which it is called as a commited step of evolution | |
void | computeFStat () |
void | computeFStat2 () |
virtual void | configure (ConfigurationParameters ¶ms, QString prefix) |
Configures the object using a ConfigurationParameters object. | |
void | copyGenes (int from, int to, int mut) |
virtual unsigned int | currentGeneration () |
Returns the current generation. | |
virtual void | doNotUseMultipleThreads () |
Forces execution of the GA using no threads (i.e., in the current thread) | |
double | drand () |
virtual void | evolveAllReplicas () |
Evolves all replications of the ga process. | |
void | evolveGenerational () |
Main function of the Genetic Algorithm (Generational, Truncation Selection Version) | |
void | evolveSteadyState () |
Main function of the Genetic Algorithm (Steady State Version) | |
virtual QString | generationFilename () |
Returns the template name (regular expression) for "generation" files. | |
virtual QString | generationFilename (unsigned int generation, unsigned int seed) |
Returns the name of the file containing the given generation for the given seed. | |
int * | getBestGenes (int ind) |
virtual double | getCurrentMutationRate () |
Returns the current mutation rate. | |
virtual unsigned int | getCurrentSeed () |
Returns the current seed. | |
virtual EvoRobotExperiment * | getEvoRobotExperiment () |
Returns a pointer to the EvoRobotExperiment object. | |
virtual QVector < EvoRobotExperiment * > | getEvoRobotExperimentPool () |
Returns a list of pointers to the EvoRobotExperiment objects used by the ga to evaluate agents. | |
int * | getGenes (int ind) |
virtual int * | getGenesForIndividual (unsigned int id) |
Returns the array of genes for the given individual. | |
void | getGenome (int frombestgenome, int togenome, int mut) |
void | getLastFStat (double &min, double &max, double &average) |
return the last value of min, max and average fitness | |
double | getNoise (double minn, double maxn) |
virtual unsigned int | getNumOfGenerations () |
Returns the number of generations to do. | |
virtual unsigned int | getNumReplications () |
Returns the number of replications. | |
void | getPheParametersAndMutationsFromEvonet () |
transfer .phe info inside GA | |
virtual unsigned int | getStartingSeed () |
Returns the starting seed. | |
bool | isEnabledStepByStep () |
return true is the step-by-step modality is enabled, false otherwise | |
bool | isStopped () |
return true if the evolution process has been stopped with stop() | |
int | loadallg (int gen, const char *filew) |
void | loadgenotype (FILE *fp, int ind) |
virtual unsigned int | loadGenotypes (QString filename) |
Loads genotypes from the given file. | |
int | loadStatistics (char *filename) |
int | mrand (int i) |
void | mreproduce () |
int | mutate (int w, double mut) |
virtual unsigned int | numLoadedGenotypes () const |
Returns number of loaded genotypes. | |
virtual void | postConfigureInitialization () |
This function is called after all linked objects have been configured. | |
void | printBest () |
void | printPop () |
void | putGenome (int fromgenome, int tobestgenome) |
void | randomizePop () |
void | reproduce () |
void | resetGenerationCounter () |
void | resetStop () |
reset the stopped status to false | |
virtual void | save (ConfigurationParameters ¶ms, QString prefix) |
Save the actual status of parameters into the ConfigurationParameters object passed. | |
void | saveagenotype (FILE *fp, int ind) |
void | saveallg () |
void | saveBestInd () |
void | saveFStat () |
virtual void | setCurrentMutationRate (double mutation_rate) |
Set the current mutation rate to use. | |
void | setInitialPopulation (int *) |
void | setMutations (float *) |
void | setSeed (int s) |
virtual QString | statisticsFilename (unsigned int seed) |
Returns the name of the file with statistics (fitness) for the given seed. | |
void | stop () |
stop the running evolution process as soon as possible | |
Static Public Member Functions | |
static void | describe (QString type) |
Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups. | |
Static Public Attributes | |
static const int | MAXINDIVIDUALS = 1000 |
constant defining the maximimum number of individuals that Evoga can manage |
Detailed Description
Genetic algorithm from evorobot more or less (spare parts)
Mandatory Resources that the EvoRobotExperiment has to declare:
Optional Resources that the EvoRobotExperiment may declare:
- "evonet": a pointer to the EvoNet
Constructor & Destructor Documentation
Member Function Documentation
QString bestsFilename | ( | unsigned int | seed | ) | [virtual] |
QString bestsFilename | ( | ) | [virtual] |
bool commitStep | ( | ) |
this method marks the point on which it is called as a commited step of evolution
This method allow to divide the code on blocks where each of it can be considered as a single step of the evolution process. These key points define the behaviour when the advancement step-by-step has been requested. When the advancement of the evolution is on "step-by-step" (enableStepByStep method), everytime this method is encountered the process will stop waiting to pass over when the user send a request to perform an another step.
This method handle also the stopping process of the evolution. In fact, it return true if the evolution process has been stopped with stop() This function return true only between the calls to stop() and to resetStop() methods:
stop(); commitStep(); // <-- it will return true resetStop(); commitStep(); // <-- it will return false
- Note:
- resetStop() is not called automatically by the Evoga after the exit for a stop, but it's called by the EvoRobotComponent after the execution of action 'stop'; If you want to use the Evoga in your custom Component remember to call resetStop()
Definition at line 1252 of file evoga.cpp.
Referenced by EvoRobotExperiment::doAllTrialsForIndividual(), Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
void configure | ( | ConfigurationParameters & | params, |
QString | prefix | ||
) | [virtual] |
Configures the object using a ConfigurationParameters object.
- Parameters:
-
params the configuration parameters object with parameters to use prefix the prefix to use to access the object configuration parameters. This is guaranteed to end with the separator character when called by the factory, so you don't need to add one
Implements ParameterSettableWithConfigureFunction.
Definition at line 1113 of file evoga.cpp.
References Logger::error(), ConfigurationHelper::getBool(), ConfigurationHelper::getDouble(), ConfigurationHelper::getInt(), ConfigurationParameters::getObjectFromGroup(), ConfigurationHelper::getString(), ConfigurationParameters::getValue(), Logger::info(), and EvoRobotExperiment::setEvoga().
unsigned int currentGeneration | ( | ) | [virtual] |
void describe | ( | QString | type | ) | [static] |
Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.
- Parameters:
-
type is the name of the type regarding the description. The type is used when a subclass reuse the description of its parent calling the parent describe method passing the type of the subclass. In this way, the result of the method describe of the parent will be the addition of the description of the parameters of the parent class into the type of the subclass
Reimplemented from ParameterSettable.
Definition at line 1165 of file evoga.cpp.
References ParameterSettable::addTypeDescription(), ParameterSettable::RealDescriptor::def(), ParameterSettable::BoolDescriptor::def(), ParameterSettable::IntDescriptor::def(), ParameterSettable::EnumDescriptor::def(), ParameterSettable::Descriptor::describeBool(), ParameterSettable::Descriptor::describeEnum(), ParameterSettable::Descriptor::describeInt(), ParameterSettable::Descriptor::describeReal(), ParameterSettable::Descriptor::describeSubgroup(), ParameterSettable::SubgroupDescriptor::help(), ParameterSettable::RealDescriptor::help(), ParameterSettable::BoolDescriptor::help(), ParameterSettable::IntDescriptor::help(), ParameterSettable::EnumDescriptor::help(), ParameterSettable::IsMandatory, ParameterSettable::RealDescriptor::limits(), ParameterSettable::IntDescriptor::limits(), ParameterSettable::MaxInteger, ParameterSettable::SubgroupDescriptor::props(), ParameterSettable::EnumDescriptor::props(), ParameterSettable::SubgroupDescriptor::type(), and ParameterSettable::EnumDescriptor::values().
void doNextStep | ( | ) | [slot] |
void doNotUseMultipleThreads | ( | ) | [virtual] |
Forces execution of the GA using no threads (i.e., in the current thread)
Definition at line 1370 of file evoga.cpp.
Referenced by EvoRobotExperiment::postConfigureInitialization().
void enableStepByStep | ( | bool | enable | ) | [slot] |
enable/disable the step-by-step modality of evolution process
When the step-by-step modality is enabled, the evolution process will block in some specific points waiting the user command to go ahead
- Parameters:
-
enable if true enable the step-by-step, if false disable it
void endGeneration | ( | int | generation, |
int | fmax, | ||
int | faverage, | ||
int | fmin | ||
) | [signal] |
emitted when a generation is ended
- Parameters:
-
generation is the number of generation finished fmax is the maximum fitness value faverage is the average fitness fmin is the minimum fitness value
Referenced by Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
void evolveAllReplicas | ( | ) | [virtual] |
Evolves all replications of the ga process.
Definition at line 1235 of file evoga.cpp.
References Logger::error(), Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
Referenced by EvoRobotComponent::evolve(), and EvolveOperation::run().
void evolveGenerational | ( | ) |
Main function of the Genetic Algorithm (Generational, Truncation Selection Version)
Definition at line 1016 of file evoga.cpp.
References Evoga::commitStep(), EvoRobotExperiment::doAllTrialsForIndividual(), EvoRobotExperiment::endGeneration(), Evoga::endGeneration(), EvoRobotExperiment::getFitness(), Evoga::getPheParametersAndMutationsFromEvonet(), Evoga::getStartingSeed(), ConcurrentResourcesUser::hasResource(), Logger::info(), EvoRobotExperiment::initGeneration(), Evoga::recoveredInterruptedEvolution(), EvoRobotExperiment::setNetParameters(), and Evoga::startingReplication().
Referenced by Evoga::evolveAllReplicas().
void evolveSteadyState | ( | ) |
Main function of the Genetic Algorithm (Steady State Version)
Definition at line 753 of file evoga.cpp.
References Evoga::commitStep(), EvoRobotExperiment::doAllTrialsForIndividual(), Evoga::endGeneration(), EvoRobotExperiment::endGeneration(), EvoRobotExperiment::getFitness(), ConfigurationParameters::getObjectFromGroup(), Evoga::getPheParametersAndMutationsFromEvonet(), Evoga::getStartingSeed(), ConcurrentResourcesUser::hasResource(), Logger::info(), EvoRobotExperiment::initGeneration(), Evoga::isStopped(), Evoga::recoveredInterruptedEvolution(), EvoRobotExperiment::setEvoga(), EvoRobotExperiment::setNetParameters(), and Evoga::startingReplication().
Referenced by Evoga::evolveAllReplicas().
void finished | ( | ) | [signal] |
emitted when the evolution has been finished or stopped
QString generationFilename | ( | unsigned int | generation, |
unsigned int | seed | ||
) | [virtual] |
Returns the name of the file containing the given generation for the given seed.
- Parameters:
-
seed the seed from which the filename should be returned generation the generation of interest
- Returns:
- the name of the file with genomes for the given seed and generation
QString generationFilename | ( | ) | [virtual] |
double getCurrentMutationRate | ( | ) | [virtual] |
unsigned int getCurrentSeed | ( | ) | [virtual] |
EvoRobotExperiment * getEvoRobotExperiment | ( | ) | [virtual] |
Returns a pointer to the EvoRobotExperiment object.
It is not guaranteed that the returned object is effectively used for evolution, in some cases it could simply be a prototype used to generate objects (via cloning) that are used to evaluate agents. Use getExperimentPool() if you want to be sure to get objects used for evaluation
- Returns:
- a pointer to the EvoRobotExperiment object
Definition at line 1286 of file evoga.cpp.
Referenced by TestRandom::buildRandomDNA(), EvoRobotComponent::evolve(), EvoRobotViewer::EvoRobotViewer(), EvolveOperation::run(), TestIndividual::runTest(), and TestRandom::runTest().
QVector< EvoRobotExperiment * > getEvoRobotExperimentPool | ( | ) | [virtual] |
Returns a list of pointers to the EvoRobotExperiment objects used by the ga to evaluate agents.
Objects returned by this function are those effectively used to evaluate individuals (see also getEvoRobotExperiment()). Note that the list could be empty.
int * getGenesForIndividual | ( | unsigned int | id | ) | [virtual] |
void getLastFStat | ( | double & | min, |
double & | max, | ||
double & | average | ||
) |
unsigned int getNumOfGenerations | ( | ) | [virtual] |
unsigned int getNumReplications | ( | ) | [virtual] |
void getPheParametersAndMutationsFromEvonet | ( | ) |
transfer .phe info inside GA
- Warning:
- this function assume that the EvoRotobEvaluator has a resource named "evonet" returning a pointer to an Evonet object; it this constraint is not satisfied an exception will be raised
Definition at line 726 of file evoga.cpp.
Referenced by Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
unsigned int getStartingSeed | ( | ) | [virtual] |
Returns the starting seed.
- Returns:
- the starting seed
Definition at line 1303 of file evoga.cpp.
Referenced by Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
bool isEnabledStepByStep | ( | ) |
bool isStopped | ( | ) |
return true if the evolution process has been stopped with stop()
This method handle also the stopping process of the evolution. In fact, it return true if the evolution process has been stopped with stop() This function return true only between the calls to stop() and to resetStop() methods:
stop(); commitStep(); // <-- it will return true resetStop(); commitStep(); // <-- it will return false
- Note:
- resetStop() is not called automatically by the Evoga after the exit for a stop, but it's called by the EvoRobotComponent after the execution of action 'stop'; If you want to use the Evoga in your custom Component remember to call resetStop()
Definition at line 1262 of file evoga.cpp.
Referenced by EvoRobotExperiment::doAllTrialsForIndividual(), Evoga::evolveSteadyState(), TestOperation::run(), and EvolveOperation::run().
unsigned int loadGenotypes | ( | QString | filename | ) | [virtual] |
Loads genotypes from the given file.
- Parameters:
-
filename the name of the file to load
- Returns:
- the number of individuals that have been loaded, 0 in case of errors
Definition at line 1330 of file evoga.cpp.
Referenced by TestIndividual::runTest(), and TestIndividual::setPopulationToTest().
unsigned int numLoadedGenotypes | ( | ) | const [virtual] |
void postConfigureInitialization | ( | ) | [virtual] |
This function is called after all linked objects have been configured.
Reimplemented from ParameterSettable.
Definition at line 1183 of file evoga.cpp.
References Evonet::DEFAULT_VALUE, EvoRobotExperiment::getGenomeLength(), Logger::info(), Evoga::MAXINDIVIDUALS, ConcurrentResourcesUser::shareResourcesWith(), and ConcurrentResourcesUser::usableResources().
void recoveredInterruptedEvolution | ( | QString | statfile | ) | [signal] |
emitted when an interrupted evolution has been recovered and it's going to start from there
- Parameters:
-
statFile is the filename from which the evolution has been recovered
Referenced by Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
void resetStop | ( | ) |
reset the stopped status to false
Definition at line 1266 of file evoga.cpp.
Referenced by EvoRobotComponent::evolve(), TestOperation::run(), EvolveOperation::run(), and EvoRobotComponent::runTest().
void save | ( | ConfigurationParameters & | params, |
QString | prefix | ||
) | [virtual] |
Save the actual status of parameters into the ConfigurationParameters object passed.
This is not implemented, a call to this function will cause an abort
- Parameters:
-
params the configuration parameters object on which save actual parameters prefix the prefix to use to access the object configuration parameters.
Implements ParameterSettable.
Definition at line 1159 of file evoga.cpp.
References Logger::error().
Referenced by EvoRobotComponent::save().
void setCurrentMutationRate | ( | double | mutation_rate | ) | [virtual] |
void startingReplication | ( | int | replication | ) | [signal] |
emitted when a replication is going to start
- Parameters:
-
replication is the number of the replication that it's going to start
Referenced by Evoga::evolveGenerational(), and Evoga::evolveSteadyState().
QString statisticsFilename | ( | unsigned int | seed | ) | [virtual] |
void stop | ( | ) |
stop the running evolution process as soon as possible
- Note:
- this method return immediately, but the evolution process may take some time before to quit depending on how many processing time last a step of the evolution process
Definition at line 1247 of file evoga.cpp.
Referenced by TestOperation::stop(), and EvolveOperation::stop().
Member Data Documentation
const int MAXINDIVIDUALS = 1000 [static] |
constant defining the maximimum number of individuals that Evoga can manage
Definition at line 71 of file evoga.h.
Referenced by Evoga::postConfigureInitialization().
The documentation for this class was generated from the following files: