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

Represents a single candidate solution in the population. More...

#include <Individual.h>

Public Member Functions

 Individual ()
 Default constructor. Initializes fitness to the maximum possible double value.
 
 Individual (std::size_t num_genes)
 Constructs an Individual with a specific number of genes.
 
std::size_t size () const
 Returns the number of genes in the genotype.
 
std::vector< GeneType > & getGenotype ()
 Returns a reference to the genotype vector.
 
const std::vector< GeneType > & getGenotype () const
 Returns a constant reference to the genotype vector.
 
void setGenotype (const std::vector< GeneType > &new_genotype)
 Sets the genotype by copying.
 
void setGenotype (std::vector< GeneType > &&new_genotype) noexcept
 Sets the genotype by moving.
 
double getFitness () const
 Gets the current fitness score.
 
void setFitness (double new_fitness)
 Sets a new fitness score.
 
auto operator<=> (const Individual &other) const
 Three-way comparison operator based on fitness (for minimization).
 
bool operator== (const Individual &other) const
 Equality operator based on fitness.
 

Friends

std::ostream & operator<< (std::ostream &os, const Individual &ind)
 Streams a summary of the individual (fitness and first few genes).
 

Detailed Description

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

Represents a single candidate solution in the population.

An Individual consists of a genotype (a vector of genes) and a fitness score. It supports comparison operators for sorting based on fitness (minimization).

Template Parameters
GeneTypeThe type of the genes (default: double).

Definition at line 23 of file Individual.h.

Constructor & Destructor Documentation

◆ Individual() [1/2]

template<typename GeneType = double>
galib::Individual< GeneType >::Individual ( )
inline

Default constructor. Initializes fitness to the maximum possible double value.

Definition at line 34 of file Individual.h.

◆ Individual() [2/2]

template<typename GeneType = double>
galib::Individual< GeneType >::Individual ( std::size_t  num_genes)
inlineexplicit

Constructs an Individual with a specific number of genes.

Parameters
num_genesNumber of genes in the genotype.

Definition at line 40 of file Individual.h.

Member Function Documentation

◆ getFitness()

template<typename GeneType = double>
double galib::Individual< GeneType >::getFitness ( ) const
inline

◆ getGenotype() [1/2]

template<typename GeneType = double>
std::vector< GeneType > & galib::Individual< GeneType >::getGenotype ( )
inline

◆ getGenotype() [2/2]

template<typename GeneType = double>
const std::vector< GeneType > & galib::Individual< GeneType >::getGenotype ( ) const
inline

Returns a constant reference to the genotype vector.

Returns
Constant reference to the genotype.

Definition at line 59 of file Individual.h.

◆ operator<=>()

template<typename GeneType = double>
auto galib::Individual< GeneType >::operator<=> ( const Individual< GeneType > &  other) const
inline

Three-way comparison operator based on fitness (for minimization).

Parameters
otherThe individual to compare against.

Definition at line 89 of file Individual.h.

◆ operator==()

template<typename GeneType = double>
bool galib::Individual< GeneType >::operator== ( const Individual< GeneType > &  other) const
inline

Equality operator based on fitness.

Parameters
otherThe individual to compare against.

Definition at line 97 of file Individual.h.

◆ setFitness()

template<typename GeneType = double>
void galib::Individual< GeneType >::setFitness ( double  new_fitness)
inline

Sets a new fitness score.

Parameters
new_fitnessThe new fitness value.

Definition at line 83 of file Individual.h.

Referenced by galib::internal::BinarySerializer< GeneType >::deserialize(), galib::internal::BinarySerializer< GeneType >::deserialize(), and galib::DifferentialEvolutionGA< GeneType >::run().

◆ setGenotype() [1/2]

template<typename GeneType = double>
void galib::Individual< GeneType >::setGenotype ( const std::vector< GeneType > &  new_genotype)
inline

Sets the genotype by copying.

Parameters
new_genotypeThe new genotype vector.

Definition at line 65 of file Individual.h.

Referenced by galib::internal::BinarySerializer< GeneType >::deserialize(), and galib::internal::BinarySerializer< GeneType >::deserialize().

◆ setGenotype() [2/2]

template<typename GeneType = double>
void galib::Individual< GeneType >::setGenotype ( std::vector< GeneType > &&  new_genotype)
inlinenoexcept

Sets the genotype by moving.

Parameters
new_genotypeThe new genotype vector.

Definition at line 71 of file Individual.h.

◆ size()

template<typename GeneType = double>
std::size_t galib::Individual< GeneType >::size ( ) const
inline

Returns the number of genes in the genotype.

Returns
Size of the genotype vector.

Definition at line 47 of file Individual.h.

Referenced by galib::ArithmeticCrossover< GeneType >::crossover(), and galib::UniformCrossover< GeneType >::crossover().

Friends And Related Symbol Documentation

◆ operator<<

template<typename GeneType = double>
std::ostream & operator<< ( std::ostream &  os,
const Individual< GeneType > &  ind 
)
friend

Streams a summary of the individual (fitness and first few genes).

Definition at line 104 of file Individual.h.


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