Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::vector_individual< T > Class Template Reference

#include <vector_individual.h>

Inheritance diagram for ultra::vector_individual< T >:
ultra::individual

Public Types

using genome_t = std::vector<T>
using const_iterator = genome_t::const_iterator
using iterator = genome_t::iterator
using value_type = genome_t::value_type
Public Types inherited from ultra::individual
using age_t = unsigned

Public Member Functions

const_iterator begin () const noexcept
const_iterator end () const noexcept
const value_type & operator[] (std::size_t) const
vector_individual & operator= (const std::vector< T > &)
bool empty () const noexcept
std::size_t size () const noexcept
std::size_t parameters () const noexcept
 operator const std::vector< T > & () const noexcept
bool is_valid () const
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void apply_each (std::size_t first, std::size_t last, F &&f)
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void apply_each (F &&f)
Public Member Functions inherited from ultra::individual
age_t age () const noexcept
void inc_age (unsigned=1) noexcept
bool load (std::istream &, const symbol_set &={})
bool save (std::ostream &) const
hash_t signature () const noexcept
std::string format (out::print_format_t) const

Protected Member Functions

 vector_individual (std::size_t)
 vector_individual (const ultra::problem &)
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void apply_each (std::size_t, std::size_t, F &&)
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void apply_each (F &&)
hash_t hash () const override
Protected Member Functions inherited from ultra::individual
void set_if_older_age (age_t) noexcept

Protected Attributes

genome_t genome_
Protected Attributes inherited from ultra::individual
hash_t signature_ {}

(Note that these are not member symbols.)

template<class T>
bool operator== (const vector_individual< T > &lhs, const vector_individual< T > &rhs) noexcept
template<class T>
std::size_t active_slots (const vector_individual< T > &ind) noexcept

Detailed Description

template<class T>
class ultra::vector_individual< T >

Provides a shared base for individuals with genomes stored in a vector.

Template Parameters
Tgene value type

Shares genome access, signature maintenance and serialisation. Derived classes define evolutionary operators.

Constructor & Destructor Documentation

◆ vector_individual() [1/2]

template<class T>
vector_individual::vector_individual ( std::size_t n)
explicitprotected

Allocates a genome for initialisation by a derived constructor.

Parameters
[in]nnumber of genes
Warning
The derived constructor must initialise the signature.

◆ vector_individual() [2/2]

template<class T>
vector_individual::vector_individual ( const ultra::problem & p)
explicitprotected

Constructs a random scalar genome and computes its signature.

Parameters
[in]pcurrent problem
Note
T must be D_INT or D_DOUBLE.

Member Function Documentation

◆ apply_each() [1/4]

template<class T>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void ultra::vector_individual< T >::apply_each ( F && f)
protected

Applies an operation to every gene and updates the signature.

Parameters
fmutating callable returning void
Precondition
no concurrent access

◆ apply_each() [2/4]

template<class T>
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void ultra::vector_individual< T >::apply_each ( F && f)

Applies an operation to every gene and updates the signature.

Parameters
fmutating callable returning void
Precondition
no concurrent access

◆ apply_each() [3/4]

template<class T>
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void ultra::vector_individual< T >::apply_each ( std::size_t first,
std::size_t last,
F && f )

Applies an operation to a range of genes and updates the signature.

Parameters
firstfirst index (inclusive)
lastone past the last index (exclusive)
fmutating callable returning void
Precondition
first <= last <= parameters(); no concurrent access

◆ apply_each() [4/4]

template<class T>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
template<class F>
requires std::invocable<F &, T &> && std::same_as<std::invoke_result_t<F &, T &>, void>
void ultra::vector_individual< T >::apply_each ( std::size_t first,
std::size_t last,
F && f )
protected

Applies an operation to a range of genes and updates the signature.

Parameters
firstfirst index (inclusive)
lastone past the last index (exclusive)
fmutating callable returning void
Precondition
first <= last <= parameters(); no concurrent access

◆ begin()

template<class T>
vector_individual< T >::const_iterator vector_individual::begin ( ) const
nodiscardnoexcept

Returns a const iterator to the first gene.

◆ empty()

template<class T>
bool vector_individual::empty ( ) const
nodiscardnoexcept

Checks whether the genome is empty.

◆ end()

template<class T>
vector_individual< T >::const_iterator vector_individual::end ( ) const
nodiscardnoexcept

Returns a const iterator past the last gene.

◆ hash()

template<class T>
hash_t vector_individual::hash ( ) const
nodiscardoverrideprotectedvirtual

Hashes the raw genome bytes with MurmurHash3.

Returns
the genome hash, or an empty hash for an empty genome

Implements ultra::individual.

◆ is_valid()

template<class T>
bool vector_individual::is_valid ( ) const
nodiscard
Returns
true if the individual passes the internal consistency check

◆ operator const std::vector< T > &()

template<class T>
vector_individual::operator const std::vector< T > & ( ) const
nodiscardnoexcept

Provides read-only access to the genome vector.

◆ operator=()

template<class T>
vector_individual< T > & vector_individual::operator= ( const std::vector< T > & v)

Replaces the genome and updates its signature.

Parameters
[in]vreplacement genes
Returns
a reference to *this

◆ operator[]()

template<class T>
const vector_individual< T >::value_type & vector_individual::operator[] ( std::size_t i) const
nodiscard

Returns the gene at the specified index.

Parameters
[in]iindex of the gene

◆ parameters()

template<class T>
std::size_t vector_individual::parameters ( ) const
nodiscardnoexcept

Returns the number of parameters, equivalent to size().

◆ size()

template<class T>
std::size_t vector_individual::size ( ) const
nodiscardnoexcept

Returns the number of genes.

◆ active_slots()

template<class T>
std::size_t active_slots ( const vector_individual< T > & ind)
related

Returns the number of parameters in the individual.

Parameters
[in]indindividual to inspect

◆ operator==()

template<class T>
bool operator== ( const vector_individual< T > & lhs,
const vector_individual< T > & rhs )
related

Compares genomes, ignoring age.

Parameters
[in]lhsfirst individual
[in]rhssecond individual

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