Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::de::individual Class Referencefinal

#include <individual.h>

Inheritance diagram for ultra::de::individual:
ultra::vector_individual< D_DOUBLE > ultra::individual

Public Member Functions

 individual (const ultra::problem &p)
individual crossover (double, const interval< double > &, const individual &, const individual &, const individual &) 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, 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 &&)
vector_individual & operator= (const std::vector< T > &)
Public Member Functions inherited from ultra::vector_individual< D_DOUBLE >
void apply_each (std::size_t first, std::size_t last, F &&f)
void apply_each (F &&f)
const_iterator begin () const noexcept
const_iterator end () const noexcept
const value_type & operator[] (std::size_t) const
vector_individual & operator= (const std::vector< D_DOUBLE > &)
bool empty () const noexcept
std::size_t size () const noexcept
std::size_t parameters () const noexcept
 operator const std::vector< D_DOUBLE > & () const noexcept
bool is_valid () const
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

Additional Inherited Members

Public Types inherited from ultra::vector_individual< D_DOUBLE >
using genome_t
using const_iterator
using iterator
using value_type
Public Types inherited from ultra::individual
using age_t = unsigned
Protected Member Functions inherited from ultra::vector_individual< D_DOUBLE >
hash_t hash () const override
Protected Member Functions inherited from ultra::individual
void set_if_older_age (age_t) noexcept
Protected Attributes inherited from ultra::vector_individual< D_DOUBLE >
genome_t genome_
Protected Attributes inherited from ultra::individual
hash_t signature_ {}

Detailed Description

An individual optimized for differential evolution.

Note
This class implements a value type with no internal synchronisation. Any operation that mutates the individual is not thread-safe and must not run concurrently with any member function unless externally synchronised.
See also
Examples
rastrigin.cc, and scheduling.cc.

Member Function Documentation

◆ apply_each() [1/2]

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() [2/2]

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
Examples
scheduling.cc.

◆ crossover()

individual ultra::de::individual::crossover ( double p,
const interval< double > & f,
const individual & a,
const individual & b,
const individual & c ) const
nodiscard

Differential evolution crossover.

Parameters
[in]pcrossover probability (parameters.evolution.p_cross)
[in]fscaling factor interval (parameters.de.weight)
[in]abase vector
[in]bfirst vector used for calculating the difference vector
[in]csecond vector used for calculating the difference vector
Returns
the offspring / trial vector

First the search direction is defined by calculating a difference vector between the pair of vectors b and c (usually chosen at random from the population). This difference vector is scaled by using the scale factor F. This way no separate probability distribution has to be used which makes the scheme completely self-organizing.

The scaled difference vector is then added to a third vector a, called the base vector. As a result a new vector is obtained, known as the mutant or donor vector:

m = a + F * (b - c)

The mutation strategy used is named DE/rand/1. Now the offspring, also called trial, vector is generated as follows:

offspring = crossover(this, m)

The mutant vector is recombined, based on a user defined parameter, called crossover probability, with this (the target / parent vector). The offspring gets at least one component of the mutant vector (the last). This scheme is called binomial.

b and c are used for mutation, this and m for crossover.

◆ operator=()

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

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