Vita
|
A container for the symbols used by the GP engine. More...
#include <symbol_set.h>
Public Types | |
using | weight_t = unsigned |
Public Member Functions | |
category_t | categories () const |
void | clear () |
Clears the current symbol set. More... | |
symbol * | decode (const std::string &) const |
symbol * | decode (opcode_t) const |
bool | enough_terminals () const |
We want at least one terminal for every used category. More... | |
template<class S , class ... Args> | |
symbol * | insert (Args &&... args) |
Adds a symbol to the symbol set. More... | |
template<class S , class ... Args> | |
symbol * | insert (Args &&...) |
symbol * | insert (std::unique_ptr< symbol >, double=1.0) |
Adds a new symbol to the set. More... | |
bool | is_valid () const |
const symbol & | roulette (category_t) const |
Extracts a random symbol from the symbol set without bias between terminals and functions . More... | |
const symbol & | roulette_free (category_t) const |
Extracts a random symbol from the symbol set. More... | |
const function & | roulette_function (category_t) const |
const terminal & | roulette_terminal (category_t) const |
symbol_set () | |
Sets up the object. More... | |
std::size_t | terminals (category_t) const |
weight_t | weight (const symbol &) const |
Friends | |
std::ostream & | operator<< (std::ostream &, const symbol_set &) |
Prints the symbol set to an output stream. More... | |
A container for the symbols used by the GP engine.
Symbols are stored to be quickly recalled by category and randomly selected.
Definition at line 36 of file symbol_set.h.
using vita::symbol_set::weight_t = unsigned |
Definition at line 39 of file symbol_set.h.
vita::symbol_set::symbol_set | ( | ) |
Sets up the object.
The constructor allocates memory for up to k_args
arguments.
Definition at line 27 of file symbol_set.cc.
category_t vita::symbol_set::categories | ( | ) | const |
>= 1
)Definition at line 214 of file symbol_set.cc.
void vita::symbol_set::clear | ( | ) |
Clears the current symbol set.
Definition at line 35 of file symbol_set.cc.
symbol * vita::symbol_set::decode | ( | const std::string & | dex | ) | const |
[in] | dex | the name of a symbol |
dex
(0 if not found)Definition at line 198 of file symbol_set.cc.
[in] | opcode | numerical code used as primary key for a symbol |
opcode
(nullptr
if not found). Definition at line 179 of file symbol_set.cc.
bool vita::symbol_set::enough_terminals | ( | ) | const |
We want at least one terminal for every used category.
true
if there are enough terminals for secure individual generation Definition at line 235 of file symbol_set.cc.
symbol * vita::symbol_set::insert | ( | Args &&... | args | ) |
Adds a symbol to the symbol set.
S | symbol to be added |
[in] | args | arguments used to build S |
nullptr
in case of error)Insert a symbol in the symbol set without the user having to allocate memory.
insert(std::unique_ptr)
method (e.g. building from factory).1.0
) for symbol S
. Definition at line 167 of file symbol_set.h.
Adds a new symbol to the set.
[in] | s | symbol to be added |
[in] | wr | the weight of s (1.0 means standard frequency, 2.0 double probability of selection) |
nullptr
in case of error)A symbol with undefined category will be changed to the first free category.
Definition at line 55 of file symbol_set.cc.
bool vita::symbol_set::is_valid | ( | ) | const |
true
if the object passes the internal consistency check Definition at line 307 of file symbol_set.cc.
const symbol & vita::symbol_set::roulette | ( | category_t | c | ) | const |
Extracts a random symbol from the symbol set without bias between terminals and functions .
[in] | c | a category |
c
Definition at line 143 of file symbol_set.cc.
const symbol & vita::symbol_set::roulette_free | ( | category_t | c | ) | const |
Extracts a random symbol from the symbol set.
[in] | c | a category |
c
Definition at line 168 of file symbol_set.cc.
const function & vita::symbol_set::roulette_function | ( | category_t | c | ) | const |
[in] | c | a category |
c
Definition at line 101 of file symbol_set.cc.
const terminal & vita::symbol_set::roulette_terminal | ( | category_t | c | ) | const |
[in] | c | a category |
c
Definition at line 113 of file symbol_set.cc.
std::size_t vita::symbol_set::terminals | ( | category_t | c | ) | const |
[in] | c | a category |
c
Definition at line 223 of file symbol_set.cc.
symbol_set::weight_t vita::symbol_set::weight | ( | const symbol & | s | ) | const |
|
friend |
Prints the symbol set to an output stream.
[out] | o | output stream |
[in] | ss | symbol set to be printed |
ss
Definition at line 278 of file symbol_set.cc.