dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
AbstractGA< S > Class Template Referenceabstract

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>

Inheritance diagram for AbstractGA< S >:
AbstractEA< S > FIGA< S > GenerationalGA< S > NSGA2< S > ParallelGeneticAlgorithm< S > SteadyGA< S >

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
 

Detailed Description

template<class S>
class AbstractGA< S >

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.

Template Parameters
SType of individual in the population.

Constructor & Destructor Documentation

◆ AbstractGA()

template<class S >
AbstractGA< S >::AbstractGA

Creates a new AbstractGA which initialises all parameter to default. The operators will be set to null.

Template Parameters
S

Member Function Documentation

◆ createInitialPopulation()

template<class S >
void AbstractGA< S >::createInitialPopulation
protectedvirtual

Creates the initial population of individuals before starting the evolutionary process.

Template Parameters
S

Implements AbstractEA< S >.

Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.

◆ createMating()

template<class S >
vector< S > AbstractGA< S >::createMating
protectedvirtual

Generates the mating population of individuals to be evaluated. The individuals are selected and after that the genetic operators are applied here.

Template Parameters
S
Returns
vector

Reimplemented in SteadyGA< S >, and NSGA2< S >.

◆ evaluatePopulation()

template<class S >
void AbstractGA< S >::evaluatePopulation ( vector< S > &  pop)
protectedvirtual

Evaluates the entire population of individuals using the problem evaluation function.

Template Parameters
S
Parameters
pop

Implements AbstractEA< S >.

Reimplemented in NSGA2< S >.

◆ finishProgress()

template<class S >
void AbstractGA< S >::finishProgress
protectedvirtual

Finishes the evolutionary process by computing the elapsed time.

Template Parameters
S

Implements AbstractEA< S >.

◆ getCrossover()

template<class S >
const Crossover< S > * AbstractGA< S >::getCrossover

Returns a raw pointer to the crossover operator.

Template Parameters
S
Returns
const Crossover*

◆ getCrossRate()

template<class S >
double AbstractGA< S >::getCrossRate

Gets the crossover rate.

Template Parameters
S
Returns
double

◆ getMutation()

template<class S >
const Mutation< S > * AbstractGA< S >::getMutation

Gets a pointer to the mutation operator.

Template Parameters
S
Returns
const Mutation*

◆ getMutationRate()

template<class S >
double AbstractGA< S >::getMutationRate

Gets the mutation rate.

Template Parameters
S
Returns
double

◆ getName()

template<class S >
virtual string AbstractGA< S >::getName ( ) const
pure virtual

Returns the name of the algorithm, this is used in the to_json method. Must be implemented in the subclasses.

Returns
string

Implements AbstractEA< S >.

Implemented in SteadyGA< S >, ParallelGeneticAlgorithm< S >, GenerationalGA< S >, FIGA< S >, and NSGA2< S >.

◆ getResults()

template<class S >
Front< S > AbstractGA< S >::getResults
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.

Template Parameters
S
Returns
Front

Implements AbstractEA< S >.

Reimplemented in NSGA2< S >.

◆ getSelection()

template<class S >
const Selection< S > * AbstractGA< S >::getSelection

Returns a raw pointer of the selection operator.

Template Parameters
S
Returns
const Selection*

◆ initProgress()

template<class S >
void AbstractGA< S >::initProgress
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.

Template Parameters
S

Implements AbstractEA< S >.

Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.

◆ isStoppingConditionReached()

template<class S >
bool AbstractGA< S >::isStoppingConditionReached
protectedvirtual

Checks whether the evolutionary process has reached the maximum limit.

Template Parameters
S
Returns
true If the evolutionary has reached the maximum number of evaluations to perform
false otherwise

Implements AbstractEA< S >.

◆ reproduction()

template<class S >
void AbstractGA< S >::reproduction ( S &  child1,
S &  child2 
)
protectedvirtual

Applies the genetic operator. This methods is invoked from createMating.

Template Parameters
S
Parameters
child1
child2

Reimplemented in NSGA2< S >, and ParallelGeneticAlgorithm< S >.

◆ run()

template<class S >
void AbstractGA< S >::run
overridevirtual

Runs the evolutionary process. This is the main EA method. This methods is in charge of:

  1. Creating the initial population.
  2. While the stop condition is not met:
    1. Mate the individuals.
    2. Evaluate the population.
    3. Perform the replacement.
    4. Update the process.
    5. Update the evolution metrics.
Template Parameters
S

Implements AbstractEA< S >.

◆ setCrossover()

template<class 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.

Template Parameters
S
Parameters
newCX

◆ setCrossRate()

template<class S >
void AbstractGA< S >::setCrossRate ( double  crossRate)

Updates the crossover rate.

Template Parameters
S
Parameters
crossRate

◆ setMutation()

template<class S >
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.

Template Parameters
S
Parameters
newMut

◆ setMutationRate()

template<class S >
void AbstractGA< S >::setMutationRate ( double  mutationRate)

Updates the mutation rate.

Template Parameters
S
Parameters
mutationRate

◆ setProblem() [1/2]

template<class S >
void AbstractGA< S >::setProblem ( Problem< S > *  prob)
overridevirtual

Uptades the problem to solve using a raw pointer. The problem must be single-objective.

Template Parameters
S
Parameters
prob

Reimplemented from AbstractEA< S >.

◆ setProblem() [2/2]

template<class S >
void AbstractGA< S >::setProblem ( shared_ptr< Problem< S >>  prob)
overridevirtual

Uptades the problem to solve using a share_ptr. The problem must be single-objective.

Template Parameters
S
Parameters
prob

Reimplemented from AbstractEA< S >.

◆ setSelection()

template<class 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.

Template Parameters
S
Parameters
newSelection

◆ to_json()

template<class S >
json AbstractGA< S >::to_json
overridevirtual

Creates and returns JSON object with the GA information.

Template Parameters
S
Returns
a json representation of the GA

Reimplemented from AbstractEA< S >.

Member Data Documentation

◆ crossover

template<class S >
unique_ptr<Crossover<S> > AbstractGA< S >::crossover
protected

Crossover operator

◆ crossRate

template<class S >
double AbstractGA< S >::crossRate
protected

Crossover rate to apply the crossover operator

◆ DEFAULT_CROSSOVER_RATE

template<class S >
double AbstractGA< S >::DEFAULT_CROSSOVER_RATE = 0.8
static

Default crossover rate to GAs set to 0.8.

Template Parameters
S

◆ DEFAULT_MUTATION_RATE

template<class S >
double AbstractGA< S >::DEFAULT_MUTATION_RATE = 0.05
static

Default mutation rate for GAs set to 0.05.

Template Parameters
S

◆ DEFAULT_POPULATION_SIZE

template<class S >
int AbstractGA< S >::DEFAULT_POPULATION_SIZE = 32
static

Default population size to GAs set to 32 individuals.

Template Parameters
S

◆ mutation

template<class S >
unique_ptr<Mutation<S> > AbstractGA< S >::mutation
protected

Mutation operator

◆ mutationRate

template<class S >
double AbstractGA< S >::mutationRate
protected

Mutation rate to apply the mutation operator

◆ replacement

template<class S >
unique_ptr<Replacement<S> > AbstractGA< S >::replacement
protected

Replacement operator

◆ selection

template<class S >
unique_ptr<Selection<S> > AbstractGA< S >::selection
protected

Selection operator


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