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

#include <symbol.h>

Inheritance diagram for ultra::symbol:
ultra::function ultra::terminal ultra::integer::add ultra::integer::div ultra::integer::ife ultra::integer::ifl ultra::integer::ifz ultra::integer::mod ultra::integer::mul ultra::integer::shl ultra::integer::sub ultra::real::abs ultra::real::add ultra::real::aq ultra::real::cos ultra::real::div ultra::real::exp ultra::real::gt ultra::real::idiv ultra::real::ife ultra::real::ifl ultra::real::ifz ultra::real::length ultra::real::ln ultra::real::lt ultra::real::max ultra::real::mod ultra::real::mul ultra::real::sigmoid ultra::real::sin ultra::real::sqrt ultra::real::sub ultra::str::ife ultra::de::real ultra::ga::integer ultra::hga::integer ultra::hga::permutation ultra::integer::literal ultra::integer::number ultra::nullary ultra::real::integer ultra::real::literal ultra::real::number ultra::src::variable ultra::str::literal

Public Types

enum  format { c_format , cpp_format , python_format , sup_format }
 Supported rendering formats for symbol stringification.
using category_t = unsigned
using opcode_t = unsigned

Public Member Functions

 symbol (const std::string &, category_t=default_category)
virtual ~symbol ()=default
 Virtual destructor to allow safe polymorphic deletion.
category_t category () const noexcept
opcode_t opcode () const noexcept
const std::string & name () const noexcept
virtual std::string to_string (format=c_format) const =0
void category (category_t) noexcept
virtual bool is_valid () const

Static Public Attributes

static constexpr category_t default_category = 0
 Default category assigned when typing is not used.
static constexpr category_t undefined_category
 Sentinel value indicating that the category has not yet been assigned.

Detailed Description

Base class for all symbols.

In ULTRA, symbols are the atomic building blocks from which programs are constructed. Together, functions (internal nodes) and terminals (leaf nodes) form the symbol set used by the evolutionary algorithm to assemble executable program structures.

A symbol is uniquely identified across runs by its name. Symbols may also belong to a category, which is used to enforce strong typing in GP and to manage value domains in GA / DE contexts.

Note
Symbols are immutable with respect to their identity (name and opcode). The category may be assigned after construction only if initially marked as undefined.

Member Typedef Documentation

◆ category_t

using ultra::symbol::category_t = unsigned

Type used to represent symbol categories.

Categories are used to:

  • enforce strong typing in genetic programming;
  • define admissible value ranges in genetic algorithms and differential evolution.

A category represents a sub-domain of values. The same numerical value may belong to different categories (e.g. "kg" vs "km/h").

◆ opcode_t

using ultra::symbol::opcode_t = unsigned

Type used as a fast, session-local identifier for symbols.

Opcodes are unique within a single execution and are primarily used for hashing and fast comparisons. They are not stable across executions and must not be serialised.

Constructor & Destructor Documentation

◆ symbol()

ultra::symbol::symbol ( const std::string & name,
category_t c = default_category )
explicit

Constructs a symbol with the given name and category.

Parameters
[in]namename of the symbol (unique textual identifier)
[in]ccategory of the symbol
Warning
The symbol name is used for serialisation and must be globally unique within a symbol set. While opcodes are also unique, they are assigned dynamically and may differ between executions.

Member Function Documentation

◆ category() [1/2]

symbol::category_t ultra::symbol::category ( ) const
nodiscardnoexcept

Returns the category of the symbol.

Returns
category associated with the symbol

◆ category() [2/2]

void ultra::symbol::category ( category_t c)
noexcept

Assigns a category to the symbol.

Parameters
[in]cnew category value
Precondition
The current category must be undefined_category
Remarks
This function exists to support deferred category assignment. It should not be used to change an already defined category.

◆ is_valid()

bool ultra::symbol::is_valid ( ) const
nodiscardvirtual

Performs an internal consistency check.

Returns
true if the symbol satisfies basic validity constraints
Remarks
Derived classes are expected to extend this check to enforce additional invariants.

Reimplemented in ultra::function.

◆ name()

const std::string & ultra::symbol::name ( ) const
nodiscardnoexcept

Returns the name of the symbol.

Returns
constant reference to the symbol name
Note
The name uniquely identifies the symbol across executions and is used during serialisation.

◆ opcode()

symbol::opcode_t ultra::symbol::opcode ( ) const
nodiscardnoexcept

Returns the opcode of the symbol.

Returns
a session-local, unique numerical identifier
Note
The opcode is intended for fast internal use (e.g. hashing). It is not stable across executions and must not be used for persistence.

◆ to_string()

Member Data Documentation

◆ undefined_category

category_t ultra::symbol::undefined_category
staticconstexpr
Initial value:
=
std::numeric_limits<category_t>::max()

Sentinel value indicating that the category has not yet been assigned.


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