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

#include <individual.h>

Inheritance diagram for ultra::hga::individual:
ultra::vector_individual< value_t > ultra::individual

Classes

class  modify_proxy

Public Member Functions

 individual (const ultra::problem &)
template<class F>
requires std::invocable<F &, individual::modify_proxy &> && std::same_as<std::invoke_result_t<F &, individual::modify_proxy&>, void>
void modify (F &&)
unsigned mutation (const problem &, double=1.0)
vector_individual & operator= (const std::vector< T > &)
Public Member Functions inherited from ultra::vector_individual< value_t >
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< value_t > &)
bool empty () const noexcept
std::size_t size () const noexcept
std::size_t parameters () const noexcept
 operator const std::vector< value_t > & () 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

Friends

individual crossover (const problem &, const individual &, const individual &)

(Note that these are not member symbols.)

D_IVECTOR pmx (const D_IVECTOR &lhs, const D_IVECTOR &rhs)
individual crossover (const problem &prb, const individual &lhs, const individual &rhs)

Additional Inherited Members

Public Types inherited from ultra::vector_individual< value_t >
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< value_t >
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< value_t >
genome_t genome_
Protected Attributes inherited from ultra::individual
hash_t signature_ {}

Detailed Description

An heterogeneous GA-individual.

Constructor & Destructor Documentation

◆ individual()

ultra::hga::individual::individual ( const ultra::problem & p)
explicit

Constructs a new, random HGA individual.

Parameters
[in]pcurrent problem

The process that generates the initial, random expressions has to be implemented so as to ensure that they don't violate the type system's constraints.

Member Function Documentation

◆ modify()

template<class F>
requires std::invocable<F &, individual::modify_proxy &> && std::same_as<std::invoke_result_t<F &, individual::modify_proxy&>, void>
void ultra::hga::individual::modify ( F && f)

Perform a controlled modification of the individual.

Template Parameters
Fcallable type accepting a modify_proxy
Parameters
fcallable invoked with a modification proxy
Postcondition
the individual is valid and its signature is up to date

Executes the callable f with a temporary modification proxy granting exclusive write access to the genome. During execution of f, class invariants of individual may be temporarily violated. All invariants are restored when this function returns. This is the only public entry point that permits arbitrary mutation of the individual.

◆ mutation()

unsigned ultra::hga::individual::mutation ( const problem & prb,
double temperature = 1.0 )

Mutates the current individual.

Parameters
[in]prbthe current problem
[in]temperaturemutation intensity (1.0 preserves the configured probability)
Returns
number of mutations performed
Note
External parameters: evolution.p_mutation

◆ 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

◆ crossover()

individual crossover ( const problem & prb,
const individual & lhs,
const individual & rhs )
related

Heterogeneous crossover.

Parameters
[in]prbthe current problem
[in]lhsfirst parent
[in]rhssecond parent
Returns
crossover children (we only generate a single offspring)

Genes of class integer are crossed using homogenous crossover; genes of class permutation are recombinex using PMX.

Note
Parents must have the same size.

◆ pmx()

D_IVECTOR pmx ( const D_IVECTOR & lhs,
const D_IVECTOR & rhs )
related

Partially mapped crossover (PMX).

Parameters
[in]lhsfirst permutation
[in]rhssecond permutation
Returns
new permutation

The Partially Mapped Crossover (PMX) is a recombination operator, initially designed for TSP like problems, that utilizes the genetic material of two parent solutions to propose a new offspring. It is one of the most commonly used crossover operator for permutation-encoded chromosomes. The principle behind PMX is to preserve the arrangement of genes from a parent while allowing variation in genes.


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