Vita
symbol.h
Go to the documentation of this file.
1
13#if !defined(VITA_SYMBOL_H)
14#define VITA_SYMBOL_H
15
16#include <limits>
17#include <string>
18
19#include "kernel/vitafwd.h"
20#include "kernel/common.h"
22
23namespace vita
24{
26using opcode_t = unsigned;
27
35class symbol
36{
37public:
39 enum format {c_format, cpp_format, mql_format, python_format, sup_format};
40
41 explicit symbol(const std::string &, category_t = 0);
42 virtual ~symbol() = default;
43
44 virtual unsigned arity() const = 0;
45 virtual bool input() const;
46
47 [[nodiscard]] category_t category() const;
48 [[nodiscard]] opcode_t opcode() const;
49 [[nodiscard]] bool terminal() const;
50
51 void category(category_t);
52
53 [[nodiscard]] std::string name() const;
54
57 virtual value_t eval(symbol_params &) const = 0;
58
59 [[nodiscard]] double penalty(core_interpreter *) const;
60
61 virtual bool is_valid() const;
62
63private:
64 // NVI template methods
65 virtual double penalty_nvi(core_interpreter *) const;
66
67 // Private data members
68 static opcode_t opc_count_;
69
70 opcode_t opcode_;
71
72 category_t category_;
73
74 std::string name_;
75};
76
86inline double symbol::penalty(core_interpreter *ci) const
87{
88 return penalty_nvi(ci);
89}
90
100{
101 return category_;
102}
103
112{
113 Expects(category_ == undefined_category);
114 Expects(c != category_);
115
116 category_ = c;
117}
118
128inline bool symbol::input() const
129{
130 return false;
131}
132
146{
147 return opcode_;
148}
149
153inline bool symbol::terminal() const
154{
155 return arity() == 0;
156}
157
158} // namespace vita
159
160#endif // include guard
Minimum interface of an interpreter.
An interface for parameter passing to functions / terminals.
Together functions and terminals are referred to as symbols.
Definition: symbol.h:36
virtual bool is_valid() const
Definition: symbol.cc:60
std::string name() const
Definition: symbol.cc:44
format
Symbol rendering format.
Definition: symbol.h:39
bool terminal() const
Definition: symbol.h:153
double penalty(core_interpreter *) const
Used for automatic calculation of penalities due to broken constraints.
Definition: symbol.h:86
opcode_t opcode() const
An opcode is a unique, numerical session ID for a symbol.
Definition: symbol.h:145
virtual bool input() const
An input variable is a feature from the learning domain.
Definition: symbol.h:128
category_t category() const
The type (a.k.a.
Definition: symbol.h:99
virtual value_t eval(symbol_params &) const =0
Calculates the value of / performs the action associated with the symbol (it's implementation specifi...
symbol(const std::string &, category_t=0)
Definition: symbol.cc:35
The main namespace for the project.
std::size_t category_t
A category provide operations which supplement or supersede those of the domain but which are restric...
Definition: common.h:44
std::variant< D_VOID, D_INT, D_DOUBLE, D_STRING > value_t
A variant containing the data types used by the interpreter for internal calculations / output value ...
Definition: value.h:45
unsigned opcode_t
This is the type used as key for symbol identification.
Definition: symbol.h:26