Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::layered_population< I > Class Template Reference

#include <layered_population.h>

Classes

struct  coord
class  base_iterator

Public Types

using layer_t = linear_population<I>
using layer_iter = typename std::list<layer_t>::iterator
using layer_const_iter = typename std::list<layer_t>::const_iterator
using value_type = I
using const_iterator = base_iterator<true>
using iterator = base_iterator<false>

Public Member Functions

 layered_population (const ultra::problem &, bool=true)
const layer_t & front () const
layer_t & front ()
const layer_t & back () const
layer_t & back ()
std::size_t layers () const noexcept
const layer_t & layer (std::size_t) const
layer_t & layer (std::size_t)
auto range_of_layers () const
auto range_of_layers ()
const I & operator[] (coord) const
I & operator[] (coord)
void init (layer_t &)
void add_layer ()
bool erase (layer_t &)
layer_iter erase (layer_iter)
std::size_t size () const
void inc_age ()
const ultra::problem & problem () const
const_iterator begin () const
const_iterator end () const
iterator begin ()
iterator end ()
bool is_valid () const
bool load (std::istream &)
bool save (std::ostream &) const

Detailed Description

template<Individual I>
class ultra::layered_population< I >

A group of individuals which may interact together (for example by mating) producing offspring.

Typical population size ranges from one hundred to many thousands. The population is organized in one or more layers that can interact in many ways (depending on the evolution strategy).

Constructor & Destructor Documentation

◆ layered_population()

template<Individual I>
ultra::layered_population< I >::layered_population ( const ultra::problem & p,
bool init_subgroups = true )
explicit

Creates a random population.

Parameters
[in]pcurrent problem
[in]init_subgroupsbuilds p.params.population.init_subgroups layers

Member Function Documentation

◆ add_layer()

template<Individual I>
void ultra::layered_population< I >::add_layer ( )

Adds a new layer to the population.

The new layer is inserted as the lower layer and randomly initialized.

◆ back() [1/2]

template<Individual I>
layered_population< I >::layer_t & ultra::layered_population< I >::back ( )
nodiscard
Returns
reference to the last layer of the population

◆ back() [2/2]

template<Individual I>
const layered_population< I >::layer_t & ultra::layered_population< I >::back ( ) const
nodiscard
Returns
const reference to the last layer of the population

◆ begin() [1/2]

template<Individual I>
layered_population< I >::iterator ultra::layered_population< I >::begin ( )
nodiscard
Returns
a iterator pointing to the first individual of the population

◆ begin() [2/2]

template<Individual I>
layered_population< I >::const_iterator ultra::layered_population< I >::begin ( ) const
nodiscard
Returns
a const_iterator pointing to the first individual of the population

◆ end() [1/2]

template<Individual I>
layered_population< I >::iterator ultra::layered_population< I >::end ( )
nodiscard
Returns
an iterator pointing one element past the last individual of the population

◆ end() [2/2]

template<Individual I>
layered_population< I >::const_iterator ultra::layered_population< I >::end ( ) const
nodiscard
Returns
an iterator pointing one element past the last individual of the population

◆ erase() [1/2]

template<Individual I>
layered_population< I >::layer_iter ultra::layered_population< I >::erase ( layer_iter pos)

Erases the specified element from the container.

Parameters
[in]positerator to the element to remove
Returns
iterator following the last removed element. If pos refers to the last element, then the end() iterator is returned

References and iterators to the erased element are invalidated. Other references and iterators are not affected.

◆ erase() [2/2]

template<Individual I>
bool ultra::layered_population< I >::erase ( layer_t & l)

Erases the specified element from the container.

Parameters
[in]lreference to the element to remove
Returns
true if an element has been removed; false otherwise

◆ front() [1/2]

template<Individual I>
layered_population< I >::layer_t & ultra::layered_population< I >::front ( )
nodiscard
Returns
reference to the first layer of the population

◆ front() [2/2]

template<Individual I>
const layered_population< I >::layer_t & ultra::layered_population< I >::front ( ) const
nodiscard
Returns
const reference to the first layer of the population

◆ inc_age()

template<Individual I>
void ultra::layered_population< I >::inc_age ( )

Increments the age of each individual of the population

◆ init()

template<Individual I>
void ultra::layered_population< I >::init ( layer_t & l)

Resets a layer of the population.

Parameters
[in]la layer of the population

◆ is_valid()

template<Individual I>
bool ultra::layered_population< I >::is_valid ( ) const
nodiscard
Returns
true if the object passes the internal consistency check

◆ layer() [1/2]

template<Individual I>
layered_population< I >::layer_t & ultra::layered_population< I >::layer ( std::size_t l)
nodiscard
Parameters
[in]llayer index
Returns
reference to a layer of the population

◆ layer() [2/2]

template<Individual I>
const layered_population< I >::layer_t & ultra::layered_population< I >::layer ( std::size_t l) const
nodiscard
Parameters
[in]llayer index
Returns
a const reference to a layer of the population

◆ layers()

template<Individual I>
std::size_t ultra::layered_population< I >::layers ( ) const
nodiscardnoexcept
Returns
number of active layers
Note
The number of active layers is a dynamic value (almost monotonically increasing with the generation number).

◆ load()

template<Individual I>
bool ultra::layered_population< I >::load ( std::istream & in)
nodiscard
Parameters
[in]ininput stream
Returns
true if population has been correctly loaded
Note
The current population isn't changed if the load operation fails.

◆ operator[]() [1/2]

template<Individual I>
I & ultra::layered_population< I >::operator[] ( coord c)
nodiscard
Parameters
[in]ccoordinate identifying an individual within the population
Returns
a reference to the selected individual
Warning
Access through this operator is not constant-time. While indexing within a layer is typically O(1), locating the layer requires traversing the underlying container, resulting in linear complexity in the number of layers.
Remarks
Prefer caching a reference to the target layer when performing repeated accesses to avoid repeated traversal.

◆ operator[]() [2/2]

template<Individual I>
const I & ultra::layered_population< I >::operator[] ( coord c) const
nodiscard
Parameters
[in]ccoordinate identifying an individual within the population
Returns
a const reference to the selected individual
Warning
Access through this operator is not constant-time. While indexing within a layer is typically O(1), locating the layer requires traversing the underlying container, resulting in linear complexity in the number of layers.
Remarks
Prefer caching a reference to the target layer when performing repeated accesses to avoid repeated traversal.

◆ problem()

template<Individual I>
const ultra::problem & ultra::layered_population< I >::problem ( ) const
nodiscard
Returns
a constant reference to the active problem

◆ save()

template<Individual I>
bool ultra::layered_population< I >::save ( std::ostream & out) const
nodiscard
Parameters
[out]outoutput stream
Returns
true if population has been correctly saved

◆ size()

template<Individual I>
std::size_t ultra::layered_population< I >::size ( ) const
nodiscard
Returns
the number of individuals in the population

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