dignea
1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
|
Class to represent an Abstract Genetic Algorithm. Base skeleton is defined here, to extend in particular versions of GAs. This class extends AbstractEA. Use this class to create your own version of GAs. More...
#include <AbstractGA.h>
Public Member Functions | |
AbstractGA () | |
Creates a new AbstractGA which initialises all parameter to default. The operators will be set to null. More... | |
virtual string | getName () const =0 |
Returns the name of the algorithm, this is used in the to_json method. Must be implemented in the subclasses. More... | |
json | to_json () const override |
Creates and returns JSON object with the GA information. More... | |
virtual Front< S > | getResults () const |
Returns a front with the feasible non repeated individuals in the last population of the Genetic Algorithm. This is the final solution of the algorithm to the problem at hand. More... | |
void | run () override |
Runs the evolutionary process. This is the main EA method. This methods is in charge of: More... | |
void | setProblem (shared_ptr< Problem< S >> prob) override |
Uptades the problem to solve using a share_ptr. The problem must be single-objective. More... | |
void | setProblem (Problem< S > *prob) override |
Uptades the problem to solve using a raw pointer. The problem must be single-objective. More... | |
double | getMutationRate () const |
Gets the mutation rate. More... | |
void | setMutationRate (double mutationRate) |
Updates the mutation rate. More... | |
double | getCrossRate () const |
Gets the crossover rate. More... | |
void | setCrossRate (double crossRate) |
Updates the crossover rate. More... | |
const Mutation< S > * | getMutation () const |
Gets a pointer to the mutation operator. More... | |
void | setMutation (unique_ptr< Mutation< S >> mutation) |
Updates the mutation operator. Takes a unique_ptr pointing to the new Mutation operator and takes the ownership. More... | |
const Crossover< S > * | getCrossover () const |
Returns a raw pointer to the crossover operator. More... | |
void | setCrossover (unique_ptr< Crossover< S >> crossover) |
Updates the crossover operator. Takes a unique_ptr pointing to the new Crossover operator and takes the ownership. More... | |
const Selection< S > * | getSelection () const |
Returns a raw pointer of the selection operator. More... | |
void | setSelection (unique_ptr< Selection< S >> selectionOperator) |
Updates the selection operator. Takes a unique_ptr pointing to the new Selection operator and takes the ownership. More... | |
Public Member Functions inherited from AbstractEA< S > | |
AbstractEA () | |
Construct a new Abstract EA object with default parameter values. More... | |
AbstractEA (const int &maxEvals, const int &popsize) | |
AbstractEA constructor which initialises the parameters maxEvalautions and populationSize. More... | |
AbstractEA (unique_ptr< PopulationEvaluator< S >>, const int &maxEvals, const int &popsize) | |
AbstractEA constructor which initialises the parameters maxEvalautions, the populationSize and the evaluator approach. More... | |
virtual string | getID () const =0 |
Returns the identificator of the algorithm, this is used in the to_json method. Must be implemented in the subclasses. It should return the acronym of useful id for a particular configuration. More... | |
int | getPopulationSize () const |
Get the population size. More... | |
void | setPopulationSize (int pSize) |
Setter to update the population size. More... | |
double | getElapsedTime () const |
Get the elapsed time of the evolutionary process. More... | |
const vector< S > & | getPopulation () const |
Gets a reference of the population. More... | |
int | getMaxEvaluations () const |
Get the maximum number of evaluations to perform. More... | |
void | setMaxEvaluations (int maxEval) |
Set a new maximum number of evaluations to perform. More... | |
const Problem< S > * | getProblem () const |
Gets a pointer to the problem which is being solved. More... | |
PopulationEvaluator< S > * | getEvaluator () const |
Gets a pointer to the population evaluator system. More... | |
void | setEvaluator (unique_ptr< PopulationEvaluator< S >> eval) |
Updates the population evaluator system with the unique_ptr. The method takes the ownership of the object behind. More... | |
int | getPerformedEvaluations () const |
Get the performed evaluations. More... | |
void | setPerformedEvaluations (int pEvals) |
Set the Performed Evaluations. Useful for the updateProgress method. More... | |
void | setPopulation (const vector< S > &pop) |
Set the Population. More... | |
virtual Evolution< S > | getEvolution () const |
Get the Evolution data. More... | |
int | getPrintingInterval () const |
Get the interval of checkpoints. More... | |
Static Public Attributes | |
static double | DEFAULT_MUTATION_RATE = 0.05 |
Default mutation rate for GAs set to 0.05. More... | |
static double | DEFAULT_CROSSOVER_RATE = 0.8 |
Default crossover rate to GAs set to 0.8. More... | |
static int | DEFAULT_POPULATION_SIZE = 32 |
Default population size to GAs set to 32 individuals. More... | |
Static Public Attributes inherited from AbstractEA< S > | |
static const int | DEFAULT_POPULATION_SIZE = 100 |
Default population size equal to 100 individuals. More... | |
static const int | DEFAULT_EVALUATIONS_LIMIT = 100000 |
Default evaluation limit equal to 100000 evaluations. More... | |
static const std::string | NAME = "Algorithm" |
static const std::string | MAX_EVALUATIONS = "Max Evaluations" |
static const std::string | POP_SIZE = "Population Size" |
static const std::string | ELAPSED_TIME = "Elapsed Time" |
static const std::string | EVALUATOR = "Evaluator" |
static const int | EVOLUTION_SIZE = 10 |
Protected Member Functions | |
virtual void | initProgress () |
Starts the evolutionary process. By default this methods sets the number of performed evaluations to the population size since it considers that all individuals have been evaluated in the createInitialPopulation method. More... | |
virtual void | updateProgress ()=0 |
Method which updates the evolutionary progress. This method must be implemented in the subclasses and it should perform thinks like updating the number of performed evaluations, etc. | |
virtual void | finishProgress () |
Finishes the evolutionary process by computing the elapsed time. More... | |
virtual bool | isStoppingConditionReached () |
Checks whether the evolutionary process has reached the maximum limit. More... | |
virtual void | createInitialPopulation () |
Creates the initial population of individuals before starting the evolutionary process. More... | |
virtual void | evaluatePopulation (vector< S > &pop) |
Evaluates the entire population of individuals using the problem evaluation function. More... | |
virtual vector< S > | createMating () |
Generates the mating population of individuals to be evaluated. The individuals are selected and after that the genetic operators are applied here. More... | |
virtual void | reproduction (S &, S &) |
Applies the genetic operator. This methods is invoked from createMating. More... | |
Protected Member Functions inherited from AbstractEA< S > | |
virtual void | updateEvolution (vector< S > &pop) |
virtual void | updateEvolution (const int &checkpoint, vector< S > &) |
Protected Attributes | |
double | mutationRate |
double | crossRate |
unique_ptr< Mutation< S > > | mutation |
unique_ptr< Crossover< S > > | crossover |
unique_ptr< Selection< S > > | selection |
unique_ptr< Replacement< S > > | replacement |
Protected Attributes inherited from AbstractEA< S > | |
int | maxEvaluations |
int | performedEvaluations |
int | populationSize |
vector< S > | population |
shared_ptr< Problem< S > > | problem |
unique_ptr< PopulationEvaluator< S > > | evaluator |
Evolution< S > | evolution |
AvgEvolution< S > | avgEvolution |
std::chrono::system_clock::time_point | startTime |
std::chrono::system_clock::time_point | endTime |
double | elapsedTime |
int | nextCheckpoint |
int | evolutionInterval |
Class to represent an Abstract Genetic Algorithm. Base skeleton is defined here, to extend in particular versions of GAs. This class extends AbstractEA. Use this class to create your own version of GAs.
S | Type of individual in the population. |
AbstractGA< S >::AbstractGA |
Creates a new AbstractGA which initialises all parameter to default. The operators will be set to null.
S |
|
protectedvirtual |
Creates the initial population of individuals before starting the evolutionary process.
S |
Implements AbstractEA< S >.
Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.
|
protectedvirtual |
Generates the mating population of individuals to be evaluated. The individuals are selected and after that the genetic operators are applied here.
S |
Reimplemented in SteadyGA< S >, and NSGA2< S >.
|
protectedvirtual |
Evaluates the entire population of individuals using the problem evaluation function.
S |
pop |
Implements AbstractEA< S >.
Reimplemented in NSGA2< S >.
|
protectedvirtual |
Finishes the evolutionary process by computing the elapsed time.
S |
Implements AbstractEA< S >.
const Crossover< S > * AbstractGA< S >::getCrossover |
double AbstractGA< S >::getCrossRate |
Gets the crossover rate.
S |
const Mutation< S > * AbstractGA< S >::getMutation |
double AbstractGA< S >::getMutationRate |
Gets the mutation rate.
S |
|
pure virtual |
Returns the name of the algorithm, this is used in the to_json method. Must be implemented in the subclasses.
Implements AbstractEA< S >.
Implemented in SteadyGA< S >, ParallelGeneticAlgorithm< S >, GenerationalGA< S >, FIGA< S >, and NSGA2< S >.
|
virtual |
Returns a front with the feasible non repeated individuals in the last population of the Genetic Algorithm. This is the final solution of the algorithm to the problem at hand.
S |
Implements AbstractEA< S >.
Reimplemented in NSGA2< S >.
const Selection< S > * AbstractGA< S >::getSelection |
|
protectedvirtual |
Starts the evolutionary process. By default this methods sets the number of performed evaluations to the population size since it considers that all individuals have been evaluated in the createInitialPopulation method.
S |
Implements AbstractEA< S >.
Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.
|
protectedvirtual |
Checks whether the evolutionary process has reached the maximum limit.
S |
Implements AbstractEA< S >.
|
protectedvirtual |
Applies the genetic operator. This methods is invoked from createMating.
S |
child1 | |
child2 |
Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.
|
overridevirtual |
Runs the evolutionary process. This is the main EA method. This methods is in charge of:
S |
Implements AbstractEA< S >.
void AbstractGA< S >::setCrossover | ( | unique_ptr< Crossover< S >> | newCX | ) |
Updates the crossover operator. Takes a unique_ptr pointing to the new Crossover operator and takes the ownership.
S |
newCX |
void AbstractGA< S >::setCrossRate | ( | double | crossRate | ) |
Updates the crossover rate.
S |
crossRate |
void AbstractGA< S >::setMutation | ( | unique_ptr< Mutation< S >> | newMut | ) |
Updates the mutation operator. Takes a unique_ptr pointing to the new Mutation operator and takes the ownership.
S |
newMut |
void AbstractGA< S >::setMutationRate | ( | double | mutationRate | ) |
Updates the mutation rate.
S |
mutationRate |
|
overridevirtual |
Uptades the problem to solve using a raw pointer. The problem must be single-objective.
S |
prob |
Reimplemented from AbstractEA< S >.
|
overridevirtual |
Uptades the problem to solve using a share_ptr. The problem must be single-objective.
S |
prob |
Reimplemented from AbstractEA< S >.
void AbstractGA< S >::setSelection | ( | unique_ptr< Selection< S >> | newSelection | ) |
Updates the selection operator. Takes a unique_ptr pointing to the new Selection operator and takes the ownership.
S |
newSelection |
|
overridevirtual |
Creates and returns JSON object with the GA information.
S |
Reimplemented from AbstractEA< S >.
|
protected |
Crossover operator
|
protected |
Crossover rate to apply the crossover operator
|
static |
Default crossover rate to GAs set to 0.8.
S |
|
static |
Default mutation rate for GAs set to 0.05.
S |
|
static |
Default population size to GAs set to 32 individuals.
S |
|
protected |
Mutation operator
|
protected |
Mutation rate to apply the mutation operator
|
protected |
Replacement operator
|
protected |
Selection operator