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

#include <NSGA2.h>

Inheritance diagram for NSGA2< S >:
AbstractGA< S > AbstractEA< S >

Public Member Functions

 NSGA2 ()
 Creates a RAW instance of a Generational GA algorithm. More...
 
string getName () const override
 Get the Name. More...
 
string getID () const override
 Get the ID of the algorithm. 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 multi-objective. More...
 
void setProblem (Problem< S > *prob) override
 Uptades the problem to solve using a raw pointer. The problem must be multi-objective. More...
 
virtual Front< S > getResults () const
 Creates the front of solution from the evolution. More...
 
- Public Member Functions inherited from AbstractGA< S >
 AbstractGA ()
 Creates a new AbstractGA which initialises all parameter to default. The operators will be set to null. More...
 
json to_json () const override
 Creates and returns JSON object with the GA information. 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...
 
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...
 

Protected Member Functions

void initProgress () override
 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...
 
void updateProgress () override
 Updates the performed evaluations to the population size on each call. More...
 
virtual void createInitialPopulation () override
 Creates the initial population of individuals before starting the evolutionary process. More...
 
virtual void evaluatePopulation (vector< S > &pop) override
 Evaluates the entire population of individuals using the problem evaluation function. More...
 
virtual vector< S > createMating () override
 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 &) override
 Applies the genetic operator. This methods is invoked from createMating. More...
 
- Protected Member Functions inherited from AbstractGA< S >
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...
 
- Protected Member Functions inherited from AbstractEA< S >
virtual void updateEvolution (vector< S > &pop)
 
virtual void updateEvolution (const int &checkpoint, vector< S > &)
 

Additional Inherited Members

- Static Public Attributes inherited from AbstractGA< S >
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 Attributes inherited from AbstractGA< S >
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 NSGA2< S >

@brief Class to represents a Non-dominated Sorting Genetic Algorithm II.

NSGA: Non-dominated Sorting GA (Srinivas & Deb, 1995)

-> N. Srinivas, K. Deb: Multiobjetive Optimization Using Nondominated Sorting in Genetic Algorithms. Evolutionary Computation 2 (1995) 221-248.


NSGA-II: Non-dominated Sorting Genetic Algorithm II

The algorithm was proposed by Deb in 2000. It is based on:

  • A fast non-dominated sorting approach, based on dominance fronts
  • A crowding operator
  • A selection operator which creates a mating pool by cominning the parent and child populations and selecting the best with respect to fitness and spread
Template Parameters
SType of individual in the population

Constructor & Destructor Documentation

◆ NSGA2()

template<class S >
NSGA2< S >::NSGA2

Creates a RAW instance of a Generational GA algorithm.

Template Parameters
Problem
S

Member Function Documentation

◆ createInitialPopulation()

template<class S >
void NSGA2< S >::createInitialPopulation
overrideprotectedvirtual

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

Template Parameters
S

Reimplemented from AbstractGA< S >.

◆ createMating()

template<class S >
vector< S > NSGA2< S >::createMating
overrideprotectedvirtual

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 from AbstractGA< S >.

◆ evaluatePopulation()

template<class S >
void NSGA2< S >::evaluatePopulation ( vector< S > &  pop)
overrideprotectedvirtual

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

Template Parameters
S
Parameters
pop

Reimplemented from AbstractGA< S >.

◆ getID()

template<class S >
string NSGA2< S >::getID ( ) const
inlineoverridevirtual

Get the ID of the algorithm.

Returns
string

Implements AbstractEA< S >.

◆ getName()

template<class S >
string NSGA2< S >::getName ( ) const
inlineoverridevirtual

Get the Name.

Returns
string

Implements AbstractGA< S >.

◆ getResults()

template<class S >
Front< S > NSGA2< S >::getResults
virtual

Creates the front of solution from the evolution.

Template Parameters
S
Returns
Front

Reimplemented from AbstractGA< S >.

◆ initProgress()

template<class S >
void NSGA2< S >::initProgress
overrideprotectedvirtual

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

Reimplemented from AbstractGA< S >.

◆ reproduction()

template<class S >
void NSGA2< S >::reproduction ( S &  child1,
S &  child2 
)
overrideprotectedvirtual

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

Template Parameters
S
Parameters
child1
child2

Reimplemented from AbstractGA< S >.

◆ run()

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

◆ setProblem() [1/2]

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

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

Template Parameters
S
Parameters
prob

Reimplemented from AbstractEA< S >.

◆ setProblem() [2/2]

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

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

Template Parameters
S
Parameters
prob

Reimplemented from AbstractEA< S >.

◆ updateProgress()

template<class S >
void NSGA2< S >::updateProgress
overrideprotectedvirtual

Updates the performed evaluations to the population size on each call.

Template Parameters
Problem
S

Implements AbstractGA< S >.


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