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

Class to define an Abstract Evolutionary Algorithm. This is the base skeleton for future extensions. More...

#include <AbstractEA.h>

Inheritance diagram for AbstractEA< S >:
Heuristic< IntIntSolution > Heuristic< BoolFloatSolution > Heuristic< IntFloatSolution > AbstractGA< S > Heuristic< S > SimulatedAnnealing< S > BestFit FirstFit NextFit WorstFit Combo Default ExpKnap MinKnap tsp_heuristics::Greedy tsp_heuristics::NearestNeighbour tsp_heuristics::TwoOpt FIGA< S > GenerationalGA< S > NSGA2< S > ParallelGeneticAlgorithm< S > SteadyGA< S >

Public Member Functions

 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 void run ()=0
 Main method of the EA. Runs the algorithm but must be implemented in the subclasses.
 
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...
 
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...
 
virtual json to_json () const
 Generates and returns the JSON representation of the EA. More...
 
virtual Front< S > getResults () const =0
 Returns a Front object with all the solutions of the evolutionary process. This method must be implemented in the subclasses. 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...
 
virtual void setProblem (shared_ptr< Problem< S >> prob)
 Set the new problem to solve. Uses a shared_ptr pointer which updates the reference counter. Does no take the ownership. More...
 
virtual void setProblem (Problem< S > *prob)
 Set the new problem to solve. Uses a raw pointer and takes the ownership of the object. 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 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 ()=0
 Initialises the evolutionary progress. This method must be implemented in the subclasses and should perform all necessary steps before the main loop.
 
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 ()=0
 Method which finishes the evolutionary progress. This method must be implemented in the subclasses and it should perform thinks like computing the execution time, etc.
 
virtual bool isStoppingConditionReached ()=0
 Check whether the number of performed evaluations has reached the maximum allowed. Must be implemented in the subclasses to adapt special cases. More...
 
virtual void createInitialPopulation ()=0
 Creates the initial population of individuals. Must be implemented in the subclasses to adapt special cases.
 
virtual void evaluatePopulation (vector< S > &pop)=0
 Evaluates the entire population of solutions. This is a virtual method that must be implemented in the subclasses to adapt special cases.
 
virtual void updateEvolution (vector< S > &pop)
 
virtual void updateEvolution (const int &checkpoint, vector< S > &)
 

Protected Attributes

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 AbstractEA< S >

Class to define an Abstract Evolutionary Algorithm. This is the base skeleton for future extensions.

Template Parameters
SType of individuals

Constructor & Destructor Documentation

◆ AbstractEA() [1/3]

template<class S >
AbstractEA< S >::AbstractEA

Construct a new Abstract EA object with default parameter values.

  • maxEvaluations is set to 100000 evaluations.
  • populationSize is set to 100 individuals of type S.
Template Parameters
S

◆ AbstractEA() [2/3]

template<class S >
AbstractEA< S >::AbstractEA ( const int &  maxEvals,
const int &  popsize 
)

AbstractEA constructor which initialises the parameters maxEvalautions and populationSize.

Template Parameters
S
Parameters
maxEvalsMaximum number of evaluations to perform
popsizeNumber of individuals in the population

◆ AbstractEA() [3/3]

template<class S >
AbstractEA< S >::AbstractEA ( unique_ptr< PopulationEvaluator< S >>  eval,
const int &  maxEvals,
const int &  popsize 
)

AbstractEA constructor which initialises the parameters maxEvalautions, the populationSize and the evaluator approach.

Template Parameters
S
Parameters
evalEvaluator approach (Sequential, parallel, OMP, etc)
maxEvalsMaximum number of evaluations to perform
popsizeNumber of individuals in the population

Member Function Documentation

◆ getElapsedTime()

template<class S >
double AbstractEA< S >::getElapsedTime ( ) const
inline

Get the elapsed time of the evolutionary process.

Returns
double

◆ getEvaluator()

template<class S >
PopulationEvaluator<S>* AbstractEA< S >::getEvaluator ( ) const
inline

Gets a pointer to the population evaluator system.

Returns
PopulationEvaluator*

◆ getEvolution()

template<class S >
Evolution< S > AbstractEA< S >::getEvolution
virtual

Get the Evolution data.

Returns the data of the evolution process. Includes the best fitness obtained at each evaluated checkpoint.

Returns
Evolution
Template Parameters
S
Returns
Evolution

◆ getID()

template<class S >
virtual string AbstractEA< S >::getID ( ) const
pure virtual

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.

Returns
string

Implemented in Heuristic< IntIntSolution >, Heuristic< BoolFloatSolution >, Heuristic< IntFloatSolution >, EIG< IP, IS, OP, OS >, SteadyGA< S >, SimulatedAnnealing< S >, ParallelGeneticAlgorithm< S >, GenerationalGA< S >, FIGA< S >, NSGA2< S >, Heuristic< S >, tsp_heuristics::TwoOpt, tsp_heuristics::NearestNeighbour, tsp_heuristics::Greedy, MPW, MiW, MinKnap, MaP, ExpKnap, Default, Combo, WorstFit, NextFit, FirstFit, and BestFit.

◆ getMaxEvaluations()

template<class S >
int AbstractEA< S >::getMaxEvaluations ( ) const
inline

Get the maximum number of evaluations to perform.

Returns
int

◆ getName()

