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

A container for a group of individuals in the genetic algorithm. More...

#include <Population.h>

Public Member Functions

 Population (std::size_t size, std::size_t num_genes)
 Constructs a population of a given size.
 
void initialize (GeneType lower, GeneType upper)
 Randomly initializes all individuals within the specified bounds.
 
std::size_t size () const
 Returns the total number of individuals in the population.
 
bool empty () const
 Checks if the population is empty.
 
std::size_t getNumGenes () const
 Returns the number of genes for individuals in this population.
 
Individual< GeneType > & operator[] (std::size_t index)
 Accesses an individual by its index.
 
const Individual< GeneType > & operator[] (std::size_t index) const
 Accesses an individual by its index (const version).
 
std::vector< Individual< GeneType > >::iterator begin ()
 Returns an iterator to the beginning.
 
std::vector< Individual< GeneType > >::iterator end ()
 Returns an iterator to the end.
 
std::vector< Individual< GeneType > >::const_iterator begin () const
 Returns a constant iterator to the beginning.
 
std::vector< Individual< GeneType > >::const_iterator end () const
 Returns a constant iterator to the end.
 
const Individual< GeneType > & getBestIndividual () const
 Finds and returns the individual with the best fitness score.
 

Detailed Description

template<typename GeneType>
class galib::Population< GeneType >

A container for a group of individuals in the genetic algorithm.

Provides methods for initializing individuals with random values and retrieving the best performing member.

Template Parameters
GeneTypeThe type of the genes.

Definition at line 24 of file Population.h.

Constructor & Destructor Documentation

◆ Population()

template<typename GeneType >
galib::Population< GeneType >::Population ( std::size_t  size,
std::size_t  num_genes 
)
inlineexplicit

Constructs a population of a given size.

Parameters
sizeNumber of individuals in the population. Must be > 0.
num_genesNumber of genes each individual should have.
Exceptions
std::invalid_argumentif size is 0.

Definition at line 35 of file Population.h.

References galib::Population< GeneType >::size().

Member Function Documentation

◆ begin() [1/2]

template<typename GeneType >
std::vector< Individual< GeneType > >::iterator galib::Population< GeneType >::begin ( )
inline

Returns an iterator to the beginning.

Definition at line 97 of file Population.h.

◆ begin() [2/2]

template<typename GeneType >
std::vector< Individual< GeneType > >::const_iterator galib::Population< GeneType >::begin ( ) const
inline

Returns a constant iterator to the beginning.

Definition at line 103 of file Population.h.

◆ empty()

template<typename GeneType >
bool galib::Population< GeneType >::empty ( ) const
inline

◆ end() [1/2]

template<typename GeneType >
std::vector< Individual< GeneType > >::iterator galib::Population< GeneType >::end ( )
inline

Returns an iterator to the end.

Definition at line 100 of file Population.h.

◆ end() [2/2]

template<typename GeneType >
std::vector< Individual< GeneType > >::const_iterator galib::Population< GeneType >::end ( ) const
inline

Returns a constant iterator to the end.

Definition at line 106 of file Population.h.

◆ getBestIndividual()

template<typename GeneType >
const Individual< GeneType > & galib::Population< GeneType >::getBestIndividual ( ) const
inline

Finds and returns the individual with the best fitness score.

Returns
Constant reference to the best individual.

Definition at line 112 of file Population.h.

Referenced by galib::GridPopulation< GeneType >::getBestIndividual(), galib::utils::ConsoleLogger< GeneType >::log(), and galib::StandardGA< GeneType >::run().

◆ getNumGenes()

template<typename GeneType >
std::size_t galib::Population< GeneType >::getNumGenes ( ) const
inline

◆ initialize()

template<typename GeneType >
void galib::Population< GeneType >::initialize ( GeneType  lower,
GeneType  upper 
)
inline

Randomly initializes all individuals within the specified bounds.

Parallelized using OpenMP.

Parameters
lowerLower bound for each gene.
upperUpper bound for each gene.

Definition at line 48 of file Population.h.

Referenced by galib::GridPopulation< GeneType >::initialize().

◆ operator[]() [1/2]

template<typename GeneType >
Individual< GeneType > & galib::Population< GeneType >::operator[] ( std::size_t  index)
inline

Accesses an individual by its index.

Parameters
indexZero-based index.
Returns
Reference to the individual.

Definition at line 87 of file Population.h.

◆ operator[]() [2/2]

template<typename GeneType >
const Individual< GeneType > & galib::Population< GeneType >::operator[] ( std::size_t  index) const
inline

Accesses an individual by its index (const version).

Parameters
indexZero-based index.
Returns
Constant reference to the individual.

Definition at line 94 of file Population.h.

◆ size()

template<typename GeneType >
std::size_t galib::Population< GeneType >::size ( ) const
inline

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