GALib-Parallel
Header-only C++ library for parallel evolutionary algorithms
Loading...
Searching...
No Matches
Public Member Functions | List of all members
galib::CellularGA< GeneType > Class Template Reference

Cellular genetic algorithm that evolves individuals on a local 2D neighbourhood. More...

#include <CellularGA.h>

Inheritance diagram for galib::CellularGA< GeneType >:
[legend]

Public Member Functions

 CellularGA (FitnessFunction< GeneType > &ff, std::unique_ptr< LocalSelection< GeneType > > local_sel, std::unique_ptr< Mutation< GeneType > > mu, std::unique_ptr< Crossover< GeneType > > cs, double m_rate, double c_rate, std::size_t max_gen, std::size_t threads, bool elitism=false)
 Constructs the cellular genetic algorithm with all required operators.
 
void run (Population< GeneType > &population) override
 Runs the cellular evolutionary optimisation loop.
 
- Public Member Functions inherited from galib::Algorithm< GeneType >
virtual ~Algorithm ()=default
 
virtual void enableConsoleLogging (const std::size_t interval)
 Enables logging of progress to the standard output.
 
virtual void enableFileLogging (const std::string &path, std::size_t interval)
 Enables logging of population snapshots to a CSV file.
 
virtual void enableLogging (const std::string &)
 Placeholder for generic logging configuration.
 

Additional Inherited Members

- Protected Member Functions inherited from galib::Algorithm< GeneType >
void notifyLoggers (std::size_t gen, const Population< GeneType > &pop)
 Notifies all active loggers to record the current state.
 
- Protected Attributes inherited from galib::Algorithm< GeneType >
std::unique_ptr< utils::ConsoleLogger< GeneType > > console_logger_m
 
std::unique_ptr< utils::FileLogger< GeneType > > file_logger_m
 

Detailed Description

template<typename GeneType = double>
class galib::CellularGA< GeneType >

Cellular genetic algorithm that evolves individuals on a local 2D neighbourhood.

The algorithm accepts a regular Population and interprets it as a 2D toroidal grid. Grid dimensions are inferred automatically from the population size by choosing a factorisation close to a square. Each cell evolves using only its local neighbourhood, which preserves spatial diversity better than fully mixing the whole population.

The evolutionary loop is:

  1. Infer grid dimensions from population.size().
  2. Evaluate the initial population.
  3. For each generation, evolve every cell independently from its local neighbourhood.
  4. Replace the old population with the newly produced one.
Template Parameters
GeneTypeNumeric type of each gene (default: double).
Note
Fitness is minimised: lower values are considered better.
The grid uses wrap-around boundaries, so edge cells still have neighbours.
When threads is 0, TBB chooses the level of parallelism automatically.

Definition at line 50 of file CellularGA.h.

Constructor & Destructor Documentation

◆ CellularGA()

template<typename GeneType = double>
galib::CellularGA< GeneType >::CellularGA ( FitnessFunction< GeneType > &  ff,
std::unique_ptr< LocalSelection< GeneType > >  local_sel,
std::unique_ptr< Mutation< GeneType > >  mu,
std::unique_ptr< Crossover< GeneType > >  cs,
double  m_rate,
double  c_rate,
std::size_t  max_gen,
std::size_t  threads,
bool  elitism = false 
)
inline

Constructs the cellular genetic algorithm with all required operators.

Parameters
ffFitness function used to evaluate individuals. Must outlive this object.
local_selLocal neighbourhood selection strategy. Ownership is transferred.
muMutation operator applied to produced offspring. Ownership is transferred.
csCrossover operator used to combine the current cell with a neighbour. Ownership is transferred.
m_rateMutation probability in the range [0, 1].
c_rateCrossover probability in the range [0, 1].
max_genNumber of generations to run.
threadsMaximum number of TBB worker threads. If 0, TBB decides automatically.
elitismIf true, the current individual competes with both children and the best one survives in the next generation.

Definition at line 156 of file CellularGA.h.

Member Function Documentation

◆ run()

template<typename GeneType = double>
void galib::CellularGA< GeneType >::run ( Population< GeneType > &  population)
inlineoverridevirtual

Runs the cellular evolutionary optimisation loop.

The input population is interpreted as a 2D grid whose shape is inferred from population.size(). The population is evolved in place and overwritten with the final generation.

Parameters
populationIn/out population to evolve.
Note
The population must be initialised before calling this method.
If the population is empty, the method returns immediately.

Implements galib::Algorithm< GeneType >.

Definition at line 190 of file CellularGA.h.

References galib::Population< GeneType >::empty(), galib::Population< GeneType >::getNumGenes(), galib::Algorithm< GeneType >::notifyLoggers(), and galib::Population< GeneType >::size().


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