Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::individual Class Referenceabstract

#include <individual.h>

Inheritance diagram for ultra::individual:
ultra::vector_individual< D_DOUBLE > ultra::vector_individual< D_INT > ultra::vector_individual< value_t > ultra::gp::individual ultra::vector_individual< T > ultra::de::individual ultra::ga::individual ultra::hga::individual

Public Types

using age_t = unsigned

Public Member Functions

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

void set_if_older_age (age_t) noexcept

Protected Attributes

hash_t signature_ {}

Detailed Description

A single member of a population.

Each individual contains a genome which represents a possible solution to the task being tackled (i.e. a point in the search space).

This class is the base class of every type of individual and factorizes out common code / data members.

Note
AKA chromosome
Thread-safety guarantees are type-specific. See derived class documentation.

Member Function Documentation

◆ age()

individual::age_t ultra::individual::age ( ) const
nodiscardnoexcept

A measurement of the age of an individual (mainly used for ALPS).

Returns
the individual's age

This is a measure of how long an individual's family of genotypic material has been in the population. Randomly generated individuals, such as those that are created when search starts, have an age of 0. Each generation that an individual stays in the population (such as through elitism) its age is increased by 1. Individuals that are created through mutation or recombination take the age of their oldest parent.

Note
This differs from conventional measures of age, in which individuals created through applying some type of variation to an existing individual (e.g. mutation or recombination) start with an age of 0.

◆ format()

std::string ultra::individual::format ( out::print_format_t fmt) const
nodiscard

Formats the individual according to the requested print format.

Parameters
[in]fmtformat specifier
Returns
string representation of the individual
Remarks
Target-language formats (C, C++, Python) remove basic redundant parentheses (at root level and inside function calls) while preserving defensive parentheses around operators. When minimal parentheses are desired, output can be normalized using target-language AST tools (e.g. Python's ast.unparse(ast.parse(code)) or C/C++ formatters).

◆ inc_age()

void ultra::individual::inc_age ( unsigned delta = 1)
noexcept

Increments the individual's age.

Parameters
[in]deltaincrement

◆ load()

bool ultra::individual::load ( std::istream & in,
const symbol_set & ss = {} )
nodiscard
Parameters
[in]ssactive symbol set
[in]ininput stream
Returns
true if the object has been loaded correctly
Note
If the load operation isn't successful the object isn't modified.

◆ save()

bool ultra::individual::save ( std::ostream & out) const
nodiscard
Parameters
[out]outoutput stream
Returns
true if the object has been saved correctly

◆ set_if_older_age()

void ultra::individual::set_if_older_age ( individual::age_t rhs_age)
protectednoexcept

Updates the age of this individual if it's smaller than rhs_age.

Parameters
[in]rhs_agethe age of an individual

◆ signature()

hash_t ultra::individual::signature ( ) const
nodiscardnoexcept

Returns the cached structural signature of the individual.

Returns
the signature of this individual

The signature is a hash representing the logical structure of the individual. It must be maintained by the derived type whenever the individual is mutated.

Signature maps syntactically distinct (but logically equivalent) individuals to the same value.

In other words identical individuals at genotypic level have the same signature; different individuals at the genotypic level may be mapped to the same signature since real structure/computation is considered and not the simple storage.

This is a very interesting property, useful for individual comparison, information retrieval, entropy calculation...

Note
Concurrent calls to signature() on the same instance are safe, provided the instance is not mutated concurrently.

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