![]() |
Ultra 0.9.4
|
#include <gene.h>
Public Types | |
| using | arg_pack = std::vector<value_t> |
| Type used to store the arguments of the function. | |
Public Member Functions | |
| gene ()=default | |
| gene (const function *, const arg_pack &) | |
| locus | locus_of_argument (std::size_t) const noexcept |
| locus | locus_of_argument (const arg_pack::value_type &) const noexcept |
| symbol::category_t | category () const noexcept |
| bool | operator== (const gene &) const noexcept=default |
| bool | is_valid () const noexcept |
Public Attributes | |
| const function * | func {} |
| Pointer to the function symbol. | |
| arg_pack | args {} |
| Arguments of the function. | |
A gene is the atomic unit of a genetic programming individual.
In ULTRA's GP engine, a gene represents a single instruction in a Straight Line Program (SLP). It consists of:
Arguments may be:
A gene is always in one of the following states:
These states are recognised by is_valid(); callers modifying public members must preserve the invariant.
The gene class does not own the function it refers to. The pointed function object is expected to be managed by a longer-lived symbol_set.
gene is a passive value type and performs no internal synchronisation. Concurrent access is safe only if no thread mutates the object.
|
default |
Constructs an empty (inactive) gene.
The resulting gene has func == nullptr and no arguments. This state is valid and typically represents an unused slot in an individual's genome.
Constructs an active gene.
| [in] | f | pointer to the function symbol |
| [in] | a | arguments list for the function |
This constructor is primarily intended for debugging and hand-crafted individuals:
std::vector<gene> g
{
{f_add, {1, 2}}, // [0] ADD 1,2
{ y, {}}, // [1] Y
{ x, {}} // [2] X
};
|
nodiscardnoexcept |
Returns the output category of the gene.
|
nodiscardnoexcept |
Checks the internal consistency of the gene.
This function verifies that the gene is either empty or fully initialised with a matching function and argument list.
|
nodiscardnoexcept |
Returns the locus referenced by an argument value.
| [in] | a | an argument belonging to this gene |
The argument position is inferred from the argument list in order to recover the correct category.
|
nodiscardnoexcept |
|
nodiscarddefaultnoexcept |
Equality comparison.
Two genes are equal if they reference the same function symbol and have identical arguments.