mc2lib
Public Types | Public Member Functions | Protected Attributes | List of all members
mc2lib::simplega::GenePool< GenomeT > Class Template Reference

Helper to manages and evolve a populates. More...

#include <simplega.hpp>

Public Types

typedef std::list< GenomeT > Population
 
typedef std::vector< GenomeT * > Selection
 

Public Member Functions

 GenePool (std::size_t target_population_size=80, float mutation_rate=0.02f)
 
 GenePool (Population population, float mutation_rate=0.02f)
 
 GenePool (Selection selection, float mutation_rate=0.02f)
 
 operator std::string () const
 
const Populationget () const
 
Populationget_ptr ()
 
float mutation_rate () const
 
void set_mutation_rate (float mutation_rate)
 
std::size_t target_population_size () const
 
std::size_t population_size () const
 
std::size_t steps () const
 
float AverageFitness () const
 
float WorstFitness () const
 
float BestFitness () const
 
void Sort ()
 
const GenomeT & SelectBest () const
 
Selection SelectAll ()
 
template<class URNG , class DIST >
Selection SelectDist (URNG &urng, DIST &dist, std::size_t count)
 
template<class URNG >
Selection SelectRoulette (URNG &urng, std::size_t count)
 
template<class URNG >
Selection SelectUniform (URNG &urng, std::size_t count)
 
void SelectionSort (Selection *v)
 
template<class URNG , class CrossoverMutateFunc >
void Step (URNG &urng, CrossoverMutateFunc crossover_mutate, const Selection &selection, std::size_t mates, std::size_t keep=0, std::size_t mate1_stride=1, std::size_t mate2_stride=1)
 

Protected Attributes

std::size_t target_population_size_
 
float mutation_rate_
 
std::size_t steps_
 
Population population_
 

Detailed Description

template<class GenomeT>
class mc2lib::simplega::GenePool< GenomeT >

Helper to manages and evolve a populates.

Helps manage and evolve a population, and provides various primitives for implementing selection operators.

Member Typedef Documentation

§ Population

template<class GenomeT>
typedef std::list<GenomeT> mc2lib::simplega::GenePool< GenomeT >::Population

Using a list for the population pool, as this permits O(1) removal of elements.

§ Selection

template<class GenomeT>
typedef std::vector<GenomeT*> mc2lib::simplega::GenePool< GenomeT >::Selection

Constructor & Destructor Documentation

§ GenePool() [1/3]

template<class GenomeT>
mc2lib::simplega::GenePool< GenomeT >::GenePool ( std::size_t  target_population_size = 80,
float  mutation_rate = 0.02f 
)
inlineexplicit

§ GenePool() [2/3]

template<class GenomeT>
mc2lib::simplega::GenePool< GenomeT >::GenePool ( Population  population,
float  mutation_rate = 0.02f 
)
inlineexplicit

§ GenePool() [3/3]

template<class GenomeT>
mc2lib::simplega::GenePool< GenomeT >::GenePool ( Selection  selection,
float  mutation_rate = 0.02f 
)
inlineexplicit

Member Function Documentation

§ AverageFitness()

template<class GenomeT>
float mc2lib::simplega::GenePool< GenomeT >::AverageFitness ( ) const
inline

§ BestFitness()

template<class GenomeT>
float mc2lib::simplega::GenePool< GenomeT >::BestFitness ( ) const
inline

§ get()

template<class GenomeT>
const Population& mc2lib::simplega::GenePool< GenomeT >::get ( ) const
inline

§ get_ptr()

template<class GenomeT>
Population* mc2lib::simplega::GenePool< GenomeT >::get_ptr ( )
inline

§ mutation_rate()

template<class GenomeT>
float mc2lib::simplega::GenePool< GenomeT >::mutation_rate ( ) const
inline

§ operator std::string()

template<class GenomeT>
mc2lib::simplega::GenePool< GenomeT >::operator std::string ( ) const
inline

§ population_size()

template<class GenomeT>
std::size_t mc2lib::simplega::GenePool< GenomeT >::population_size ( ) const
inline

§ SelectAll()

template<class GenomeT>
Selection mc2lib::simplega::GenePool< GenomeT >::SelectAll ( )
inline
Returns
Entire population as Selection.

§ SelectBest()

template<class GenomeT>
const GenomeT& mc2lib::simplega::GenePool< GenomeT >::SelectBest ( ) const
inline

§ SelectDist()

template<class GenomeT>
template<class URNG , class DIST >
Selection mc2lib::simplega::GenePool< GenomeT >::SelectDist ( URNG &  urng,
DIST &  dist,
std::size_t  count 
)
inline
Returns
Random subset of population, using distribution dist to select.

§ SelectionSort()

template<class GenomeT>
void mc2lib::simplega::GenePool< GenomeT >::SelectionSort ( Selection v)
inline

Sorts (in-place) a Selection based on fitness.

§ SelectRoulette()

template<class GenomeT>
template<class URNG >
Selection mc2lib::simplega::GenePool< GenomeT >::SelectRoulette ( URNG &  urng,
std::size_t  count 
)
inline
Returns
Random subset of population, where a higher fitness means an individual is more likely to be selected.

§ SelectUniform()

template<class GenomeT>
template<class URNG >
Selection mc2lib::simplega::GenePool< GenomeT >::SelectUniform ( URNG &  urng,
std::size_t  count 
)
inline
Returns
Random subset of the population, where each individual has the same probability of being selected.

§ set_mutation_rate()

template<class GenomeT>
void mc2lib::simplega::GenePool< GenomeT >::set_mutation_rate ( float  mutation_rate)
inline

§ Sort()

template<class GenomeT>
void mc2lib::simplega::GenePool< GenomeT >::Sort ( )
inline

Sorts (in-place) the population based on fitness.

§ Step()

template<class GenomeT>
template<class URNG , class CrossoverMutateFunc >
void mc2lib::simplega::GenePool< GenomeT >::Step ( URNG &  urng,
CrossoverMutateFunc  crossover_mutate,
const Selection selection,
std::size_t  mates,
std::size_t  keep = 0,
std::size_t  mate1_stride = 1,
std::size_t  mate2_stride = 1 
)
inline

Takes a selection and mates the initial selection[:mates] individuals.

The elements in selection also determine which individuals are to be removed from the population; selection[keep:] are removed from population (can e.g. be used for elitism).

§ steps()

template<class GenomeT>
std::size_t mc2lib::simplega::GenePool< GenomeT >::steps ( ) const
inline

§ target_population_size()

template<class GenomeT>
std::size_t mc2lib::simplega::GenePool< GenomeT >::target_population_size ( ) const
inline

§ WorstFitness()

template<class GenomeT>
float mc2lib::simplega::GenePool< GenomeT >::WorstFitness ( ) const
inline

Member Data Documentation

§ mutation_rate_

template<class GenomeT>
float mc2lib::simplega::GenePool< GenomeT >::mutation_rate_
protected

§ population_

template<class GenomeT>
Population mc2lib::simplega::GenePool< GenomeT >::population_
protected

§ steps_

template<class GenomeT>
std::size_t mc2lib::simplega::GenePool< GenomeT >::steps_
protected

§ target_population_size_

template<class GenomeT>
std::size_t mc2lib::simplega::GenePool< GenomeT >::target_population_size_
protected

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