◆ getPerformedEvaluations()

template<class S >
int AbstractEA< S >::getPerformedEvaluations ( ) const
inline

Get the performed evaluations.

Returns
int

◆ getPopulation()

template<class S >
const vector<S>& AbstractEA< S >::getPopulation ( ) const
inline

Gets a reference of the population.

Returns
const vector&

◆ getPopulationSize()

template<class S >
int AbstractEA< S >::getPopulationSize ( ) const
inline

Get the population size.

Returns
int

◆ getPrintingInterval()

template<class S >
int AbstractEA< S >::getPrintingInterval ( ) const
inline

Get the interval of checkpoints.

Returns
int

◆ getProblem()

template<class S >
const Problem<S>* AbstractEA< S >::getProblem ( ) const
inline

Gets a pointer to the problem which is being solved.

Returns
const Problem*

◆ getResults()

template<class S >
virtual Front<S> AbstractEA< S >::getResults ( ) const
pure virtual

◆ isStoppingConditionReached()

template<class S >
virtual bool AbstractEA< S >::isStoppingConditionReached ( )
protectedpure virtual

Check whether the number of performed evaluations has reached the maximum allowed. Must be implemented in the subclasses to adapt special cases.

Returns
true if the maximum number of evaluations have been performed
false otherwise

Implemented in EIG< IP, IS, OP, OS >, Heuristic< S >, Heuristic< IntIntSolution >, Heuristic< BoolFloatSolution >, Heuristic< IntFloatSolution >, SimulatedAnnealing< S >, and AbstractGA< S >.

◆ setEvaluator()

template<class S >
void AbstractEA< S >::setEvaluator ( unique_ptr< PopulationEvaluator< S >>  eval)
inline

Updates the population evaluator system with the unique_ptr. The method takes the ownership of the object behind.

Parameters
eval

◆ setMaxEvaluations()

template<class S >
void AbstractEA< S >::setMaxEvaluations ( int  maxEval)
inline

Set a new maximum number of evaluations to perform.

Parameters
maxEval

◆ setPerformedEvaluations()

template<class S >
void AbstractEA< S >::setPerformedEvaluations ( int  pEvals)
inline

Set the Performed Evaluations. Useful for the updateProgress method.

Parameters
pEvals

◆ setPopulation()

template<class S >
void AbstractEA< S >::setPopulation ( const vector< S > &  pop)

Set the Population.

Set the population of the EA.

Parameters
pop
popNew population to the EA.

◆ setPopulationSize()

template<class S >
void AbstractEA< S >::setPopulationSize ( int  pSize)

Setter to update the population size.

Template Parameters
S
Parameters
pSizeNew size of the population

◆ setProblem() [1/2]

template<class S >
virtual void AbstractEA< S >::setProblem ( Problem< S > *  prob)
inlinevirtual

Set the new problem to solve. Uses a raw pointer and takes the ownership of the object.

Parameters
prob

Reimplemented in AbstractGA< S >, SimulatedAnnealing< S >, and NSGA2< S >.

◆ setProblem() [2/2]

template<class S >
virtual void AbstractEA< S >::setProblem ( shared_ptr< Problem< S >>  prob)
inlinevirtual

Set the new problem to solve. Uses a shared_ptr pointer which updates the reference counter. Does no take the ownership.

Parameters
prob

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

◆ to_json()

template<class S >
json AbstractEA< S >::to_json
virtual

Generates and returns the JSON representation of the EA.

Template Parameters
S
Returns
json

Reimplemented in MapElites< IP, IS, OP, OS >, EIG< IP, IS, OP, OS >, AbstractGA< S >, ParallelGeneticAlgorithm< S >, Heuristic< S >, Heuristic< IntIntSolution >, Heuristic< BoolFloatSolution >, and Heuristic< IntFloatSolution >.

◆ updateEvolution() [1/2]

template<class S >
void AbstractEA< S >::updateEvolution ( const int &  checkpoint,
vector< S > &  solutions 
)
protectedvirtual

Updates the evolution results of the algorithm for the given checkpoint

Template Parameters
Problem
S
Parameters
checkpointCheckpoint in the evolution process
solutionssolutions Population of solutions in the checkpoin to collect data from

Reimplemented in Heuristic< S >.

◆ updateEvolution() [2/2]

template<class S >
void AbstractEA< S >::updateEvolution ( vector< S > &  solutions)
protectedvirtual

Updates the evolution results of the algorithm for the given checkpoint

Template Parameters
Problem
S
Parameters
solutionsPopulation of solutions in the checkpoin to collect data from

Reimplemented in Heuristic< S >.

Member Data Documentation

◆ DEFAULT_EVALUATIONS_LIMIT

template<class S >
const int AbstractEA< S >::DEFAULT_EVALUATIONS_LIMIT = 100000
static

Default evaluation limit equal to 100000 evaluations.

Template Parameters
S

◆ DEFAULT_POPULATION_SIZE

template<class S >
const int AbstractEA< S >::DEFAULT_POPULATION_SIZE = 100
static

Default population size equal to 100 individuals.

Template Parameters
S

◆ maxEvaluations

template<class S >
int AbstractEA< S >::maxEvaluations
protected

Number of evaluations to perform by the EA

◆ populationSize

template<class S >
int AbstractEA< S >::populationSize
protected

Number of individuals in the population


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