Vita
Public Types | Public Member Functions | List of all members
vita::symbol Class Referenceabstract

Together functions and terminals are referred to as symbols. More...

#include <symbol.h>

Inherited by vita::function, and vita::terminal.

Public Types

enum  format {
  c_format , cpp_format , mql_format , python_format ,
  sup_format
}
 Symbol rendering format. More...
 

Public Member Functions

virtual unsigned arity () const =0
 
category_t category () const
 The type (a.k.a. More...
 
void category (category_t)
 Changes the category of a symbol. More...
 
virtual value_t eval (symbol_params &) const =0
 Calculates the value of / performs the action associated with the symbol (it's implementation specific). More...
 
virtual bool input () const
 An input variable is a feature from the learning domain. More...
 
virtual bool is_valid () const
 
std::string name () const
 
opcode_t opcode () const
 An opcode is a unique, numerical session ID for a symbol. More...
 
double penalty (core_interpreter *) const
 Used for automatic calculation of penalities due to broken constraints. More...
 
 symbol (const std::string &, category_t=0)
 
bool terminal () const
 

Detailed Description

Together functions and terminals are referred to as symbols.

GP assembles variable length program structures from basic units called functions and terminals. Functions perform operations on their inputs, which are either terminals or output from other functions.

Definition at line 35 of file symbol.h.

Member Enumeration Documentation

◆ format

Symbol rendering format.

Definition at line 39 of file symbol.h.

Constructor & Destructor Documentation

◆ symbol()

vita::symbol::symbol ( const std::string &  name,
category_t  c = 0 
)
explicit
Parameters
[in]namename of the symbol
[in]ccategory of the symbol
Note
By default a symbol:
  • is NOT associative;
  • is NOT an input;
  • is NOT parametric. These are safe values for derived classes.
Warning
Since the name of the symbol is used for serialization, it must be unique. Even the opcode is unique, but it can change between executions.

Definition at line 35 of file symbol.cc.

Member Function Documentation

◆ arity()

virtual unsigned vita::symbol::arity ( ) const
pure virtual

Implemented in vita::function, and vita::terminal.

◆ category() [1/2]

category_t vita::symbol::category ( ) const
inline

The type (a.k.a.

category) of the symbol

Returns
the category

In strongly typed GP every terminal and every function argument / return value has a type (a.k.a. category).

Definition at line 99 of file symbol.h.

◆ category() [2/2]

void vita::symbol::category ( category_t  c)
inline

Changes the category of a symbol.

Parameters
[in]cthe new category
Remarks
Should be called only for symbols with undefined category.

Definition at line 111 of file symbol.h.

◆ eval()

virtual value_t vita::symbol::eval ( symbol_params ) const
pure virtual

◆ input()

bool vita::symbol::input ( ) const
inlinevirtual

An input variable is a feature from the learning domain.

Returns
true if the symbol is an input variable

Only a terminal can be an input variable.

Default (safe) value is false.

Reimplemented in vita::variable.

Examples
example6.cc.

Definition at line 128 of file symbol.h.

◆ is_valid()

bool vita::symbol::is_valid ( ) const
virtual
Returns
true if the object passes the internal consistency check

Reimplemented in vita::function.

Definition at line 60 of file symbol.cc.

◆ name()

std::string vita::symbol::name ( ) const
Returns
the name of the symbol

Definition at line 44 of file symbol.cc.

◆ opcode()

opcode_t vita::symbol::opcode ( ) const
inline

An opcode is a unique, numerical session ID for a symbol.

Returns
the opcode

The opcode is a fast way to uniquely identify a symbol and is primarily used for hashing.

Remarks
A symbol can be identified also by its name (a std::string). The name is often a better option since it doesn't change among executions.

Definition at line 145 of file symbol.h.

◆ penalty()

double vita::symbol::penalty ( core_interpreter ci) const
inline

Used for automatic calculation of penalities due to broken constraints.

Parameters
[in]ciinterpreter used for symbol's constraints evaluation
Returns
a penalty based on symbol specific broken constraints
  • 0.0 states that no constraint penalty is applied;
  • larger values specify larger penalties.

Definition at line 86 of file symbol.h.

◆ terminal()

bool vita::symbol::terminal ( ) const
inline
Returns
true if this symbol is a terminal

Definition at line 153 of file symbol.h.


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